C++链接mysql时出现错误:
/usr/bin/ld: 找不到 -lmysqlclient
collect2: 错误:ld 返回 1
make[2]: *** [../bin/hik] 错误 1
make[1]: *** [src/CMakeFiles/hik.dir/all] 错误 2
解决:
- 先找mysqlclient在那里
locate mysqlclient
- 因此在CMakeList.txt中添加下面一句:
link_directories(/usr/lib64/mysql)
然后继续cmake ..
,make
,发现出现如下错误:
LZTtools.cpp:(.text+0x1d):对‘mysql_init’未定义的引用
LZTtools.cpp:(.text+0x5b):对‘mysql_real_connect’未定义的引用
LZTtools.cpp:(.text+0x74):对‘mysql_error’未定义的引用
LZTtools.cpp:(.text+0xcc):对‘mysql_query’未定义的引用
LZTtools.cpp:(.text+0xde):对‘mysql_store_result’未定义的引用
LZTtools.cpp:(.text+0xee):对‘mysql_num_rows’未定义的引用
LZTtools.cpp:(.text+0x35f):对‘mysql_fetch_row’未定义的引用
解决:
- 修改CMakeList.txt的target_link_libraries
target_link_libraries(${PROJECT_NAME} libmysqlclient.so)