User forums > Using Code::Blocks

Code::Blocks + MingGW doesn't link static lib.. HELP !

(1/3) > >>

Feneck91:
I had problems with wxWidgets and gdb when I use shared libs (dll on windows), I receive SIGTRAP and could not debug my application !
You can see my post on WxWidgets forum: http://forums.wxwidgets.org/viewtopic.php?t=26715

So... Simplify, re-build wxWidgets in Monolitic static libs and put all my dll to static libs... All compile perfectly.
WxWidgets is linked, no problems.

but when I linked my application I had lot of undefined reference : the linker don't use the lib I put into the projet properties.
I look, take a lot of time, looking for error... did not found.

Desperate, I try to make a very very simple App with
- exe : command line, hello world !
- static lib : 3 simples function to use.

Modify dependencies, addind libs into exe project.
No way, the function I called into exe file is always undefined reference, the linker cannot see it.

I have used the Code::Blocks templates to create these 2 projects :
- Console application
- Static library

I give you the very very small exemple (3 ko in zip files, contains 3 file sources).
If anybody can help me or say to me, I cannot use Static Library because of a internal bugg of MinGW or Code::Blocks IDE, or I must add options into the compiler...

Help !

[attachment deleted by admin]

Jenna:
In your sample project you make a typical beginners error and has nothing to do with C::B and therefore violates our forum rules.
Be aware, that such a topic might get locked or even silently deleted.

You mix c and c++ code, this does not work.

You can search the web or a C/C++ forum for the cause, tis forum is definitely the wrong place.

Put

--- Code: ---#ifdef __cplusplus
extern "C"
{
#endif

--- End code ---

at the beginning and

--- Code: ---#ifdef __cplusplus
}
#endif

--- End code ---

at the end of your header-file used for C and C++ and it will work.

Nevertheless it's better to avoid mixing of C and C++ in your code if possible (in my opinion).

Feneck91:
I though I have found to replicate my problem into this short example, I never use C file, and never use extern "C" in my software...
The problem is a WxWidgets problem or MinGW one or Code::Blocks one.
.... writing this message.... find the solution.
I give it here :
I'm working for 15 years in Visual C++ and all these libraries are included by the wizard, that why I don't know :
The order of the library is important for linking... YOU MUST PUT Wx libs BEFORE all systems libs else it don't link.

I'm really sorry if I violates yours forum rules, I thought it was a problem with Code::Blocks.
Thanks for your help.

Stephane.

MortenMacFly:

--- Quote from: Feneck91 on January 22, 2010, 01:25:11 pm ---I'm working for 15 years in Visual C++ and all these libraries are included by the wizard, that why I don't know :
The order of the library is important for linking...

--- End quote ---
See: That is exactly why I hate VS. It gives you no in-sight, makes some hocus-pocus and it somehow works as the VS compiler/linker probably is tweaked accordingly. However, once you want to port or switch to another build system you are in hell.

C::B requires you to setup all the settings correctly. But this will also enable you to be 100% sure how your project is setup/built. BTW: It would not even be possible otherwise as we support many compilers and would need a similar "hocus-pocus" mechanism for every compiler then. That's pointless and useless.

Feneck91:
I be back for another question concerning Code::blocks....

I have succeeded compile my project with wxWidgets 2.9.0 compiled as a static library.
My exe use several other personnal other libs liked as statically library too. I have corectly add project dependencies between each libraries.
Problem : When I change an cpp file in the personnal static library, the library is re-build but the exe is not linked again, I MUST modify a cpp of the main application to force to re-link again, why the compiler doesn't detect it automatically ?
I know a way : Into Project/Targets options, with dependencies button I could make a dependencies to lib files but it is strande to must do it manually.
Do you have more information about it ?

Navigation

[0] Message Index

[#] Next page

Go to full version