Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Linking statically to 3rd party libraries (on linux)
Linking statically to 3rd party libraries (on linux) [message #765016] Tue, 13 December 2011 09:08 Go to next message
ben is currently offline benFriend
Messages: 7
Registered: December 2011
Junior Member
It feels like I'm fighting my tools, so if my workflow is completely wrong, please let me know.

Here is my plan:
I find a 3rd party library, could be anything, let's say Google Protobufs, so I do this:

  • Download it
  • Check it into SVN
  • Using Eclipse, check it out of SVN as a new autotools project
  • Check it builds.

Then what I want to do is set it up so that it exports a bunch of stuff for dependent projects:

  • Go into C/C++ General -> Export Settings
  • Export the include directory (relative to workspace)

Now I get stuck.

I want to export something to tell the linker that any project that depends on this project must link to the libprotobuf.a I just built.

It's easy enough to specify a search directory and specify that I want to export protobuf as the library, but how I can be sure that it will link statically to that library? How can I be sure it will link to the library I just built rather than finding it in /usr/lib or whatever?

Instead of having a command line that looks like:
g++ -L"/pathToWorkspace/ptotobuf/lib" -lprotobuf

I want:
g++ /pathToWorkspace/ptotobuf/lib/libprotobuf.a

Now, the reason I want to statically link everything is so that I know what I'm dealing with and to ease deployment and development across multiple machines. I don't want to be writing .rpms or .debs or whatever and managing dependencies like that, I just want it all linked into my binary. Am I doing it wrong?

I'm a bit new to developing on linux and frankly I don't know what will happen if I decide to build my project with gcc 4.6.2 with -std=c++0x and link against a 3rd party library that could be built with gcc 4.4 and with no C++11 support. I guess it's fine if the library interface is C, but perhaps not if it's C++? Anyway, I'd rather avoid the whole issue by building and linking everything myself. Again, I might just be doing it wrong(TM).
Re: Linking statically to 3rd party libraries (on linux) [message #765098 is a reply to message #765016] Tue, 13 December 2011 12:16 Go to previous messageGo to next message
Axel Mueller is currently offline Axel MuellerFriend
Messages: 1973
Registered: July 2009
Senior Member
Here is a detailed explanation.
http://librixxxi.blogspot.com/2010/09/building-static-libraries-and-test.html


Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: Linking statically to 3rd party libraries (on linux) [message #765439 is a reply to message #765098] Wed, 14 December 2011 03:59 Go to previous messageGo to next message
ben is currently offline benFriend
Messages: 7
Registered: December 2011
Junior Member
Hi, thanks for the link.

That's fine for libraries which I create myself but not for Makefile and Autotools projects because there is no Build Artifact tab for those.

Also, that article does seem to suggest that the g++ command line has g++ -L"/path" -lLibName rather than g++ /path/libLibName.a, which again is probably fine for my own libraries, but with myriad 3rd party library versions floating around my machine, I would rather tie down which one I'm linking against.
Re: Linking statically to 3rd party libraries (on linux) [message #765515 is a reply to message #765439] Wed, 14 December 2011 08:27 Go to previous messageGo to next message
Axel Mueller is currently offline Axel MuellerFriend
Messages: 1973
Registered: July 2009
Senior Member
Is your main project (the one with the executable) also a Makefile project? Then you must modify the makefile yourselves.

Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: Linking statically to 3rd party libraries (on linux) [message #765998 is a reply to message #765515] Thu, 15 December 2011 03:32 Go to previous messageGo to next message
ben is currently offline benFriend
Messages: 7
Registered: December 2011
Junior Member
The main project is a makefile project that is managed by eclipse. I've tried changing it to the internal CDT builder, but now I'm not getting any console output during build. The linking options seem to behave the same though.
Re: Linking statically to 3rd party libraries (on linux) [message #765999 is a reply to message #765515] Thu, 15 December 2011 03:32 Go to previous messageGo to next message
ben is currently offline benFriend
Messages: 7
Registered: December 2011
Junior Member
double post

[Updated on: Thu, 15 December 2011 03:33]

Report message to a moderator

Re: Linking statically to 3rd party libraries (on linux) [message #766120 is a reply to message #765998] Thu, 15 December 2011 08:54 Go to previous messageGo to next message
Axel Mueller is currently offline Axel MuellerFriend
Messages: 1973
Registered: July 2009
Senior Member
ben wrote on Thu, 15 December 2011 04:32
The main project is a makefile project that is managed by eclipse.

Then you can set the linker options in Project Properties->C/C++ Build->Settings


Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: Linking statically to 3rd party libraries (on linux) [message #768398 is a reply to message #766120] Tue, 20 December 2011 03:59 Go to previous message
ben is currently offline benFriend
Messages: 7
Registered: December 2011
Junior Member
Apologies for the delay and thanks again for your response.

I am aware that I can manually set the options there for every executable I need to produce.

I was wondering if it was possible to export from the library project the information required for the executable to statically link to the library file that was just built.
Previous Topic:vera++ Code Style Tool Integration
Next Topic:Installation on (K)Ubuntu Linux
Goto Forum:
  


Current Time: Fri Mar 29 05:13:13 GMT 2024

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

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

Back to the top