cannot find -lMyStaticLibrary

General questions regarding the usage of CodeLite
JSeb
CodeLite Curious
Posts: 4
Joined: Wed May 13, 2015 3:48 am
Genuine User: Yes
IDE Question: C++
Contact:

cannot find -lMyStaticLibrary

Post by JSeb »

This seems to be a fairly simple problem, but I couldn't find a complete solution on these forums.

I have a workspace with two projects, one an executable and the other a static library. The former uses the latter.

I changed my executable's build order to make sure the library is compiled first.

My project, however, does not link. In my executable's settings, I tried changing Linker->Libraries Search Path and Linker->Libraries, but I still get
cannot find -lMyStaticLibrary
during the linking phase.

Indeed, I'm not sure what it's looking for: since for a static library the link stage is skipped, I just get a bunch of .o and .o.d files. Certainly no MyStaticLibrary.a
User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: cannot find -lMyStaticLibrary

Post by eranif »

Can you post a full re-build log? (i.e. perform clean and build and post here the log of the build)
This will give a hint of what is missing

Thanks
Eran
Make sure you have read the HOW TO POST thread
JSeb
CodeLite Curious
Posts: 4
Joined: Wed May 13, 2015 3:48 am
Genuine User: Yes
IDE Question: C++
Contact:

Re: cannot find -lMyStaticLibrary

Post by JSeb »

Sure, here it is:

Code: Select all

C:\Windows\system32\cmd.exe /C C:/MinGW/bin/mingw32-make.exe -j2 SHELL=cmd.exe -e -f  Makefile
"----------Building project:[ MyStaticLibrary - Debug ]----------"
mingw32-make.exe[1]: Entering directory 'U:/DEV/CPP/STATIC_SAMPLE'
C:/MinGW/bin/g++.exe  -c  "U:/DEV/CPP/STATIC_SAMPLE/File1.cpp" -g -O0 -Wall  -o ./Debug/CTest.cpp.o -I. -I.
C:/MinGW/bin/g++.exe  -c  "U:/DEV/CPP/STATIC_SAMPLE/File2.cpp" -g -O0 -Wall  -o ./Debug/CTestSuite.cpp.o -I. -I.
C:/MinGW/bin/ar.exe rcu ./Debug/MyStaticLibrary @"MyStaticLibrary.txt"
mingw32-make.exe[1]: Leaving directory 'U:/DEV/CPP/STATIC_SAMPLE'
"----------Building project:[ MyExecutable - Debug ]----------"
mingw32-make.exe[1]: Entering directory 'U:/DEV/CPP/SAMPLE/MyExecutable'
C:/MinGW/bin/g++.exe  -c  "U:/DEV/CPP/SAMPLE/MyExecutable/main.cpp" -g -O0 -Wall  -o ./Debug/main.cpp.o -I. -I. -I../../STATIC_SAMPLE/
C:/MinGW/bin/g++.exe -o ./Debug/MyExecutable @"MyExecutable.txt" -L. -LU:/DEV/CPP/STATIC_SAMPLE -LU:/DEV/CPP/STATIC_SAMPLE/Debug  -lMyStaticLibrary
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -lMyStaticLibrary
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[1]: *** [Debug/MyExecutable] Error 1
mingw32-make.exe: *** [All] Error 2
MyExecutable.mk:78: recipe for target 'Debug/MyExecutable' failed
mingw32-make.exe[1]: Leaving directory 'U:/DEV/CPP/SAMPLE/MyExecutable'
Makefile:4: recipe for target 'All' failed
====1 errors, 0 warnings====
This is a toy project, to figure out CodeLite.

To try and make the thing work, you will notice I put two absolute paths in Linker->Libraries Search Path.
User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: cannot find -lMyStaticLibrary

Post by eranif »

You modified the static library settings:

In the static library, I can see that CodeLite runs 'ar' and generate the following file:

Code: Select all

./Debug/MyStaticLibrary
What I am missing here is the libMyStaticLibrary.a

To fix this:
static library settings->general->output file and set it to:
libMyStaticLibrary.a
Without the '.a' and the 'lib' prefix the linker will not be able to find it (by using -lMyStaticLibrary, the linker will search for libMyStaticLibrary.[a|dll|so] )

Eran
Make sure you have read the HOW TO POST thread
JSeb
CodeLite Curious
Posts: 4
Joined: Wed May 13, 2015 3:48 am
Genuine User: Yes
IDE Question: C++
Contact:

Re: cannot find -lMyStaticLibrary

Post by JSeb »

It works!

I now understand that if you create a static library via the wizard, the variable in settings->general->output file is correctly initialized.
But when you change the type of an existing project to make it a static library, you have to manually do this.

Thank you for the quick and clear answers!
Post Reply