cartographer

記錄一點小的問題

根據官網要求安裝的是gmock官網安裝過程,但是make的時候是需要gtest的。
我前幾天編譯cartographer是能成功的,最近自己在學習gtest,不知道改錯了什麼,不管怎麼編譯cartographer都不能成功。

遇到兩個問題

1.CMP0026

在下載github上的代碼後,直接cmake,因爲我的cmake版本是3.5,會有問題。有一個warning就是CMP0026。按照提示步驟上網查了,解決辦法如下。
在根目錄的CMakeLists.txt文件裏添加這句話

cmake_policy(SET CMP0026 OLD)

前幾行看起來是這樣子的

# Copyright 2016 The Cartographer Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required (VERSION 2.8.7)
cmake_policy(SET CMP0026 OLD)
project(cartographer)
set(CARTOGRAPHER_MAJOR_VERSION 1)
set(CARTOGRAPHER_MINOR_VERSION 0)
set(CARTOGRAPHER_PATCH_VERSION 0)
set(CARTOGRAPHER_VERSION ${CARTOGRAPHER_MAJOR_VERSION}.${CARTOGRAPHER_MINOR_VERSION}.${CARTOGRAPHER_PATCH_VERSION})
set(CARTOGRAPHER_SOVERSION ${CARTOGRAPHER_MAJOR_VERSION}.${CARTOGRAPHER_MINOR_VERSION})

之後在cmake是就不會有warning了。

2.gtest編譯報錯

比較匪夷所思的是在編譯cartographer時,需要找到gtest的源碼,而且還需要編譯。不是可以直接鏈接到已有的gtest庫嗎。。
按照教程

sudo apt-get install google-mock

在/usr/src下會出現gmock的目錄。但是看了gmock的CMakeLists發現還需要gtest。但是官網給出的步驟裏沒有gtest的安裝。不知道爲何。如果不安裝,那麼編譯cartographer時一定會出錯。
於是使用

sudo apt-get install libgtest-dev

會發現/usr/src多出了一個gtest文件夾,這樣子纔是正確的。

然而。。。這樣子也不一定可以。反正我這次編譯是失敗了。
在打開cmake-gui以後去觀察了cartographer的配置。其中有一句。
GMOCK_SRC_DIR
默認是會配置成/usr/src/gmock的。然而這樣配置,我在編譯時會死在%73的進度條上顯示

[ 72%] Building CXX object gmock/CMakeFiles/gmock.dir/usr/src/gtest/src/gtest-all.cc.o
In file included from /usr/src/gtest/src/gtest-all.cc:42:0:
/usr/src/gtest/src/gtest.cc: In destructor ‘virtual testing::Test::~Test()’:
/usr/src/gtest/src/gtest.cc:1897:10: error: type ‘const class testing::internal::scoped_ptr<testing::internal::GTestFlagSaver>’ argument given to ‘delete’, expected pointer
   delete gtest_flag_saver_;
          ^
/usr/src/gtest/src/gtest.cc: At global scope:
/usr/src/gtest/src/gtest.cc:2177:1: error: prototype for ‘testing::TestInfo::TestInfo(const string&, const string&, const char*, const char*, testing::internal::TypeId, testing::internal::TestFactoryBase*)’ does not match any in class ‘testing::TestInfo’
 TestInfo::TestInfo(const std::string& a_test_case_name,
 ^
In file included from /usr/local/include/gtest/internal/gtest-internal.h:40:0,
                 from /usr/local/include/gtest/gtest.h:58,
                 from /usr/src/gtest/src/gtest-all.cc:39:
/usr/local/include/gtest/gtest.h:772:3: error: candidates are: testing::TestInfo::TestInfo(const testing::TestInfo&)
   GTEST_DISALLOW_COPY_AND_ASSIGN_(TestInfo);
   ^
In file included from /usr/src/gtest/src/gtest-all.cc:39:0:
/usr/local/include/gtest/gtest.h:728:3: error:                 testing::TestInfo::TestInfo(const string&, const string&, const char*, const char*, testing::internal::CodeLocation, testing::internal::TypeId, testing::internal::TestFactoryBase*)
   TestInfo(const std::string& test_case_name,
   ^
In file included from /usr/src/gtest/src/gtest-all.cc:42:0:
/usr/src/gtest/src/gtest.cc: In function ‘testing::TestInfo* testing::internal::MakeAndRegisterTestInfo(const char*, const char*, const char*, const char*, testing::internal::TypeId, testing::internal::SetUpTestCaseFunc, testing::internal::TearDownTestCaseFunc, testing::internal::TestFactoryBase*)’:
/usr/src/gtest/src/gtest.cc:2227:45: error: no matching function for call to ‘testing::TestInfo::TestInfo(const char*&, const char*&, const char*&, const char*&, const void*&, testing::internal::TestFactoryBase*&)’
                    fixture_class_id, factory);
                                             ^
In file included from /usr/local/include/gtest/internal/gtest-internal.h:40:0,
                 from /usr/local/include/gtest/gtest.h:58,
                 from /usr/src/gtest/src/gtest-all.cc:39:
/usr/local/include/gtest/gtest.h:772:3: note: candidate: testing::TestInfo::TestInfo(const testing::TestInfo&)
   GTEST_DISALLOW_COPY_AND_ASSIGN_(TestInfo);
   ^
/usr/local/include/gtest/gtest.h:772:3: note:   candidate expects 1 argument, 6 provided
In file included from /usr/src/gtest/src/gtest-all.cc:39:0:
/usr/local/include/gtest/gtest.h:728:3: note: candidate: testing::TestInfo::TestInfo(const string&, const string&, const char*, const char*, testing::internal::CodeLocation, testing::internal::TypeId, testing::internal::TestFactoryBase*)
   TestInfo(const std::string& test_case_name,
   ^
/usr/local/include/gtest/gtest.h:728:3: note:   candidate expects 7 arguments, 6 provided
In file included from /usr/src/gtest/src/gtest-all.cc:42:0:
/usr/src/gtest/src/gtest.cc: In function ‘void testing::internal::InitGoogleTestImpl(int*, CharType**)’:
/usr/src/gtest/src/gtest.cc:4983:3: error: ‘g_argvs’ was not declared in this scope
   g_argvs.clear();
   ^
In file included from /usr/src/gtest/src/gtest-all.cc:43:0:
/usr/src/gtest/src/gtest-death-test.cc: In function ‘void testing::internal::SplitString(const string&, char, std::vector<std::__cxx11::basic_string<char> >*)’:
/usr/src/gtest/src/gtest-death-test.cc:1209:60: error: ‘void testing::internal::SplitString(const string&, char, std::vector<std::__cxx11::basic_string<char> >*)’ was declared ‘extern’ and later ‘static’ [-fpermissive]
                         ::std::vector< ::std::string>* dest) {
                                                            ^
In file included from /usr/local/include/gtest/gtest.h:58:0,
                 from /usr/src/gtest/src/gtest-all.cc:39:
/usr/local/include/gtest/internal/gtest-internal.h:612:6: note: previous declaration of ‘void testing::internal::SplitString(const string&, char, std::vector<std::__cxx11::basic_string<char> >*)’
 void SplitString(const ::std::string& str, char delimiter,
      ^
In file included from /usr/src/gtest/src/gtest-all.cc:45:0:
/usr/src/gtest/src/gtest-port.cc: In function ‘const char* testing::internal::StringFromGTestEnv(const char*, const char*)’:
/usr/src/gtest/src/gtest-port.cc:798:75: error: ambiguating new declaration of ‘const char* testing::internal::StringFromGTestEnv(const char*, const char*)’
 const char* StringFromGTestEnv(const char* flag, const char* default_value) {
                                                                           ^
In file included from /usr/local/include/gtest/internal/gtest-internal.h:40:0,
                 from /usr/local/include/gtest/gtest.h:58,
                 from /usr/src/gtest/src/gtest-all.cc:39:
/usr/local/include/gtest/internal/gtest-port.h:2555:13: note: old declaration ‘std::__cxx11::string testing::internal::StringFromGTestEnv(const char*, const char*)’
 std::string StringFromGTestEnv(const char* flag, const char* default_val);
             ^
In file included from /usr/src/gtest/src/gtest-all.cc:48:0:
/usr/src/gtest/src/gtest-typed-test.cc: In member function ‘const char* testing::internal::TypedTestCasePState::VerifyRegisteredTestNames(const char*, int, const char*)’:
/usr/src/gtest/src/gtest-typed-test.cc:71:31: error: ‘defined_test_names_’ was not declared in this scope
     for (DefinedTestIter it = defined_test_names_.begin();
                               ^
/usr/src/gtest/src/gtest-typed-test.cc:88:29: error: ‘defined_test_names_’ was not declared in this scope
   for (DefinedTestIter it = defined_test_names_.begin();
                             ^
gmock/CMakeFiles/gmock.dir/build.make:62: recipe for target 'gmock/CMakeFiles/gmock.dir/usr/src/gtest/src/gtest-all.cc.o' failed
make[2]: *** [gmock/CMakeFiles/gmock.dir/usr/src/gtest/src/gtest-all.cc.o] Error 1
CMakeFiles/Makefile2:261: recipe for target 'gmock/CMakeFiles/gmock.dir/all' failed
make[1]: *** [gmock/CMakeFiles/gmock.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2

解決辦法是去github上下載googletest-master
自己編譯一遍。之後在cartographer的CMakeLists.txt裏的GMOCK_SRC_DIR爲
具體路徑按照自己的環境來配置。

/home/xjh/workspace/googletest-master/googlemock

之後編譯就能成功了。
我還是不清楚爲何cartographer一定要找到gtest的源碼,而且還提供編譯選項呢。。有知道的求告知~~

發佈了36 篇原創文章 · 獲贊 18 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章