1

我正在尝试按照http://mesonbuild.com/samples.html上的教程在我的 Mac(使用 macOS Sierra)上使用 Meson 构建系统构建一个基本的 Qt 应用程序。

我的 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。

源代码如下。

主.cpp:

#include "mainwindow.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    return a.exec();
}

主窗口.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

主窗口.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)中,源代码编译得很好。

提前感谢您的帮助。

4

1 回答 1

0

build目录中执行以下操作

mesonconf -Dcpp_std=c++11

或者,在文件中设置默认语言版本meson.build

于 2017-04-17T09:23:34.507 回答