Compiling problems: cannot find crt1.o
Debian / Ubuntu The problem is you likely only have the gcc for your current architecture and that’s 64bit. You need the 32bit support files. For that, you need to install them sudo apt install gcc-multilib
Debian / Ubuntu The problem is you likely only have the gcc for your current architecture and that’s 64bit. You need the 32bit support files. For that, you need to install them sudo apt install gcc-multilib
Recent versions of gcc/ld default to linking with –as-needed. This means if you write -lexternal before the C file the library will automatically get excluded (the order matters when testing if things are “needed” like this) You can fix this with either of: gcc -L. -o program program.c -lexternal gcc -L. -Wl,–no-as-needed -lexternal -o program … Read more
Use –whole-archive linker option. Libraries that come after it in the command line will not have unreferenced symbols discarded. You can resume normal linking behaviour by adding –no-whole-archive after these libraries. In your example, the command will be: g++ -o program main.o -Wl,–whole-archive /path/to/libmylib.a In general, it will be: g++ -o program main.o \ -Wl,–whole-archive … Read more
You have to weaken and globalize the symbol using objcopy. -W symbolname –weaken-symbol=symbolname Make symbol symbolname weak. This option may be given more than once. –globalize-symbol=symbolname Give symbol symbolname global scoping so that it is visible outside of the file in which it is defined. This option may be given more than once. This worked … Read more
A typical BFD-ld or Gold linked Linux executable has 2 loadable segments, with the ELF header merged with .text and .rodata into the first RE segment, and .data, .bss and other writable sections merged into the second RW segment. Here is the typical section to segment mapping: $ echo “int foo; int main() { return … Read more
Passing -relocatable or -r to ld will create an object that is suitable as input of ld. $ ld -relocatable a.o b.o -o c.o $ gcc c.o other.o -o executable $ ./executable The generated file is of the same type as the original .o files. $ file a.o a.o: ELF 32-bit LSB relocatable, Intel 80386, … Read more
You can do this by executing the following command: ld –verbose | grep SEARCH_DIR | tr -s ‘ ;’ \\012 gcc passes a few extra -L paths to the linker, which you can list with the following command: gcc -print-search-dirs | sed ‘/^lib/b 1;d;:1;s,/[^/.][^/]*/\.\./,/,;t 1;s,:[^=]*=,:;,;s,;,; ,g’ | tr \; \\012 The answers suggesting to use … Read more
The -Wl,xxx option for gcc passes a comma-separated list of tokens as a space-separated list of arguments to the linker. So gcc -Wl,aaa,bbb,ccc eventually becomes a linker call ld aaa bbb ccc In your case, you want to say “ld -rpath .“, so you pass this to gcc as -Wl,-rpath,. Alternatively, you can specify repeat … Read more
It is for resolving circular dependences between several libraries (listed between -( and -)). Citing Why does the order in which libraries are linked sometimes cause errors in GCC? or man ld http://linux.die.net/man/1/ld -( archives -) or –start-group archives –end-group The archives should be a list of archive files. They may be either explicit file … Read more
LIBRARY_PATH is used by gcc before compilation to search directories containing static and shared libraries that need to be linked to your program. LD_LIBRARY_PATH is used by your program to search directories containing shared libraries after it has been successfully compiled and linked. EDIT: As pointed below, your libraries can be static or shared. If … Read more