The following is an example to describe my problem:
ld -Lpath1 -Lpath2 -lA -lB -Xlinker -T -Xlinker \
-W1,-rpath,/usr/local/lib -l-o target
ld: cannot find -lA
collect2: ld returned 2 exit status
Both path1 and path2 are relative paths, and I can find the library A according to the ld's pwd, so why did the ld output this error msg?
Could anyone give me some suggestion to debug this problem?
i miss some, there is a "-static" before a library called rt.
As your suggestion, i try to let gcc drive the ld to do linking process.
gcc A.o B.o -mabi=64 -static -lrt -Xlinker -T -Xlinker ld.script -W1,-rpath,/usr/local/lib -lmemdbg -o target
it don't work.
and then i remove the "-static" option, and another dynamic lib after -lpthread(because rt depend on pthread which is found when i remove the "-static")
gcc A.o B.o -mabi=64 -lrt -lpthread -Xlinker -T -Xlinker ld.script -W1,-rpath,/usr/local/lib -lmemdbg -o target
and this time, the objects is linked together successfully.
and then i try to figure out why the "-static" command don't work by passing a "-v" to gcc
. some "-L" option appeared, and do find a lib called librt.a in the search list.
i really confused. the version of gcc is 4.3
There are various issues that could be factors:
-W1option should probably be
-Wl, but that would not account for the link error.
-l-ooption should probably be two options with an argument for the
-loption (unless you really have a library
main()for you - and that only on classic Unix and not Linux systems.
lddirectly than when using the compiler instead.