2

While doing programming in Code::Blocks it compiles well for C but not for C++. Even for a "Hello World" program:

#include <iostream>

using namespace std;

int main()
{
    cout << "Hello world!" << endl;
    return 0;
}

it gives these errors:

-------------- Build: Debug in project ---------------

    Compiling: main.cpp
    Linking console executable: bin\Debug\project.exe
    C:\Program Files (x86)\CodeBlocks\MinGW\lib/libstdc++.a(eh_throw.o):eh_throw.cc:(.text+0x7b): undefined reference to `__w32_sharedptr_unexpected'
    C:\Program Files (x86)\CodeBlocks\MinGW\lib/libstdc++.a(eh_throw.o):eh_throw.cc:(.text+0x8c): undefined reference to `__w32_sharedptr_terminate'
    C:\Program Files (x86)\CodeBlocks\MinGW\lib/libstdc++.a(eh_globals.o):eh_globals.cc:(.text+0x4e): undefined reference to `__w32_sharedptr'
    C:\Program Files (x86)\CodeBlocks\MinGW\lib/libstdc++.a(eh_globals.o):eh_globals.cc:(.text+0xb9): undefined reference to `__w32_sharedptr'
    C:\Program Files (x86)\CodeBlocks\MinGW\lib/libstdc++.a(eh_globals.o):eh_globals.cc:(.text+0x179): undefined reference to `__w32_sharedptr'
    C:\Program Files (x86)\CodeBlocks\MinGW\lib/libstdc++.a(eh_globals.o):eh_globals.cc:(.text+0x186): undefined reference to `__w32_sharedptr'
    C:\Program Files (x86)\CodeBlocks\MinGW\lib/libstdc++.a(eh_globals.o):eh_globals.cc:(.text+0x1e3): undefined reference to `__w32_sharedptr'
    C:\Program Files (x86)\CodeBlocks\MinGW\lib/libstdc++.a(eh_globals.o):eh_globals.cc:(.text+0x1ef): more undefined references to `__w32_sharedptr' follow
    C:\Program Files (x86)\CodeBlocks\MinGW\lib/libstdc++.a(eh_terminate.o):eh_terminate.cc:(.text+0x67): undefined reference to `__w32_sharedptr_terminate'
    C:\Program Files (x86)\CodeBlocks\MinGW\lib/libstdc++.a(eh_terminate.o):eh_terminate.cc:(.text+0x97): undefined reference to `__w32_sharedptr_unexpected'
    C:\Program Files (x86)\CodeBlocks\MinGW\lib/libstdc++.a(eh_terminate.o):eh_terminate.cc:(.text+0xb3): undefined reference to `__w32_sharedptr_terminate'
    C:\Program Files (x86)\CodeBlocks\MinGW\lib/libstdc++.a(eh_terminate.o):eh_terminate.cc:(.text+0xd3): undefined reference to `__w32_sharedptr_unexpected'
    collect2: ld returned 1 exit status
    Process terminated with status 1 (0 minutes, 1 seconds)
    12 errors, 0 warnings
8
  • Please post the code you are using. Commented Nov 3, 2011 at 7:42
  • Please post some source code. Commented Nov 3, 2011 at 7:44
  • 1
    #include <iostream> using namespace std; int main() { cout << "Hello world!" << endl; return 0; } Commented Nov 3, 2011 at 7:48
  • 1
    Edit your question. Once you've put the code in, use ctrl-K to make it look like code. Commented Nov 3, 2011 at 7:54
  • 2
    I bet you're not linking using g++... Commented Nov 3, 2011 at 8:07

1 Answer 1

4

The errors you're getting indicate that the linker is having trouble locating __w32_sharedptr which is probably a dependency libstdc++ needs to work.

Normally the standard library and any dependencies it needs are linked in automatically when you build your project. However, as trojanfoe's comment indicates this is only true if you're compiling with g++. If you're building C++ code with gcc, the C++ standard library won't get included automatically since the gcc driver thinks it's compiling C code.

To verify what's actually happening in your codeblocks setup go to Settings->Compiler and Debugger->Global compiler settings(on the left)->under Toolchain executables tab. You should see something similar to this:

enter image description here

If your setup looks right but still refuses to build properly, enable full compiler logging and see what commands are actually being invoked by the IDE. You can find this under Global compiler settings->Other settings tab-> Compiler Log = Full command line. Note you might have to scroll a bit to the right to find the tab.

With full logging enabled, rebuild your project again and update your question with the commands used.

This is approximately what you should see in the log window when you rebuilt with the above options turned on:

enter image description here

Sign up to request clarification or add additional context in comments.

6 Comments

My set up looks right as u have guided. It used to work but after I installed SDL library in my codeblock, the program gives me this such of trouble. Is it because of the SDL Library..??
@PrajwalAcharya Did you enable full logging in that case? What does the log window show when you try to build? The full commandline used to build will show up there when you enable full logging.
log windows this time too shows same as above..?? Will reinstalling codeblocks solve this..?? I can probably reinstall SDL Library too..!!!
@PrajwalAcharya If you're seeing the same thing as before then you didn't enable full commandline logging. I updated my answer to show you how it should look like.
Finally Finally I got out of that problem thank you @Victor Now it worked and is running c++ programs too..!!!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.