【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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

bible_reader

如果觉得文章有用,欢迎打赏支持

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值