FindIconv: Explicitly references libc
When I used FindIconv.cmake
to find libiconv, it returned the system library /usr/lib/x86_64-linux-gnu/libc.so,
Then use ${Iconv_LIBRARIES}
with TARGET_LINK_LIBRARIES(MyTarget PUBLIC ${Iconv_LIBRARIES})
to my project and export the target file (*targets.cmake
).
In the target file, it shows:
set_target_properties(MyTarget PROPERTIES
INTERFACE_LINK_LIBRARIES "\$<LINK_ONLY:dl>;\$<LINK_ONLY:m>;/usr/lib/x86_64-linux-gnu/libc.so;..."
)
Then, I link this target to another project, and when linking to the library, it works fine, but the link fails in the executable file:
: && /usr/bin/cc -fPIC -O3 -DNDEBUG xx.c.o -ldl -lm -llibc && :
/usr/bin/ld: cannot find -llibc
Obviously, cmake converted the system library to -llibc
, and added a prefix lib
. However, it should be converted as -lc
.
Can somebody tell me why it happened?
Thanks.
Edited by Brad King