Why does the -r option (roaming) make ld a library not found?

Running Debian / Linux x86_64 with GNU ld 2.21.

Simply put, if I contact

ld -o main main.o /usr/lib/crti.o /usr/lib/crt1.o /usr/lib/crtn.o -lc -lm

It works, but when I contact

ld -r -o main1.o main.o /usr/lib/crti.o /usr/lib/crt1.o /usr/lib/crtn.o -lc -lm

He complains

ld: cannot find -lc
ld: cannot find -lm

I am not actually trying to compile the code in this way, but I am trying to understand why someone else is testing whether the library exists, does not work. (So ​​I really don't understand what is happening with ld... usually I just use GCC for reference)

Why talk the ldlink in roaming mode so that it suddenly cannot find libraries? If I just want to check that there is -lm, what should I do besides

ld -r -lm

to find the library?

, , : https://github.com/jeremysalwen/ESPS ( , - , - , .)

+5
2

MacOS X

MacOS X ld -r:

-r mach-o MH_OBJECT.

, MacOS X, , -lm Mach-O, -lc. , main.o, obj1.o obj2.o, :

cp obj1.o ./-lm
cp obj2.o ./-lc
ld -r -o main1.o main.o -lm -lc

. , :

ld: warning: unexpected dylib (/usr/lib/libm.dylib) on link line
ld: warning: unexpected dylib (/usr/lib/libc.dylib) on link line

:

ld -r -o main1.o -arch x86_64 main.o obj1.o obj2.o

- .

Linux

Linux man- ld , :

-i ( ​​, -r).

-r
--relocatable

--- .. , ld. . , Unix, "OMAGIC". , . ++ ; -Ur.

, , , . ; , "a.out" .

, -i.

, ; . , , .

, , () -r, , .

, , . , autoconf, main.c, , , :

int main(void){return 0;}

C:

cc -o main main.c -lm -lc

, . , -lc, , -lm .

+3

echo $LD_PRELOAD?

, , ld .so . , LD_PRELOAD, .so.

0

All Articles