Author Topic: Problem Building project with Code::Block  (Read 17234 times)

Offline arashfahim

  • Single posting newcomer
  • *
  • Posts: 9
Problem Building project with Code::Block
« on: October 04, 2010, 12:31:23 am »
Hi,
I am an absolute beginner in C++ and I installed full version of Code::Block in my Laptop. I tried to run the "Hello World!" program as the first program. I received the following error.

Quote
-------------- Build: Debug in test1 ---------------

mingw32-g++.exe -Wall -fexceptions  -g    -I"C:\Program Files\CodeBlocks\MinGW\lib\gcc\mingw32\4.4.1\include" -I"C:\Program Files\CodeBlocks\MinGW\lib\gcc\mingw32\4.4.1\include\c++" -I"C:\Program Files\CodeBlocks\MinGW\lib\gcc\mingw32\4.4.1\include\c++\backward" -I"C:\Program Files\CodeBlocks\MinGW\lib\gcc\mingw32\4.4.1\include\c++\mingw32" -I"C:\Program Files\CodeBlocks\MinGW\lib\gcc\mingw32\4.4.1\include\c++\bits" -I"C:\Program Files\CodeBlocks\MinGW\lib\gcc\mingw32\4.4.1\include\c++\debug" -I"C:\Program Files\CodeBlocks\MinGW\lib\gcc\mingw32\4.4.1\include\c++\ext" -I"C:\Program Files\CodeBlocks\MinGW\lib\gcc\mingw32\4.4.1\include\c++\mingw32\bits"  -c "C:\Documents and Settings\user\Desktop\C++tests\test1\main.cpp" -o obj\Debug\main.o
In file included from c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/ios:43,
                 from c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/ostream:40,
                 from c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/iostream:40,
                 from C:\Documents and Settings\user\Desktop\C++tests\test1\main.cpp:2:
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/ios_base.h:234: error: field '_M_msg' has incomplete type
In file included from c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/basic_ios.h:39,
                 from c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/ios:45,
                 from c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/ostream:40,
                 from c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/iostream:40,
                 from C:\Documents and Settings\user\Desktop\C++tests\test1\main.cpp:2:
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/locale_facets.h: In member function 'std::string std::numpunct<_CharT>::grouping() const':
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/locale_facets.h:1746: error: return type 'struct std::string' is incomplete
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/locale_facets.h: In member function 'virtual std::string std::numpunct<_CharT>::do_grouping() const':
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/locale_facets.h:1814: error: return type 'struct std::string' is incomplete
In file included from c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/locale_facets.h:2599,
                 from c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/basic_ios.h:39,
                 from c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/ios:45,
                 from c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/ostream:40,
                 from c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/iostream:40,
                 from C:\Documents and Settings\user\Desktop\C++tests\test1\main.cpp:2:
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/locale_facets.tcc: In member function '_InIter std::num_get<_CharT, _InIter>::_M_extract_float(_InIter, _InIter, std::ios_base&, std::_Ios_Iostate&, std::string&) const':
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/locale_facets.tcc:192: error: invalid use of incomplete type 'struct std::string'
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/stringfwd.h:52: error: declaration of 'struct std::string'
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/locale_facets.tcc:263: error: invalid use of incomplete type 'struct std::basic_string<char, std::char_traits<char>, std::allocator<char> >'
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/stringfwd.h:52: error: declaration of 'struct std::basic_string<char, std::char_traits<char>, std::allocator<char> >'
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/locale_facets.tcc:277: error: invalid use of incomplete type 'struct std::string'
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/stringfwd.h:52: error: declaration of 'struct std::string'
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/locale_facets.tcc:300: error: invalid use of incomplete type 'struct std::string'
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/stringfwd.h:52: error: declaration of 'struct std::string'
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/locale_facets.tcc:336: error: invalid use of incomplete type 'struct std::string'
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/stringfwd.h:52: error: declaration of 'struct std::string'
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/locale_facets.tcc: In member function '_InIter std::num_get<_CharT, _InIter>::_M_extract_int(_InIter, _InIter, std::ios_base&, std::_Ios_Iostate&, _ValueT&) const':
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/locale_facets.tcc:448: error: invalid use of incomplete type 'struct std::string'
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/stringfwd.h:52: error: declaration of 'struct std::string'
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/locale_facets.tcc:534: error: invalid use of incomplete type 'struct std::string'
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/stringfwd.h:52: error: declaration of 'struct std::string'
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/locale_facets.tcc:547: error: invalid use of incomplete type 'struct std::string'
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/stringfwd.h:52: error: declaration of 'struct std::string'
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/locale_facets.tcc: In member function 'virtual _InIter std::num_get<_CharT, _InIter>::do_get(_InIter, _InIter, std::ios_base&, std::_Ios_Iostate&, float&) const':
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/locale_facets.tcc:675: error: invalid use of incomplete type 'struct std::string'
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/stringfwd.h:52: error: declaration of 'struct std::string'
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/locale_facets.tcc:677: error: invalid use of incomplete type 'struct std::string'
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/stringfwd.h:52: error: declaration of 'struct std::string'
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/locale_facets.tcc: In member function 'virtual _InIter std::num_get<_CharT, _InIter>::do_get(_InIter, _InIter, std::ios_base&, std::_Ios_Iostate&, double&) const':
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/locale_facets.tcc:690: error: invalid use of incomplete type 'struct std::string'
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/stringfwd.h:52: error: declaration of 'struct std::string'
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/locale_facets.tcc:692: error: invalid use of incomplete type 'struct std::string'
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/stringfwd.h:52: error: declaration of 'struct std::string'
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/locale_facets.tcc: In member function 'virtual _InIter std::num_get<_CharT, _InIter>::do_get(_InIter, _InIter, std::ios_base&, std::_Ios_Iostate&, long double&) const':
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/locale_facets.tcc:722: error: invalid use of incomplete type 'struct std::string'
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/stringfwd.h:52: error: declaration of 'struct std::string'
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/locale_facets.tcc:724: error: invalid use of incomplete type 'struct std::string'
c:\program files\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/stringfwd.h:52: error: declaration of 'struct std::string'
Process terminated with status 1 (0 minutes, 0 seconds)
31 errors, 0 warnings

I tried to reinstall Code::Block, but it gave me the same error. I also tried to google the error but no success.

I appreciate you experts to help me remove the problem.

Thanks a lot

Online stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Problem Building project with Code::Block
« Reply #1 on: October 04, 2010, 02:02:47 am »
Did you re-install the Compiler?
If not, I suggest trying it.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline arashfahim

  • Single posting newcomer
  • *
  • Posts: 9
Re: Problem Building project with Code::Block
« Reply #2 on: October 04, 2010, 02:05:40 am »
Yes, I reinstalled it. I chose full installation. But, still  got the same error.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Problem Building project with Code::Block
« Reply #3 on: October 04, 2010, 02:16:22 am »
I tried to run the "Hello World!" program as the first program.
some suggestions:

1, give us the full steps how you create and build the "hello world" program.
2, the minimal sample code of the "hello world" program.
3, use .cpp (not .c).

If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline arashfahim

  • Single posting newcomer
  • *
  • Posts: 9
Re: Problem Building project with Code::Block
« Reply #4 on: October 04, 2010, 02:35:01 am »
I tried to run the "Hello World!" program as the first program.
some suggestions:

1, give us the full steps how you create and build the "hello world" program.
2, the minimal sample code of the "hello world" program.
3, use .cpp (not .c).


I did it in 2 ways.
First I created an empty file main.cpp. I put the following on the file:
Quote
#include<iostream>
using namespace std;

 int main(){
    cout <<"Hello World!" << endl;
    return 0;
 }
Then F9.
Second through New>Project>Console Application
choosing C++ and naming the project as test1. Then F9.

I took your advice. The file is called main.cpp not  .c. But the problem still exists.

Offline arashfahim

  • Single posting newcomer
  • *
  • Posts: 9
Re: Problem Building project with Code::Block
« Reply #5 on: October 04, 2010, 02:46:05 am »
I run the new  simple program:
Quote
using namespace std;

 int main(){
     int a=2;
//    cout <<"Hello World!" << endl;
    return a;
 }
It works perfectly. Therefore the problem should be in iostream.
Am I true? Should I add some path to compiler folder?

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Problem Building project with Code::Block
« Reply #6 on: October 04, 2010, 03:48:54 am »
Should I add some path to compiler folder?
No, these folders were added by compiler by default.

I have no idea about other error.

BTW: you can put your project file in a folder WITHOUT a space in the folder path.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline arashfahim

  • Single posting newcomer
  • *
  • Posts: 9
Re: Problem Building project with Code::Block
« Reply #7 on: October 04, 2010, 04:28:26 am »
Quote
you can put your project file in a folder WITHOUT a space in the folder path.
It does not helped. Does anyone have any idea?

Online stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Problem Building project with Code::Block
« Reply #8 on: October 04, 2010, 05:13:21 am »
If you have another MinGW in your system path, remove it.
If you have an MinGW in the folder x:\mingw for any drive letter in place of x rename or delete the MinGW folder.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline arashfahim

  • Single posting newcomer
  • *
  • Posts: 9
Re: Problem Building project with Code::Block
« Reply #9 on: October 04, 2010, 02:48:04 pm »
Thanks Tim. I searched all the hard drive.  The only path is "C:\Program Files\CodeBlocks\MinGW". There is no other one. Did you mean that by system path?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Problem Building project with Code::Block
« Reply #10 on: October 04, 2010, 02:54:48 pm »
no, he means the PATH environment variable
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline arashfahim

  • Single posting newcomer
  • *
  • Posts: 9
Re: Problem Building project with Code::Block
« Reply #11 on: October 04, 2010, 03:14:30 pm »
I checked this:
My Computer>System Properties>Advance [tab]> environment variables
Obviously there is no "C:program files/.../mingw" PATH in there. Should I add any. If yes which PATH. Because Code::Block has many folders one inside another, I can't figure out which one.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Problem Building project with Code::Block
« Reply #12 on: October 04, 2010, 03:15:45 pm »
If another installation is in system-path, it should be no problem (if the installation you use is complete), but if any of the disks has a \MinGW folder an installation in another folder might break.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Problem Building project with Code::Block
« Reply #13 on: October 04, 2010, 03:16:59 pm »
While compiling, C::B prepends the compilers bin dir to the path-variable (if your compiler installation dir is setup correctly in C::B).

Offline arashfahim

  • Single posting newcomer
  • *
  • Posts: 9
Re: Problem Building project with Code::Block
« Reply #14 on: October 04, 2010, 03:49:08 pm »
Dear Jens,
How should I check if my compiler installation dir is setup correctly in C::B?

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Problem Building project with Code::Block
« Reply #15 on: October 04, 2010, 04:07:02 pm »
Go to "Settings -> Compiler and debugger... -> GCC -> Toolchain executables" and make sure the compiler installation dir points to the directory of your MinGW-install that includes the bin-dir (not the bin-dir itself) and make sure the executables that are set exist in the bin-dir of your MinGW-install.

Online stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Problem Building project with Code::Block
« Reply #16 on: October 04, 2010, 04:13:27 pm »
It looks like you have added the include path the Compilers uses automatically in the wrong way.

Check your Code::Blocks compiler configuration.

Edit: Make sure you pick the right Compiler from the "Selected Compiler" Pull-down list and make it the default compiler


This one is likely right
"Settings->Compiler and Debugger->Global Compiler settings->Toolchain executables"

But,
"Settings->Compiler and Debugger->Global Compiler settings->Search Directory" is likely wrong
The Three Sub Tabs are empty on me.

And
"Settings->Compiler and Debugger->Global Compiler settings->Linker Settings"
is also empty on mine.

Tim S.
 
« Last Edit: October 04, 2010, 04:16:09 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline arashfahim

  • Single posting newcomer
  • *
  • Posts: 9
Re: Problem Building project with Code::Block
« Reply #17 on: October 04, 2010, 04:35:08 pm »
The compiler I chose is GNU GCC Compiler.
"Settings->Compiler and Debugger->Global Compiler settings->Search Directory" was not empty in mine. I deleted all the PATHs.
The other tabs were empty.
It fixed the problem. Thanks a lot every body.