我想編譯使用C++ 11的庫。該圖書館是一個子項目。 在其的CMakeLists.txt我設置C++ 11特徵與CXX_STANDARD
和CXX_STANDARD_REQUIRED
所見here。CMake的:C++ 11沒有設置與CXX_STANDARD
它沒有錯誤執行CMake的命令,但是當我開始編譯我得到關於C++ 11個功能缺失的錯誤,好像
In file included from /folder/OptionWidget.cpp:1:0:
/folder/OptionWidget.h:14:28: warning: defaulted and deleted functions only available with -std=c++0x or -std=gnu++0x [enabled by default]
/folder/OptionWidget.h:14:28: error: ‘virtual WTradeGui::OptionWidget::~OptionWidget()’ declared virtual cannot be defaulted in the class body
make[2]: *** [.../OptionWidget.cpp.o] Error 1
的錯誤在於,我宣佈在頭一個默認的虛擬析構函數virtual ~OptionWidget() = default;
如果我執行命令make VERBOSE=1
我可以看到,C++ 11標誌未被編譯在命令設置:
/usr/bin/c++ -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DQT_WIDGETS_LIB -I/folder/wtradegui -I/folder/wtradegui -I/folder/wtrade/src -isystem /qt/include -isystem /qt/QtWidgets -isystem /qt/QtGui -isystem /qt/QtCore -isystem -fPIC -o CMakeFiles/wtradegui.dir/OptionWidget.cpp.o -c /folder/OptionWidget.cpp
我使用Ubuntu 15.04,cmake 3.3.1和gcc 4.6.3。
同樣的項目使用內置的MinGW沒有窗戶下的問題,(抱歉,我不記得的版本,它的一個附帶的Qt 5.5.0版本)。
我必須以建立在Linux上的項目做什麼呢?
這是主要的CMakeList.txt
# In order to work following variables must be set
#
# QT_DIR: Path to Qt installation.
cmake_minimum_required (VERSION 3.1.0)
# Variables that should be set before execution
if (WIN32)
set (QT_DIR "" CACHE PATH "Qt library path")
else (WIN32)
set (QT_DIR "/usr/include" CACHE PATH "Qt library path")
endif (WIN32)
message ("Generating WPlot project")
message ("Setting QT_DIR To ${QT_DIR}")
add_subdirectory (wplot)
add_subdirectory (demo)
而這正是的CMakeLists.txt wplot文件夾內
# wPlot project
cmake_minimum_required (VERSION 3.1.0)
project (wplot)
set (major_version 0)
set (minor_version 0)
set (bugfix_version 1)
set (project_version ${major_version}.${minor_version}.${bugfix_version})
set (OUTPUT_DIR "build")
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/export/lib)
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/export/lib)
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/export/bin)
set (INCLUDE_EXPORT_DIRECTORY ${CMAKE_BINARY_DIR}/export/include/wplot)
set (CMAKE_DOC_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/export/doc)
set (CMAKE_PREFIX_PATH ${QT_DIR}/lib/cmake)
set (CMAKE_AUTOMOC ON)
set (CMAKE_INCLUDE_CURRENT_DIR ON)
message ("=== Generating WPlot ===")
message ("Setting QT_DIR To ${QT_DIR}")
message ("CMAKE_PREFIX_PATH set to ${CMAKE_PREFIX_PATH}")
find_package (Qt5Widgets REQUIRED)
include_directories (${CMAKE_SOURCE_DIR} ${Qt5Widgets_INCLUDE_DIRS})
file (GLOB_RECURSE WPLOT_SOURCES "*.cpp")
file (GLOB WPLOT_PUBLIC_HEADERS "*.h")
file (COPY ${WPLOT_PUBLIC_HEADERS} DESTINATION ${INCLUDE_EXPORT_DIRECTORY})
# Compile project
add_definitions(-DWPLOT_LIBRARY)
add_library (wplot SHARED ${WPLOT_SOURCES})
target_link_libraries(wplot ${Qt5Widgets_LIBRARIES})
set_target_properties(
wplot
PROPERTIES
VERSION ${project_version}
SOVERSION ${project_version}
)
set_property(TARGET wplot PROPERTY CXX_STANDARD 11)
set_property(TARGET wplot PROPERTY CXX_STANDARD_REQUIRED ON)