I'm trying to create a static library and link to it a symbol from another static library, which is used by it. Although I pass to target_link_library necessary lib, the symbol is not included. See the small example below:
This is my library.cpp
:
#include <mysql.h>
void fun() {
MYSQL* x;
mysql_errno(x);
}
And this is CMakeLists.txt
file:
add_library(mylib library.cpp)
target_include_directories(mylib /usr/include/mysql)
target_link_libraries(mylib PUBLIC /usr/lib/x86_64-linux-gnu/libmysqlclient.a)
After running cmake .. && make
, the library libmylib.a is created, but it doesn't contain mysql_errno
symbol:
arrno@zzz1-msi:~$ cmake .. && make
Scanning dependencies of target mylib
[ 50%] Building CXX object CMakeFiles/mylib.dir/library.o
[100%] Linking CXX static library libmylib.a
arrno@zzz1-msi:~$ nm libmylib.a
library.o:
U _GLOBAL_OFFSET_TABLE_
U mysql_errno
0000000000000000 T _Z3funv
In libmysqlclient.a the symbol mysql_errno
is defined:
arrno@zzz1-msi:~$ nm /usr/lib/x86_64-linux-gnu/libmysqlclient.a | grep mysql_errno
0000000000000000 T mysql_errno
I want to use libmylib.a
in my programs without linking libmysqlclient.a
. Now I cannot. What have I done wrong?