根据官网要求安装的是gmock官网安装过程,但是make的时候是需要gtest的。
我前几天编译cartographer是能成功的,最近自己在学习gtest,不知道改错了什么,不管怎么编译cartographer都不能成功。
遇到两个问题
在下载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了。
比较匪夷所思的是在编译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_ptrinternal::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::vectorchar> >*)’:
/usr/src/gtest/src/gtest-death-test.cc:1209:60: error: ‘void testing::internal::SplitString(const string&, char, std::vectorchar> >*)’ 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::vectorchar> >*)’
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的源码,而且还提供编译选项呢。。有知道的求告知~~