Shared Library file format not recognised - linux

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.

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 generate ARM object file on linux

I'm trying to generate ARM Object file under ubuntu using arm-none-eabi package but without success.
url describing this format:
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0041c/BCEJDJBC.html
root#ubuntu:~/arm/blink# arm-none-eabi-as hello.S
root#ubuntu:~/arm/blink# file a.out
a.out: ELF 32-bit LSB relocatable, ARM, version 1 (SYSV), not stripped

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

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

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++

Resources