Static linking vs. dynamic linking?
I have written an OpenGL based program which uses i.a. libjpeg that I want to link statically so I can send it to someone who doesn't have all the libraries needed installed to allow for a dynamically linked executable to run.
As such I tried with giving the [b]-static[b] parameter to gcc. Code:
x86_1$ make |
Quote:
|
Quote:
Where can I get it? I don't see anything to it here: http://www.opengl.org/resources/libr..._downloads.php |
After reading some I learned I needed the libglut.a file, which I happened to have around for some reason ... after installing it I simply get instead:
Code:
/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../i486-slackware-linux/bin/ld: cannot find -lGL I also found: http://www.linuxquestions.org/questi...ith-gcc-80200/ which seem to state that this is actually quite tricky to do. What is the static version of GL called? |
Quote:
You already use -L<path>, so you might need to just another -L<path> for the static library. By the way, you might come to the conclusion that in your case it would be more convenient to call 'ld' directly. |
Quote:
|
Quote:
I.e. check your distro package manager features. In the worst case you'll build the library from source. |
Quote:
|
Quote:
|
Saw this : http://forum.lafox.net/index.php?showtopic=15150 thread in Russian - it appears libGL comes with proprietary NVidia/TI drivers. And at all it might be just libGL.so.
|
|
By taking static libraries from another distro (Ubuntu) and simply copy the .a files I needed I have managed to remove all missing libraries that were not found by the linker when attempting to link statically.
However, now I simply get this: Code:
/usr/X11R6/lib/libglut.a(glut_event.o): In function `interruptibleXNextEvent': I then tried to copy in the libX11.a library, which fixed some of them, but not nearly all; what else files do I need? Thanks for the help so far by the way. Is there a way to link statically against some, but not all libraries? I don't really need to link against X11. |
Quote:
I am not sure whether you can link statically against some, but not all libraries, check 'ld' switches for this. Start from 'ldd --help | less' and check all the switches controlling library search places and order. My gut tells me you better create a directory into which you symlink just the needed libraries and make 'ld' look for libraries only in that directory. Probably you'll need to create a toy program and toy libraries to check static/dynamic libraries mixture. What you can do for sure is to use 'dlopen' in your program, i.e. in such a manner you deal with dynamic libraries loading. |
You should only statically link the library that you need to have linked statically, not all of them.
It is easy enough to do. Just list the lib you want linked statically as another object file to link. |
All times are GMT -5. The time now is 09:04 PM. |