2016-08-25 8 views
0

私はCMakeでサンプルC++ protobufアプリケーションを構築しようとしています。しかし、リンカーはprotobufに関連するいくつかのメソッドを見つけることができません。GoogleのprotobufでテストC++アプリケーションをビルドできません

例.protoファイルをdevelopers guideから使用します。リンカがいるProtobuf用のオブジェクトファイルをビルドしようとすると、しかし、私はこのようなエラーがたくさんあるC++コード生成:私はいるProtobuf 2.6.1を使用

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で自分自身を構築しました。サンプルアプリケーションは、CMakeによってQTCreatorでQT 5.5.1 Toolsetと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) 

ありがとうございます!

+0

自分でprotobufを作成した場合は、どこにインストールしましたか? '/ usr/lib'システムでは?通常の '/ usr/local/lib'では?どこか別の場所? –

+1

あなたのリンカコマンドを貼り付け、protobufのlibが検索パスにあることを確認する必要があります。 – Bruce

+0

私は_libprotobuf_を '/ usr/lib'にインストールしました。そして私はCMakeList.txtで 'LINK_DIRECTORIES(/ usr/lib)'を使ってこのパスをリンカのserachパスに追加します。 – piphonom

答えて

0

問題がリンカー検索パスにありました。リンカは、私が作成したlib(バージョン9.0.1)の代わりにOS distributon(バージョン8.0.0)からlibprotobufを使用しようとしました。

関連する問題