【cmake】利用cmakeList鏈接protobuf

利用cmakeList鏈接protobuf

include(FindProtobuf)
find_package(Protobuf REQUIRED "2.5.0")

if (Protobuf_FOUND)  # 需要特別注意Protobuf_FOUND的大小寫
    INCLUDE_DIRECTORIES(${PROTOBUF_INCLUDE_DIR})
else (Protobuf_FOUND)
    MESSAGE(FATAL_ERROR "PROTOBUF NOT FOUNED")
endif (Protobuf_FOUND)

add_library(common1 ${DIR_COMMON_SRCS})

link_directories(${PROTOBUF_LIBRARIES})
target_link_libraries(common1 ${PROTOBUF_LIBRARY_DEBUG}) # ${PROTOBUF_LIBRARY_DEBUG}這個代表了libprotobuf.so,不同的編譯,可能變量名不一樣,需要自己確定,如果不能自己確定的時候,cmake 編譯的時候帶上編譯選項--trace-expand

cmakeLists.txt鏈接protobuf的常見錯誤:

# undefine reference to kEmptyString 

解決方法:查找是否已經安裝了多版本的protobuf,重新卸載並安裝對應版本的protobuf

# missing protobuf include dir

解決方法:安裝protobuf,yum install protobuf

tips:

yum list installed | grep protobuf

whereis protobuf

which protoc

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章