I get a "can't link with a main executable" when trying to link a precompiled library to a main file when compiling.
hostname:folder user$ g++ -o add testadd.cc -ladd -lmultiply -L.
ld: in ./libmultiply.dylib, can't link with a main executable
collect2: ld returned 1 exit status
hostname:folder user$
both libs (add and multiply) where compiled before, and are present in the same directory.
Can anyone give me a hint what can cause this error?
Thanx
PS: OSX 10.6.4 with g++-4.2.1
FYI:
When using the compiler-switch -dynamiclib and you get the above mentioned error, try compiling with -dynamiclib -undefined dynamic_lookup instead.
For me that worked. :)
好像有人遇到了类似的问题: ld无法与主可执行文件链接
I fiddled around a bit, and apparently I fixed it...
Before I compiled the shared lib with
g++ -o libmultiply.dylib libmultiply.cc -dynamiclib
and received the mentioned Error. Now I recompiled the lib again, with
g++ -o libmultiply.dylib libmultiply.cc -dynamiclib -undefined dynamic_lookup
and it seems to work now. (At least the compiling and linking.) But I still need to check, whether the lib actually does what it is suposed to. ;)
Up until now I dunno why the linking now does not report the error, but maybe someone else can shed some light into that with these infos. =)
just my 2 ct.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.