Author Topic: Code::Blocks + MingGW doesn't link static lib.. HELP !  (Read 11975 times)

Offline Feneck91

  • Multiple posting newcomer
  • *
  • Posts: 112
Code::Blocks + MingGW doesn't link static lib.. HELP !
« on: January 22, 2010, 10:31:09 am »
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]

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Code::Blocks + MingGW doesn't link static lib.. HELP !
« Reply #1 on: January 22, 2010, 12:15:10 pm »
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: [Select]
#ifdef __cplusplus
extern "C"
{
#endif

at the beginning and
Code: [Select]
#ifdef __cplusplus
}
#endif

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).

Offline Feneck91

  • Multiple posting newcomer
  • *
  • Posts: 112
Re: Code::Blocks + MingGW doesn't link static lib.. HELP !
« Reply #2 on: January 22, 2010, 01:25:11 pm »
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.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9493
Re: Code::Blocks + MingGW doesn't link static lib.. HELP !
« Reply #3 on: January 22, 2010, 02:14:30 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...
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.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline Feneck91

  • Multiple posting newcomer
  • *
  • Posts: 112
Re: Code::Blocks + MingGW doesn't link static lib.. HELP !
« Reply #4 on: January 23, 2010, 11:03:31 pm »
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 ?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11783
    • Travis build status
Re: Code::Blocks + MingGW doesn't link static lib.. HELP !
« Reply #5 on: January 23, 2010, 11:49:41 pm »
Choose your app project -> right click -> properties  -> build targets -> dependencies -> external dependency files -> add you lib file
(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 Feneck91

  • Multiple posting newcomer
  • *
  • Posts: 112
Re: Code::Blocks + MingGW doesn't link static lib.. HELP !
« Reply #6 on: January 24, 2010, 08:09:34 am »
That what I have said :
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.
But I continue to think... it strange that the compiler not the the lib have changed automatically...
I had the external dependencies, it's work...

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11783
    • Travis build status
Re: Code::Blocks + MingGW doesn't link static lib.. HELP !
« Reply #7 on: January 24, 2010, 10:49:44 am »
I've replied to you in order to verify that we are talking about the same thing.

Morten: Can we add some hocus pocus for this? Also I'm for adding (in a user controlled way) the hocus pocus you mentioned in your VC hate post :)
Can you say what are the implementation problems?
(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 MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9493
Re: Code::Blocks + MingGW doesn't link static lib.. HELP !
« Reply #8 on: January 24, 2010, 01:53:43 pm »
Can you say what are the implementation problems?
Look: C::B handles dependencies just fine. It's really just a matter of the project setup. You can setup project dependencies and order the targets in a project as need and all will work just fine. If you create a virtual target across all projects in a workspace that will compile the modules as needed your compile process will never fail. In addition I usually resolve missing linker symbols step by step which ensures the right order automatically. Remember that you only have to do it once.

There is really no hocus-pocus needed. Just knowledge about your dependencies and a correct project setup.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11783
    • Travis build status
Re: Code::Blocks + MingGW doesn't link static lib.. HELP !
« Reply #9 on: January 24, 2010, 02:50:10 pm »
There is really no hocus-pocus needed. Just knowledge about your dependencies and a correct project setup.

I know how to do it. But I also know that C::B can do it for me  :lol:
The question is can we implement it reliably?  :lol:
And what are the possible problems?
(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 MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9493
Re: Code::Blocks + MingGW doesn't link static lib.. HELP !
« Reply #10 on: January 24, 2010, 03:36:13 pm »
The question is can we implement it reliably?  :lol:
I honestly believe no.

And what are the possible problems?
Well - try to do it (configurable) for a number of (partially unknown) compilers (think f copies of compilers) and platform depended. So the same compiler on another platform will have different dependencies. Try to work out a concept and you most likely will fail. It works for MS because they have one compiler and one platform. It's easy to do it that way. But if you really come up with a good approach... I am very interested in hearing it!
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline Feneck91

  • Multiple posting newcomer
  • *
  • Posts: 112
Re: Code::Blocks + MingGW doesn't link static lib.. HELP !
« Reply #11 on: January 24, 2010, 06:09:40 pm »
I make dependencies on libs and all work fine ! I just ask some question to find way to resolve problems that I know how to resolve in Visual C++ compiler, not to launch stones on Code::Blocs... Really, I'm very surprise by the quality of Code::Blocks IDE, good job for everyone to have made this very good complier environment !
Thanks to all contributors.

For this problem : I modify the .h of a lib, the lib is re-build an exe link again. I modify the .cpp of a lib, the lib is re-build but the exe is considered up to date and so is not linked again. I have added dependencies with all .a (lib) that the exe used and all work fine now.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9493
Re: Code::Blocks + MingGW doesn't link static lib.. HELP !
« Reply #12 on: January 24, 2010, 06:39:47 pm »
I have added dependencies with all .a (lib) that the exe used and all work fine now.
That's exactly the steps you had to do. :-)
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline TerryP

  • Multiple posting newcomer
  • *
  • Posts: 26
    • My journal
Re: Code::Blocks + MingGW doesn't link static lib.. HELP !
« Reply #13 on: January 25, 2010, 08:55:43 am »
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...
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.

Not to drift off topic, but that really is a user problem, not a visual studio problem.

Code::Blocks has wizards of it's own that try to setup certain properties for a new project. There's no real difference... the question is who has the balls to ask, "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" with a straight face. Any decent programmer should know how the build and runtime system for their language environment works, I still know plenty who can't tell a cmd window from a tutorial. The biggest difference between C::B and Microsoft's IDE, is the former adapts itself to tool bundles, while the latter integrates itself with its tools.

The only real differences I've found between the two, is Code::Blocks lacks inheritable property sheets, and has a much more logical layout for setting build options.
Just Another Computer Geek