2017-04-17 152 views
0

我得到一个C++源代码和项目结构如下:如何使用arm-linux-gcc交叉编译gmock?

|-+ ACode 
    |-+ src //include code 
    |-+ include //include .h file 
    |-+ test 
    |-+ CMakeLists.txt 
.... //similar to the ACode 
|-+ build 
|-+ doc 
|-+ ThirdParty 
    |-+ googletest-release-1.8.0 
     |-+ googlemock 
     |-+ googletest 
     |-+ CMakeLists.txt 
    |-+ MultipartParser 
    |-+ rapidjson 
    |-+ CMakeLists.txt 
    |-+ googletest.cmake 
|-+ tests 
|-+ CMakeLists.txt 

我用的cmake - >化妆可以建立成功,可以执行在Linux平台上的成功。

现在我想用arm-linux-gcc交叉编译它。

获取错误信息修改项目的CMakeLists.txt文件之后。 的CMakeLists.txt文件中添加如下内容:

SET(CMAKE_SYSTEM_NAME Linux) 
SET(CMAKE_C_COMPILER "/../../toolschain/4.4.3/bin/arm-linux-gcc") 
SET(CMAKE_CXX_COMPILER "/../../toolschain/4.4.3/bin/arm-linux-g++") 

获取错误消息而使用make命令:

Scanning dependencies of target gmock_main [ 1%] Building CXX object ThirdParty/googletest-release-1.8.0/googlemock/CMakeFiles/gmock_main.dir/__/googletest/src/gtest-all.cc.o [ 2%] Building CXX object ThirdParty/googletest-release-1.8.0/googlemock/CMakeFiles/gmock_main.dir/src/gmock-all.cc.o In file included from /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock.h:58, from /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/src/gmock-all.cc:40: /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-actions.h: In static member function 'static Result testing::internal::ReturnNullAction::Perform(const ArgumentTuple&)': /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-actions.h:631: error: 'nullptr' was not declared in this scope In file included from /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-spec-builders.h:75, from /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-generated-function-mockers.h:43, from /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock.h:61, from /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/src/gmock-all.cc:40: /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h: In member function 'bool testing::internal::IsNullMatcher::MatchAndExplain(const Pointer&, testing::MatchResultListener*) const': /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:983: error: 'nullptr' was not declared in this scope /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h: In member function 'bool testing::internal::NotNullMatcher::MatchAndExplain(const Pointer&, testing::MatchResultListener*) const': /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1003: error: 'nullptr' was not declared in this scope /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h: At global scope: /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1560: sorry, unimplemented: cannot expand 'Tail ...' into a fixed-length argument list /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1561: error: 'int' is not a class type /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1561: error: 'ListType' in class 'int' does not name a type /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1561: error: template argument 2 is invalid /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1561: error: expected '::' before 'ListType' /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h: In static member function 'static int testing::internal::MatcherList::BuildList(const Head&, const Tail& ...)': /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1568: error: 'int' is not a class type /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1568: error: 'int' is not a class type /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1568: error: 'int' is not a class type /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1568: error: 'BuildList' is not a member of 'int' /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h: In static member function 'static testing::Matcher testing::internal::MatcherList::CreateMatcher(const int&)': /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1578: error: request for member 'first' in 'matchers', which is of non-class type 'const int' /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1579: error: 'int' is not a class type /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1579: error: 'int' is not a class type /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1579: error: 'int' is not a class type /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1579: error: 'int' is not a class type /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1579: error: 'int' is not a class type /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1579: error: 'CreateMatcher' is not a member of 'int' /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1580: error: request for member 'second' in 'matchers', which is of non-class type 'const int' /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1577: error: expected primary-expression before '(' token /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1578: error: request for member 'first' in 'matchers', which is of non-class type 'const int' /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1579: error: 'int' is not a class type /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1579: error: 'int' is not a class type /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1579: error: 'int' is not a class type /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1579: error: 'int' is not a class type /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1579: error: 'int' is not a class type /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1579: error: 'CreateMatcher' is not a member of 'int' /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1579: error: expected primary-expression before ',' token /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1579: error: missing template arguments before '>' token /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1580: error: request for member 'second' in 'matchers', which is of non-class type 'const int' /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h: At global scope: /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1623: sorry, unimplemented: cannot expand 'Args ...' into a fixed-length argument list /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1625: error: 'int' is not a class type /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1625: error: 'ListType' in class 'int' does not name a type /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h: In constructor 'testing::internal::VariadicMatcher::VariadicMatcher(const Args& ...)': /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1611: error: 'int' is not a class type /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1611: error: 'int' is not a class type /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1611: error: 'int' is not a class type /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1611: error: 'BuildList' is not a member of 'int' /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h: In member function 'testing::internal::VariadicMatcher::operator testing::Matcher() const': /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1618: error: 'int' is not a class type /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1618: error: 'int' is not a class type /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1618: error: 'int' is not a class type /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1618: error: 'int' is not a class type /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1618: error: 'int' is not a class type /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1618: error: 'CreateMatcher' is not a member of 'int' /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1618: error: expected primary-expression before ',' token /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1618: error: missing template arguments before '>' token /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h: At global scope: /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1631: error: expected unqualified-id before 'using' /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:1725: error: expected unqualified-id before 'using' In file included from /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-spec-builders.h:75, from /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-generated-function-mockers.h:43, from /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock.h:61, from /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/src/gmock-all.cc:40: /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:4363: error: expected initializer before '<' token /../../Linux+C/Temp/20170414/alexa-client-sdk-master/ThirdParty/googletest-release-1.8.0/googlemock/include/gmock/gmock-matchers.h:4368: error: expected initializer before '<' token make[2]: * [ThirdParty/googletest-release-1.8.0/googlemock/CMakeFiles/gmock_main.dir/src/gmock-all.cc.o] Error 1 make[1]: * [ThirdParty/googletest-release-1.8.0/googlemock/CMakeFiles/gmock_main.dir/all] Error 2 make: *** [all] Error 2

谁能帮助我如何修改的CMakeLists.txt文件? 还是我错过了什么?

回答

0

我的解决方案:

你只需要添加CMAKE_TOOLCHAIN_FILE到主的CMakeLists.txt:

cmake_minimum_required(VERSION 2.6.2)                                          


project(googletest-distribution)            


enable_testing()                 


# add CMAKE_TOOLCHAIN_FILE to here to support cross compilling. 
if(NOT CMAKE_TOOLCHAIN_FILE) 
    # nothing to do 
else() 
    # nothing to do 
endif()                   


option(BUILD_GTEST "Builds the googletest subproject" ON)      


#Note that googlemock target already builds googletest       

option(BUILD_GMOCK "Builds the googlemock subproject" OFF)      


if(BUILD_GMOCK)                 
    add_subdirectory(googlemock)             

elseif(BUILD_GTEST)                
    add_subdirectory(googletest)             

endif()      

十字compilling步:

mkdir build_linux_armv7 
cd build_linux_armv7 
cmake .. -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake 
make 
make install 

toolchain.cmake方面:

set(CMAKE_SYSTEM_NAME Linux)                                             

set(CMAKE_CROSSCOMPILING TRUE)             

set(CMAKE_CXX_COMPILER               
    /usr/bin/arm-linux-gnueabihf-g++)           

set(CMAKE_C_COMPILER                
    /usr/bin/arm-linux-gnueabihf-gcc)           

#set(CMAKE_FIND_ROOT_PATH              

# /your_compiler_root_directory/)            

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)          

set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)          

set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)