【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

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