Page 1 of 1

linking libraries

Posted: Tue Mar 16, 2010 9:30 pm
by cilker
Hello,

I am starting to use CodeLite and have apparently not the many experience in using IDEs, though I never had this sort of problems with visual studio. I included windows.h and the compiler not complained anything, but apparently the linker complained not to have found the reference to a function, that is:

./Debug/main.o: In function `WinMain@16':
C:/Users/Ilker/C++/Ilkers C++ Programme/Windows Programmierung/main.cpp:39: undefined reference to `GetStockObject@4'

I used the conveniencies of CodeLite and found out that this function is declared in wingdi.h, that is included with windows.h already. So I think that the according library was not found or searched for. You will know that the header apparently is found in "include" in the mingw directory, but apparrently it is not possible to find the appropriate library in the lib directory of mingw. So, apparently I did not understand all of regarding the including mechanism, at all, because I am very surprised on this situation, so I ask you:

1. Why is the (standard?) path to some headerfiles is well known to the compiler (linker?), but not the path to the corresponding libraries?? I thought with the delivery of headerfiles the corresponding libraries are also supported and their paths are set in the IDE.

2. How do I find out which library-name belongs to xxx.h? Is it xxx.lib or libxxx.a or something else? I found a libgdi32.a in the lib directory, is that the library to wingdi.h?, and if it is so, why does the linker not find it automatically? And is it possible to impose other name conventions for headerfiles and their libraries?

3. If I have to link the library manually, I din't find out yet, how to set paths for the linker for searching for those libraries.

thank you

Re: linking libraries

Posted: Tue Mar 16, 2010 9:44 pm
by eranif
cilker wrote:1. Why is the (standard?) path to some headerfiles is well known to the compiler (linker?), but not the path to the corresponding libraries?? I thought with the delivery of headerfiles the corresponding libraries are also supported and their paths are set in the IDE.
The paths are known, but the ibraries are not. You need to specify them by your self. This is how the compiler/linker works.

Just for clarification: codelite is an IDE not a compiler, nor linker - so this is the behavior of the linker and *not* of codelite.

Also, you are wrong by saying that "headerfiles is well known to the compiler" - the *path* is known, which fies to include? this was done by *you* by adding the "incude" statement into your code.

You will to do the same for the linker.

quick search in google shows this: http://msdn.microsoft.com/en-us/library ... S.85).aspx so you need to add libGdi32.a to the linker path.
To do this:
open the project settings (right click it and select 'settings') , next select the linker tab, and in the 'Additional Libraries' add libGdi32.a

I am assuming that you are using g++/MinGW on Windows here.
cilker wrote:2. How do I find out which library-name belongs to xxx.h? Is it xxx.lib or libxxx.a or something else? I found a libgdi32.a in the lib directory, is that the library to wingdi.h?, and if it is so, why does the linker not find it automatically? And is it possible to impose other name conventions for headerfiles and their libraries?
See my first comment
cilker wrote:3. If I have to link the library manually, I din't find out yet, how to set paths for the linker for searching for those libraries.
See my first comment

In the future:
1) State your OS (one can guess it by reading the post, but in general this is how to post)
2) State your codelite version
3) Compiler you are using
4) And most important: are you using a self compiled binary of codelite or one of the distributed packages

Eran

Re: linking libraries

Posted: Tue Mar 16, 2010 10:04 pm
by cilker
Thank you for your quick response!

"I am assuming that you are using g++/MinGW on Windows here."

Yes your assumptions are true, and in the future I will follow the advises you posted at the end, when I have more questions.