无法使用 Google 的 protobuf 构建测试 C++ 应用程序

Can't build test C++ app with Google's protobuf

我正在尝试使用 CMake 构建示例 C++ protobuf 应用程序。但是linker找不到protobuf相关的一些方法。

我使用来自 developers guide 的示例 .proto 文件。但是当链接器尝试为 protobuf 生成的 C++ 代码构建目标文件时,我遇到了很多这样的错误:

undefined reference to `google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(int, std::string const&, google::protobuf::io::CodedOutputStream*)'
undefined reference to `google::protobuf::io::CodedOutputStream::WriteStringWithSizeToArray(std::string const&, unsigned char*)'
undefined reference to `google::protobuf::internal::empty_string_'
undefined reference to `google::protobuf::internal::InitEmptyString()'
undefined reference to `google::protobuf::internal::empty_string_once_init_'
undefined reference to `google::protobuf::internal::WireFormat::VerifyUTF8StringFallback(char const*, int, google::protobuf::internal::WireFormat::Operation, char const*)'

我使用自己用 GCC 4.8.4 构建的 protobuf 2.6.1。示例应用程序由 CMake 在 QTCreator 中使用 QT 5.5.1 工具集和 GCC 4.8.4 构建。有我的CMakeList.txt

project(protobuf-test)
cmake_minimum_required(VERSION 2.8)
aux_source_directory(. SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST})
LINK_DIRECTORIES(/usr/lib)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} pthread protobuf)

感谢帮助!

问题出在链接器搜索路径中。链接器尝试使用 OS 发行版(版本 8.0.0)中的 libprotobuf 而不是我构建的库(版本 9.0.1)。