Can't link to specific OpenSSL library (Linux Mint 13) - linux

OpenSSL doesn't work well with valgrind unless you build it with a particular option so I've build OpenSSL again so that I can debug a program easily. The problem is, every time I build the program it links to an OpenSSL library I do not want. My makefile prints out a lot but the two lines that are most important are:
cc /usr/local/ssl/lib/libcrypto.so.1.0.0 /usr/local/ssl/lib/libssl.so.1.0.0 -L/opt/local/lib -shared -o bin/libcbitcoin-crypto.2.0.so build/CBOpenSSLCrypto.o
cc build/testCBNodeFull.o -L/home/matt/Desktop/cbitcoin/bin -lcbitcoin.2.0 -lcbitcoin-network.2.0 -lcbitcoin-storage.2.0 -lcbitcoin-threads.2.0 -lcbitcoin-logging.2.0 -lcbitcoin-crypto.2.0 -lcbitcoin.2.0 -lcbitcoin-file-ec.2.0 -lcbitcoin-rand.2.0 -L/opt/local/lib -lpthread -levent_core -levent_pthreads /usr/local/ssl/lib/libcrypto.so.1.0.0 -o bin/testCBNodeFull
As suggested elsewhere I'm specifying the precise location of the OpenSSL library I want. However ldd bin/testCBNodeFull gives me this:
libcrypto.so.1.0.0 => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0
There is apparently nothing wrong with the library I want to link to:
$ file bin/testCBNodeFull
bin/testCBNodeFull: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0xd9472ecc11e12dc66d165c807a5dbe31fd461cf2, not stripped
$ file /usr/local/ssl/lib/libcrypto.so.1.0.0
/usr/local/ssl/lib/libcrypto.so.1.0.0: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=0xb75602dc478ae55576e21aac5251b915b1653e73, not stripped
Both compiled as x86-64 as you can see. Maybe there is a tool that allows me to change the location of the shared library of the executable?

Shared libraries are loaded at runtime, not compile time. So, you need to tell valgrind which OpenSSL library you want it to use at runtime. You can do this by setting the LD_LIBRARY_PATH environment variable to the directory containing your rebuilt object.
export LD_LIBRARY_PATH=/home/matt/mylib
#now try ldd bin/testCBNodeFull

Related

object file not PIC showing relocatable?

I have a small library, and I build it with gcc without -fPIC option, I think this would mean that the generated object file will not be relocatable, but when I issued file command, it shows relocatable, why?
build command:
gcc -DNDEBUG -g -o module.o -c module.c
file module.o
module.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), with debug_info, not stripped
Because you are looking at the object file, before it is linked into a binary. ELF files are generally one of four types:
CORE core files
DYN Shared object file, for libraries
EXEC Executable file, for binaries
REL Relocatable file, before linked into an executable file
See this link for more info
You misunderstood the difference between position independent and relocatable. Position independent shared libraries have relative addresses and can work anywhere in the virtual memory WITHOUT modification of the text segment. However, relocatable shared libraries have absolute addresses, so their text segment is modified every time they are loaded into RAM.

How to specify GNU / Linux version compiling dropbear

I have a compiled binary of Dropbear. When I do file dbclient I get the following :
dbclient: ELF 32-bit LSB executable, ARM, version 1 (SYSV),
dynamically linked (uses shared libs), stripped
When I am trying to compile it on my own (very beginner) with
./configure --host=arm-linux-gnueabi --prefix=/ --disable-zlib
CC=arm-linux-gnueabi-gcc LD=arm-linux-gnueabi-ld make make install
I get the following after it compiled
dbclient: ELF 32-bit LSB executable, ARM, version 1 (SYSV),
dynamically linked (uses shared libs), for GNU/Linux 2.6.31,
BuildID[sha1]=0x016ac7e729afb02d60248393619b41380379777d, not stripped
For the stripped part, I don't care I could strip it later.
But my question is how to specify the "for GNU/Linux 2.6.31". What does it mean and how do I change it to target Linux 3.10.49 armv5tejl?

How to compile on linux so that the resulting executable does not require shared libraries

I successfully compiled swftools using their instructions (http://wiki.swftools.org/index.php/FAQ) on my Fedora 14 machine. I want to use one of the tools (pdf2swf) on another Linux machine. When I move it and run it on the other machine it asks for some shared libraries. Is it possible to compile swftools (in particular pdf2swf) so that when I run it on another Linux machine it does not ask for any shared libraries? It is OK if the executable itself is bigger in size, as far as it can run independently.
I am new to Linux, so if something requires advanced knowledge please point me to the appropriate online resource.
Regards
it's trivial: link with -static. of course, this implies that you'll need static libraries installed. the linker (often called through cc) simply defaults to using shared libraries when both are available.
[hahn#box ~]$ cat hello.c
#include <stdio.h>
int main() {
printf("Hello, world!\n");
return 0;
}
[hahn#box ~]$ cc hello.c -o hello
[hahn#box ~]$ file hello
hello: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, not stripped
[hahn#box ~]$ ldd hello
linux-gate.so.1 => (0x00205000)
libc.so.6 => /lib/libc.so.6 (0x00697000)
/lib/ld-linux.so.2 (0x005b4000)
[hahn#box ~]$ cc hello.c -o hello -static
[hahn#box ~]$ file hello
hello: ELF 32-bit LSB executable, Intel 80386, version 1 (GNU/Linux), statically linked, for GNU/Linux 2.6.32, not stripped
[hahn#box ~]$ ldd hello
not a dynamic executable
[hahn#box ~]$ ./hello
Hello, world!
to make this work, I needed to install glibc-static, which is not installed by default (at least on this box, which is Fedora14). some packages let you select static linking at the ./configure level, or else you may need to modify the Makefile.
Well, what you want are statically linked libraries, as opposed to dynamically/shared libraries.
You need to compile your application and link it statically. If you use gcc you can apply the static switch to your call of the compiler:
gcc -static <and the whole gcc shebang>
Most of the times you can edit the makefile (look for a CC define or CC_ARGS something like that) and just include the static switch as above.

Know more about shared libraries of a executable file

Is there a way to know what shared libraries are used from a executable file ?
From DivFix++ for example:
$ file DivFix++
DivFix++: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped
Using ldd:
$ ldd DivFix++
You can use the ldd command which prints the shared library dependencies:
ldd DivFix++

Shared Library file format not recognised

I am using a shared library. Which I am using it to cross compile my executable. During the linking stage linker throws the error file format not recognised.
When I run ld on it libcclass.so: file not recognized: File format not recognized
When I run file libcclass.so: it gives libcclass.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), not stripped
If you're cross-compiling an executable, you also need to cross-compile all of the shared libraries it depends on, and link against those. For example, you can't link an i386 executable to an x86_64 shared library.

Resources