LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   How to compile a static binary? (https://www.linuxquestions.org/questions/linux-software-2/how-to-compile-a-static-binary-697658/)

<Ol>Origy 01-16-2009 12:48 AM

How to compile a static binary?
 
I am trying to compile a static binary of cryptsetup-1.0.6 from source for use within the initial ram disk (initrd). The commands "configure && make && make install" will compile a dynamically linked executable, but what are the correct commands to compile a static binary "cryptsetup.static"?

I assume it is "configure --enable-static" before invoking make && make install. The only problem is that in this case the make script spits out some error that the gcc tried to link a dynamic object libgcrypt.so.

chakka.lokesh 01-16-2009 02:16 AM

-static-libgcc

go through the above option in "man gcc"

<Ol>Origy 01-16-2009 08:36 AM

Here's the actual error that make spits out when using "configure --enable-static":
Quote:

gcc -g -O2 -o cryptsetup -static cryptsetup.o /usr/lib/libpopt.a ../lib/.libs/libcryptsetup.a -ldevmapper /usr/lib/libgcrypt.so -lnsl /usr/lib/libgpg-error.so -luuid
/usr/lib/gcc/i486-slackware-linux/4.1.2/../../../../i486-slackware-linux/bin/ld: attempted static link of dynamic object `/usr/lib/libgcrypt.so'
collect2: ld returned 1 exit status
make[2]: *** [cryptsetup] Error 1
make[2]: Leaving directory `/root/cryptsetup-1.0.6/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/root/cryptsetup-1.0.6'
make: *** [all] Error 2
And neither configure nor make seem to recognize the -static-libgcc flag.

aldesha989 01-16-2009 08:47 AM

try
make install

<Ol>Origy 01-17-2009 02:15 AM

Anyone?

I have noticed that my system lacked the two problematic static libraries - libgcrypt.a and libgpg-error.a - which the GCC tried to link their dynamic versions. I think I fixed the absence by downloading both libs from GnuPG website and compiling them from source using the standard "configure && make && make install" routine.

Trying to compile cryptsetup-1.0.6 with "configure --enable-static", make spits out this new error:
Quote:

gcc -g -O2 -o cryptsetup -static cryptsetup.o /usr/lib/libpopt.a ../lib/.libs/libcryptsetup.a -ldevmapper -L/usr/local/lib /usr/local/lib/libgcrypt.a /usr/lib/libgpg-error.so /usr/local/lib/libgpg-error.a -luuid
/usr/lib/gcc/i486-slackware-linux/4.1.2/../../../../i486-slackware-linux/bin/ld: attempted static link of dynamic object `/usr/lib/libgpg-error.so'
collect2: ld returned 1 exit status
make[2]: *** [cryptsetup] Error 1
make[2]: Leaving directory `/root/sources/cryptsetup-1.0.6/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/root/sources/cryptsetup-1.0.6'
make: *** [all] Error 2
Unfortunately, here is where I was stuck all along. I definitely have both static libs present now, but why is >make< still trying to link a shared library? Could it be a bug in the make script?

Valery Reznic 01-18-2009 02:27 AM

Quote:

Originally Posted by <Ol>Origy (Post 3411741)
Anyone?

I have noticed that my system lacked the two problematic static libraries - libgcrypt.a and libgpg-error.a - which the GCC tried to link their dynamic versions. I think I fixed the absence by downloading both libs from GnuPG website and compiling them from source using the standard "configure && make && make install" routine.

Trying to compile cryptsetup-1.0.6 with "configure --enable-static", make spits out this new error:

Unfortunately, here is where I was stuck all along. I definitely have both static libs present now, but why is >make< still trying to link a shared library? Could it be a bug in the make script?

You can use Ermine (http://magicErmine.com) or statifier (http://statifier.sf.net)
to create from dynamically linked file self-contained executable with all needed shared libraries.


All times are GMT -5. The time now is 08:50 PM.