CMake添加C++11特性,解决:no member named XXX in namespace std



  • 先检测当前编译系统是否支持c++11,如果支持的话将"-std=c++11"加入编译参数中。


    include(CheckCXXCompilerFlag)
    CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
    CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
    if(COMPILER_SUPPORTS_CXX11)
            set(CMAKE_CXX_FLAGS "-std=c++11")
    elseif(COMPILER_SUPPORTS_CXX0X)
            set(CMAKE_CXX_FLAGS "-std=c++0x")
    else()
         message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
    endif()
    
    set(CMAKE_CXX_COMPILER "g++")
    set(CMAKE_BUILD_TYPE "Debug")
    set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb -m64 ${CMAKE_CXX_FLAGS}")
    set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall -m64 ${CMAKE_CXX_FLAGS}")
    

    这可以解决一些类似这样的问题:

    • error: no member named ‘tuple’ in namespace ‘std’
    • error: no member named ‘vector’ in namespace ‘std’

Log in to reply