How to Statically Link a Library

Mar 16, 2011 at 11:24am
Hey guys :D I have a quick question!

I have a program that uses the GTK+ library however I would like to statically link it to see if I can get it to run on linux platforms that don't necessarily have the correct versions of the required shared libraries.

My make file looks like this:

1
2
myBinary: main.cpp
g++ main.cpp 'pkg-config --cflags --libs gtk+-2.0' -o myBinary


Is this a case of adding/modifying part of the g++ command arguments?

Best regards, aatwo.
Mar 16, 2011 at 11:35am
Mar 16, 2011 at 2:08pm
Thanks :) nice and simple. Unfortunately GTK is apparently not statically linkable and gives me loads of errors. Worth a try though. thank you :)
Last edited on Mar 16, 2011 at 2:08pm
Mar 16, 2011 at 8:20pm
I tried to respond earlier, but it didn't work...

GTK is licensed under the LGPL, so most people just dynamically link with it. If you statically link, your code must also be licensed as GPL or LGPL.

It is possible to do it. However, you must recompile the GTK library using the static link options. Once you have the static library, you can statically link your program with it.

Good luck!
Topic archived. No new replies allowed.