1
我想在我的Mac上使用Meson構建系統(使用macOS Sierra)構建一個基本的Qt應用程序,按照http://mesonbuild.com/samples.html的教程。爲介子設置編譯器
我meson.build文件看起來像這樣:
project('qt5 demo', 'cpp',
default_options : ['cpp_std=c++11'])
qt5_dep = dependency('qt5', modules : ['Core', 'Gui', 'Widgets'])
# Import the extension module that knows how
# to invoke Qt tools.
qt5 = import('qt5')
prep = qt5.preprocess(moc_headers : 'mainWindow.h',
ui_files : 'mainWindow.ui')
executable('qt5app',
sources : ['main.cpp', 'mainWindow.cpp', prep],
dependencies : qt5_dep,
cpp_args : '-std=c++11')
我只由四個文件一個小測試程序:main.cpp中,mainwindow.h,mainwindow.cpp和mainwindow.ui。
源代碼如下。
main.cpp中:
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
mainwindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
mainwindow.cpp:
#include "mainwindow.h"
#include "ui_mainWindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
的程序編譯,當我使用的qmake作爲預期執行使用以下qmake文件構建系統:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = QtDesigner
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
當我執行
meson build
它工作得很好,除了警告:
WARNING: rcc dependencies will not work reliably until this upstream issue is fixed:
https://bugreports.qt.io/browse/QTBUG-45460
它還會編譯沒有錯誤,當我切換到構建目錄,並調用
ninja
但是當我執行該程序時出現以下錯誤:
dyld: Library not loaded: @rpath/QtCore.framework/Versions/5/QtCore
Referenced from:
/Users/<myname>/code/C++/QtDesignerCode/build/./qt5app
Reason: image not found
Abort trap: 6
這似乎是鏈接器找不到庫?這很奇怪,就像在Qt Creator中(使用qmake)源代碼編譯得很好。
在此先感謝您的幫助。
不幸的是設置the default language version,沒有解決不了的問題。我仍然得到以下錯誤: 用於建築x86_64的未定義符號: ... LD:符號(S)沒有發現建築x86_64的 鐺:錯誤:連接命令失敗,退出代碼1(使用-v看到 調用) 忍者:建立停止:子命令失敗。 我認爲這不是C++ 11,而是鏈接器的東西,我不明白。 – Jiddoo
好吧,我發現我忘了在meson.build中包含Qt模塊的'Gui'和'Core'。現在它編譯並鏈接正常,但是現在我在啓動應用程序時出現以下錯誤: 'dyld:Library未加載:@ rpath/QtCore。/用戶/ /sciebo/code/C++/QtDesignerCode/build/./qt5app 原因:沒有找到圖片 中止陷阱:框架/版本/ 5/QtCore 從引用6 ' –
Jiddoo
你最好編輯您的問題幷包含最小的源代碼來重現您所看到的錯誤。因爲,我無法複製它。我所做的只是從qt創建者生成簡單的'mainwindow.cpp'和其他文件,並將您提到的URL中的'meson.build'放在同一個目錄中。它在這裏工作得很好。 –