Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Link .lib in Eclipse CDT for Windows, Cygwin G++ linker
Link .lib in Eclipse CDT for Windows, Cygwin G++ linker [message #809173] Tue, 28 February 2012 15:06 Go to next message
Massimo Cristofolini is currently offline Massimo CristofoliniFriend
Messages: 5
Registered: February 2012
Junior Member
Hi everybody!

I've just installed Eclipse (I usually develop with MS Visual Studio and 'ol Borland Builder).
I'm trying to link a library (say, myLib.lib), stored in my project path (D:\Documenti\eclipse\workspace\HelloWorld), but I get an error.
Console output:
Building target: HelloWorld
Invoking: Cross G++ Linker
g++ -LD:\Documenti\eclipse\workspace\HelloWorld -o "HelloWorld"  ./main.o   -lmyLib
/usr/lib/gcc/i686-pc-cygwin/4.5.3/../../../../i686-pc-cygwin/bin/ld: cannot find -lmyLib
collect2: ld returned 1 exit status
make: *** [HelloWorld] Error 1

I've modified project Properties->C/C++ Build->Settings->Cross G++ Linker for Debug and Release mode adding the current path to the "Library search path" (both using '/' and '\'), adding the library in the "Library" field (with/without .lib, with/without entire path, ...) but without success.

I found some discussions about this, but most is for Linux version, and following the Windows oriented posts I get no results.

Any hint?
Maybe a step by step guide.
Thanks in advance for your help!

[Updated on: Tue, 28 February 2012 15:07]

Report message to a moderator

Re: Link .lib in Eclipse CDT for Windows, Cygwin G++ linker [message #809208 is a reply to message #809173] Tue, 28 February 2012 15:48 Go to previous messageGo to next message
Axel Mueller is currently offline Axel MuellerFriend
Messages: 1973
Registered: July 2009
Senior Member
Quote:
I found some discussions about this, but most is for Linux version, and following the Windows oriented posts I get no results.

You should reread these discussions. The solution will be identical (it does not depend on the platform but the compiler!).


Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: Link .lib in Eclipse CDT for Windows, Cygwin G++ linker [message #809755 is a reply to message #809208] Wed, 29 February 2012 08:10 Go to previous messageGo to next message
Massimo Cristofolini is currently offline Massimo CristofoliniFriend
Messages: 5
Registered: February 2012
Junior Member
Hi Axel, thanks for the response.
I talk about Linux-Windows because I read some point in the discussions that let me think about some differences between the use of Eclipse in these OS.
In most of these discussion I read about:
1. removing the "lib" prefix in the inclusion -> what if there is no "lib" prefix? I must add it to the name of the file? Seems not to work...
2. removing the ".a" and ".so" in the inclusion -> Windows uses ".lib" extension. I don't get results by removing it in the inclusion
3. solutions for "shared libraries", where I can declare just the name of the library without path -> "shared libraries" is a Unix-oriented thing. In Windows I think I must specify the entire path odf the library...but I still get the error.

If someone can clarify me these points I'll be glad.

Thanks!
Re: Link .lib in Eclipse CDT for Windows, Cygwin G++ linker [message #809905 is a reply to message #809755] Wed, 29 February 2012 12:28 Go to previous messageGo to next message
Axel Mueller is currently offline Axel MuellerFriend
Messages: 1973
Registered: July 2009
Senior Member
Quote:
1. removing the "lib" prefix in the inclusion -> what if there is no "lib" prefix? I must add it to the name of the file? Seems not to work...

Usually libraries have the prefix lib (that as what everybody uses). But you can define the complete path and name using
-l library
(the space is important).

2. removing the ".a" and ".so" in the inclusion -> Windows uses ".lib" extension. I don't get results by removing it in the inclusion

The linker will use (or should) the correct extension depending on the platform. You should just omit the extension.

Quote:
3. solutions for "shared libraries", where I can declare just the name of the library without path -> "shared libraries" is a Unix-oriented thing. In Windows I think I must specify the entire path odf the library...but I still get the error.

Shared libraries are called DLLs on Windows. There is no difference to UNIX (only the extension). Under Properties->Tool Settings Tab->C++ Linker you can specify the paths where the linker will search for libraries (option -L) and you can give the name of the library.

Linker option for gcc are explained in http://gcc.gnu.org/onlinedocs/gcc-4.6.2/gcc/Link-Options.html#Link-Options


Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: Link .lib in Eclipse CDT for Windows, Cygwin G++ linker [message #809990 is a reply to message #809905] Wed, 29 February 2012 14:34 Go to previous messageGo to next message
Massimo Cristofolini is currently offline Massimo CristofoliniFriend
Messages: 5
Registered: February 2012
Junior Member
I made a couple of thests, but still without success.
Better talk about the specific problem first.
So, the libray (.lib) I need to link is a link library for a dll.
In Properties->C/C++ Build->Settings->Cross C++ Linker I've added "D:\Documenti\eclipse\workspace\HelloWorld" (where the DLL is) for -L option and "D:\Documenti\eclipse\workspace\HelloWorld\FlyCapture2.lib" in -l (complete .lib path).
The resulting command is:
g++ -L"D:\Documenti\eclipse\workspace\HelloWorld" -o "HelloWorld"  ./main.o   -lD:/Documenti/eclipse/workspace/HelloWorld/FlyCapture2.lib

-> file not found!
Adding the space before the .lib path in Cross C++ Linker option I get

g++ -L"D:\Documenti\eclipse\workspace\HelloWorld" -o "HelloWorld"  ./main.o   -l\ D:/Documenti/eclipse/workspace/HelloWorld/FlyCapture2.lib

like if the space is part of the path. of course, again, file not found.
I've added the space after -l option manually working from command line

g++ -L"D:\Documenti\eclipse\workspace\HelloWorld" -o "HelloWorld"  ./main.o   -l D:/Documenti/eclipse/workspace/HelloWorld/FlyCapture2.lib

Still no file found.

...what am I missing?

[Updated on: Wed, 29 February 2012 14:35]

Report message to a moderator

Re: Link .lib in Eclipse CDT for Windows, Cygwin G++ linker [message #809997 is a reply to message #809990] Wed, 29 February 2012 14:47 Go to previous messageGo to next message
Axel Mueller is currently offline Axel MuellerFriend
Messages: 1973
Registered: July 2009
Senior Member
Hmm, for the library you used slashes instead of backslashes. Can you try with backslashes? What about using cygwin path style?

BTW, you can omit the -L option when you specify the complete path with -l.

I think here is a good explanation for your problem http://eclipsesource.com/blogs/2010/03/03/shared-libraries-with-eclipse-cdt-and-cygwin-on-windows/


Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: Link .lib in Eclipse CDT for Windows, Cygwin G++ linker [message #810001 is a reply to message #809990] Wed, 29 February 2012 14:52 Go to previous messageGo to next message
Massimo Cristofolini is currently offline Massimo CristofoliniFriend
Messages: 5
Registered: February 2012
Junior Member
Update:
I renamed the library adding a"lib" prefix, but I forgot to delete it in the next tests. Shame on me!
The command
g++ -LD:/Documenti/eclipse/workspace/HelloWorld -o "HelloWorld"  ./main.o   -lFlyCapture2

finds the library (it seems so...), but I get "undefined references" to all the functions I call in the given namespace.
I'll try to figure this out (if there's some hints, they'll be appreciated!)

EDIT:
Late post! I'll read your link Axel, thanks.

[Updated on: Wed, 29 February 2012 14:53]

Report message to a moderator

Re: Link .lib in Eclipse CDT for Windows, Cygwin G++ linker [message #810043 is a reply to message #810001] Wed, 29 February 2012 16:00 Go to previous messageGo to next message
Fabien Bourrel is currently offline Fabien BourrelFriend
Messages: 14
Registered: February 2012
Junior Member
Hello,

I think that the option -l has to be before your .o file in the g++ command.
The linker searches and processes libraries and object files in the order they are specified.

So,
g++ ... main.o -lmylib

is different as
g++ ... -lmylib main.o


Hope this helps,
Fabien
Re: Link .lib in Eclipse CDT for Windows, Cygwin G++ linker [message #810059 is a reply to message #810043] Wed, 29 February 2012 16:29 Go to previous messageGo to next message
Massimo Cristofolini is currently offline Massimo CristofoliniFriend
Messages: 5
Registered: February 2012
Junior Member
Uhm...I think that the problem is the library itself, compiled with Visual Studio. I wasn't unable to use it with Borland (but I get differnet errors).
Maybe something similar here? Any experience about it?
Re: Link .lib in Eclipse CDT for Windows, Cygwin G++ linker [message #812613 is a reply to message #810059] Sun, 04 March 2012 03:14 Go to previous message
Todd Leftart is currently offline Todd LeftartFriend
Messages: 3
Registered: January 2012
Junior Member
at least with CDT 8.1(which I'm using), this is working for me:

if the .lib file is located at : X:\foo\lib\foo.lib, add the library search path (-L) as "/cygdrive/x/foo/lib", and add Libraries (-l) as "foo".
and don't forget add the path of the DLL's container folder in you PATH environment variable.

for the "undefined references" problem, it maybe caused by calling conventions, try adding "__stdcall" before the function name in your library header file.
Previous Topic:Call Hierarchy doesn't work as I would expect
Next Topic:"Single file build" error parsing
Goto Forum:
  


Current Time: Fri Apr 19 06:19:58 GMT 2024

Powered by FUDForum. Page generated in 0.03103 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top