[問題] cmake有library undefined reference
開發平台(Platform): (Ex: Win10, Linux, ...)
Docker(linux ubuntu 16.04)
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
GCC
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
Redis
問題(Question)D:
在一個openvino的smaple中
想要
#include <hiredis/hiredis.h>
但是卻跑出
main.cpp:(.text+0x691): undefined reference to `redisCommand'
main.cpp:(.text+0x699): undefined reference to `freeReplyObject'
上網查後應該是庫沒有export
所以在環境變數中
export LD_LIBRARY_PATH=/usr/local/lib/libhiredis:$LD_LIBRARY_PATH
也在export中確定有此資料夾
但狀況卻一樣
餵入的資料(Input):
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
main.cpp:(.text+0x691): undefined reference to `redisCommand'
main.cpp:(.text+0x699): undefined reference to `freeReplyObject'
程式碼(Code):(請善用置底文網頁, 記得排版,禁止使用圖檔)
最上層的 CMakeLists
https://hackmd.io/@YlZanT8HShi_e7mTutiZ0g/r1bDHJ2fB
專案 cmakelist
https://hackmd.io/@YlZanT8HShi_e7mTutiZ0g/SJybuPozB
補充說明(Supplement):
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 203.77.33.178 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1564338949.A.C80.html
推
07/29 10:58,
6年前
, 1F
07/29 10:58, 1F
好的我用這個關鍵字查一下。
→
07/29 10:58,
6年前
, 2F
07/29 10:58, 2F
→
07/29 10:59,
6年前
, 3F
07/29 10:59, 3F
推
07/29 11:05,
6年前
, 4F
07/29 11:05, 4F
→
07/29 11:06,
6年前
, 5F
07/29 11:06, 5F
→
07/29 11:07,
6年前
, 6F
07/29 11:07, 6F
感謝回覆剛剛發現我貼錯cmakelist,所以修正抱歉。
※ 編輯: owem0410 (111.71.39.10 臺灣), 07/29/2019 11:21:59
※ 編輯: owem0410 (111.71.39.10 臺灣), 07/29/2019 11:42:54
推
07/29 12:51,
6年前
, 7F
07/29 12:51, 7F
→
07/29 22:43,
6年前
, 8F
07/29 22:43, 8F
→
07/29 22:43,
6年前
, 9F
07/29 22:43, 9F
感謝兩位大大的回答
在專案的cmakelist中加入下面
我一開始用發現是找的到的所以就卡住了
find_library(hiredis /usr/local/lib/ )
後來加入target_link_libraries(${TARGET_NAME} hiredis)
就可以成功build
※ 編輯: owem0410 (203.77.33.178 臺灣), 07/29/2019 22:55:25
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章
33
68