Linux使用cmake编译项目,如何使用cmake在linux中构建Qt项目(How to build Qt project in linux with cmake)...
如何使用cmake在linux中構建Qt項目(How to build Qt project in linux with cmake)
我使用的是ubuntu 14.04,cmake 2.8.12.2,Qt5.6.2(內置版本),GNU make 3.81
用cmake PathToSource -G "Eclipse CDT4 - Unix Makefiles"運行cmake之后
我做的。 我得到#error "You must build your code with position independent code if Qt was built with -reduce-relocations. " "Compile your code with -fPIC (-fPIE is not enough)." # error "You must build your code with position independent code if Qt was built with -reduce-relocations. "\ #error "You must build your code with position independent code if Qt was built with -reduce-relocations. " "Compile your code with -fPIC (-fPIE is not enough)." # error "You must build your code with position independent code if Qt was built with -reduce-relocations. "\
然后我下載Qt5.7.0源文件,構建并安裝它沒有問題。 我再做cmake PathToSource -G "Eclipse CDT4 - Unix Makefiles" ,制作它。 我收到很多錯誤,比如/home/sflee/Documents/Software_dev/3rd_party/Qt5.7.0/include/QtCore/qhash.h:957:10: error: 'pair' does not name a type auto pair = qAsConst(*this).equal_range(akey); 和/home/sflee/Documents/Software_dev/3rd_party/Qt5.7.0/include/QtCore/qbasicatomic.h:285:14: error: 'Ops' has not been declared { return Ops::fetchAndAddRelease(_q_value, valueToAdd); } /home/sflee/Documents/Software_dev/3rd_party/Qt5.7.0/include/QtCore/qbasicatomic.h:285:14: error: 'Ops' has not been declared { return Ops::fetchAndAddRelease(_q_value, valueToAdd); }
怎么解決?
I am using ubuntu 14.04, cmake 2.8.12.2, Qt5.6.2 (a built version), GNU make 3.81
After I run cmake with cmake PathToSource -G "Eclipse CDT4 - Unix Makefiles"
I do make. I get #error "You must build your code with position independent code if Qt was built with -reduce-relocations. " "Compile your code with -fPIC (-fPIE is not enough)." # error "You must build your code with position independent code if Qt was built with -reduce-relocations. "\
I then download source file of Qt5.7.0, build and install it without problem. I do again cmake PathToSource -G "Eclipse CDT4 - Unix Makefiles", make it. I get many errors, such as /home/sflee/Documents/Software_dev/3rd_party/Qt5.7.0/include/QtCore/qhash.h:957:10: error: ‘pair’ does not name a type auto pair = qAsConst(*this).equal_range(akey); and /home/sflee/Documents/Software_dev/3rd_party/Qt5.7.0/include/QtCore/qbasicatomic.h:285:14: error: ‘Ops’ has not been declared { return Ops::fetchAndAddRelease(_q_value, valueToAdd); }
How to solve it?
原文:https://stackoverflow.com/questions/40316244
更新時間:2020-07-05 07:07
最滿意答案
Qt 5.7需要C ++ 11編譯器。 如果你從auto pair得到那種錯誤,聽起來你的編譯器沒有編譯C ++ 11代碼。 有兩個可能的原因:
你只需要將-std=c++11傳遞給你的編譯器,正如這個問題所解釋的那樣 。
你有太舊的編譯器。 但是,由于您使用相同的編譯器編譯Qt 5.7本身,這對您來說應該不是問題。
Qt 5.7 requires C++11 compiler. If you get that kind of error from auto pair, it sounds like your compiler is not compiling C++11 code. There are two possible reasons:
You just need to pass -std=c++11 to your compiler, as explaned under this question.
You have too old compiler. However, since you compiled Qt 5.7 itself with the same compiler, this shouldn't be the problem for you.
2017-05-23
相關問答
你的腳本有幾個錯誤,還有一些東西可以改進。 更改后,它將如下所示: cmake_minimum_required(VERSION 3.0.2)
project(MyProject)
find_package(Qt5Widgets)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
add_library(mainwindow mainwindow.cpp)
target_link_lib
...
要在CMakeLists.txt中使用Qt5 ,您應該使用(組合)這些函數: 在頂級CMakeLists.txt中 #### Qt5
find_package( Qt5Core REQUIRED )
find_package( Qt5Widgets REQUIRED )
find_package( Qt5Gui REQUIRED )
find_package( Qt5OpenGL REQUIRED )
find_package( Qt5Multimedia REQUIRED )
find_pack
...
首先,如果要進行適當的依賴關系處理,請明確列出要包含的文件,替換file(GLOB ...) 。 這還將確保構建正在為您期望的文件集創建依賴關系。 除了下面的原因, 這個答案還有更多關于你可能想要這樣做的細節。 AUTOUIC的CMake文檔包括以下聲明: 如果找到與ui_.h匹配的預處理程序#include指令,并且存在.ui文件,則將執行uic以生成相應的文件。 您能否確認您的.cpp源代碼具有遵循此模式的#include指令? 在您的file(GLOB
...
CMake生成順序是根據文件和目標之間的依賴關系計算的。 如果您的qt庫依賴于.ui文件生成的標頭,那么您必須在目標qt輸入中添加${qt_UI_H} : QT5_WRAP_UI(qt_UI_H ${qt_UI})
[...]
add_library(qt "${DIR_SRC}/qt/form_main.cpp" ${qt_UI_H})
在編譯libqt之前,CMake通常應該在.ui文件上執行UIC 順便說一句,使用target_link_libraries只在鏈接時設置目標之間的依賴關系。
...
這不是cmake問題,而是使用about.cpp文件損壞。 由于某種原因,它有流浪的角色。 解決方案是“uncorrupt it”,然后它將使用相同的cmake文件。 This is not a cmake issue, but corruption with your about.cpp file. It has got stray characters for one reason or another. The solution is "uncorrupt it", and then it
...
將qt5添加到CMakeLists.txt與qt4不同,你可以找到許多這樣的有用鏈接,順便說一下我的ubuntu的版本是12.04并且我安裝了沒有apt-get的qt,我使用這種格式在我的cmakelists中查找qt。文本 : find_package(Qt5Widgets)
include_directories(${Qt5Widgets_INCLUDES}
/opt/Qt5.0.2/5.0.2/gcc/include/QtGui
/opt/Qt5.0.2/5.0.2/gcc/include
...
我認為你是這個bug的受害者(仍未解決)。 我不是100%確定出了什么問題,但你可以在評論中找到一些想法。 I think you're a victim of this bug (still unsolved). I'm not 100% sure of what's going wrong, but you can find some ideas in the comments.
您可以在Qt Creator中使用或不使用Qt,使用或不使用C ++編譯器,使用或不使用cmake二進制文件等。 Qt Creator使用工具包作為(多個)項目中一起使用的東西的集合,因此您不必一次又一次地定義這些相同的設置。 套件中可用的設置取決于您啟用的插件,如果未設置某些信息,Creator非常高興 - 只要您正在處理的項目不需要此信息。 因此,如果你打開一個基于qmake的項目,如果一個工具包沒有設置Qt版本(這是提供qmake二進制文件),創建者會抱怨。 如果您嘗試打開基于cmake的項
...
您需要使用CMAKE_PREFIX_PATH 。 例如: cmake.exe -DCMAKE_PREFIX_PATH="C:/path/to/Qt/5.X/compiler/lib/cmake"
You need to use CMAKE_PREFIX_PATH. For example: cmake.exe -DCMAKE_PREFIX_PATH="C:/path/to/Qt/5.X/compiler/lib/cmake"
Qt 5.7需要C ++ 11編譯器。 如果你從auto pair得到那種錯誤,聽起來你的編譯器沒有編譯C ++ 11代碼。 有兩個可能的原因: 你只需要將-std=c++11傳遞給你的編譯器,正如這個問題所解釋的那樣 。 你有太舊的編譯器。 但是,由于您使用相同的編譯器編譯Qt 5.7本身,這對您來說應該不是問題。 Qt 5.7 requires C++11 compiler. If you get that kind of error from auto pair, it sounds lik
...
總結
以上是生活随笔為你收集整理的Linux使用cmake编译项目,如何使用cmake在linux中构建Qt项目(How to build Qt project in linux with cmake)...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: kaggle账号_Kaggle 数据挖掘
- 下一篇: 两台服务器之间mysql数据库怎么做同步