[SATLUG] Creating a binary.....

Enrique Sanchez esanchezvela.satlug at gmail.com
Mon Mar 5 09:18:43 CST 2012

I have a little C program that I want to use across different environments
and I am trying to find a "smart" (aka lazy) way to be able to use it
without having to recompile it for every single version of a particular
library found in the environment.

so far, I have the object files of all programs involved just need to
perform the final linking phase of them all but so far I haven't been very
successful getting it to work...

here is the inventory...

[user at server 64bit]> ls -la
total 32
drwxr-xr-x 2 user user  4096 Mar  5 09:57 .
drwxr-xr-x 3 user user  4096 Mar  5 09:56 ..
-rw-r--r-- 1 user user  6344 Mar  3 22:22 keymgrd.o
-rw-r--r-- 1 user user 16368 Mar  3 22:22 km_utils.o

currently I get my binary using this command:

[user at server 64bit]>  gcc -v -lcrypto -lssl -o keymgrd  km_utils.o keymgrd.o

but I would like to get to a level where I could use just the linker
because I don't have GCC installed everywhere and I would like just to
relink the software every time I upgrade the OpenSSL library files, I've
been trying with the following command:

[user at server 64bit]>  ld  -o keymgrd  km_utils.o keymgrd.o -lcrypto -lssl
-lc  --entry main

it works in the sense that it creates the binary without a problem, however
when I try to run the program, it fails miserably to load. here is the ldd
output for each option...

When I ran GCC in verbose mode I saw it created the binary with "collect2"
with a bunch of "weird" parameters out of which I understood about 1/2 of

LDD output of the binary generated by GCC

[user at server 64bit]> ldd keymgrd

linux-vdso.so.1 =>  (0x00007fff56f68000)
libcrypto.so.6 => /lib64/libcrypto.so.6 (0x0000003ff9800000)
libssl.so.6 => /lib64/libssl.so.6 (0x0000003ffe200000)
libc.so.6 => /lib64/libc.so.6 (0x0000003ff1000000)
libdl.so.2 => /lib64/libdl.so.2 (0x0000003ff1800000)
libz.so.1 => /usr/lib64/libz.so.1 (0x0000003ff2000000)
libgssapi_krb5.so.2 => /usr/lib64/libgssapi_krb5.so.2 (0x0000003ffea00000)
libkrb5.so.3 => /usr/lib64/libkrb5.so.3 (0x0000003ffce00000)
libcom_err.so.2 => /lib64/libcom_err.so.2 (0x0000003ff8000000)
libk5crypto.so.3 => /usr/lib64/libk5crypto.so.3 (0x0000003ffca00000)
/lib64/ld-linux-x86-64.so.2 (0x0000003ff0c00000)
libkrb5support.so.0 => /usr/lib64/libkrb5support.so.0 (0x0000003ffda00000)
libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x0000003ffd600000)
libresolv.so.2 => /lib64/libresolv.so.2 (0x0000003ffa400000)
libselinux.so.1 => /lib64/libselinux.so.1 (0x0000003ff2c00000)
libsepol.so.1 => /lib64/libsepol.so.1 (0x0000003ff2800000)

LDD output when the linker is run alone:
[user at server 64bit]> ldd keymgrd
/usr/bin/ldd: ./keymgrd: /lib/ld64.so.1: bad ELF interpreter: No such file
or directory

as I said before I'd like to use a form of "ld" to create the binary
depending on the library found on the server and refresh the binary
whenever the libraries are updated.


Enrique Sanchez Vela

More information about the SATLUG mailing list