I have built and installed my library according to the following cmake:
install(
TARGETS ${LIBRARY_NAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(
TARGETS ${LIBRARY_NAME}_static
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
so I get:
/usr/local/pkgconfig/libmylib.pc
/usr/local/lib/libmylib.0.1.1.dylib
/usr/local/lib/libmylib.0.dylib
/usr/local/lib/libmylib.dylib
/usr/local/lib/libmylib.a
/usr/local/include/libmylib.h
Now if I try to build test.c:
#include <libmylib.h>
int main() {
mylibfoo();
}
gcc test.c -lmylib
the source is compiled with the dynamic library.
else
gcc test.c
the linker gives the following error:
Undefined symbols for architecture x86_64:
"_mylibfoo", referenced from:
_main in mylibfoo-a8b267.o
I'm trying on the Darwin Kernel Version 19.3.0 (MacOS) system but I get the same result on a Linux system unless I build with: gcc test.c -l:libmylib.a
I want that if -l
was not specified, the build uses the static library.