【问题标题】:Setting compiler right for meson为介子设置编译器
【发布时间】:2017-09-04 02:16:54
【问题描述】:

我正在尝试在我的 Mac(使用 macOS Sierra)上使用 Meson 构建系统构建一个基本的 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();
}

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

提前感谢您的帮助。

【问题讨论】:

    标签: c++ qt c++11 meson-build


    【解决方案1】:

    build 目录中执行以下操作

    mesonconf -Dcpp_std=c++11
    

    或者,在您的meson.build 文件中设置the default language version

    【讨论】:

    • 不幸的是,这并没有解决问题。我仍然收到以下错误:体系结构 x86_64 的未定义符号:... ld:未找到体系结构 x86_64 的符号 clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)忍者:构建已停止: 子命令失败。我认为这不是 C++11,而是链接器的某些东西我不正确。
    • 好的,我发现我忘记在 meson.build 中包含 Qt 模块“Gui”和“Core”。现在它编译和链接正常,但现在我在启动应用程序时收到以下错误:dyld: Library not loaded: @rpath/QtCore.framework/Versions/5/QtCore Referenced from: /Users/&lt;myname&gt;/sciebo/code/C++/QtDesignerCode/build/./qt5app Reason: image not found Abort trap: 6
    • 您最好编辑您的问题并包含最少的源代码以重现您看到的错误。因为,我无法复制它。我所做的只是从 qt creator 生成简单的mainwindow.cpp 和其他文件,并将meson.build 从您提到的 URL 中放入同一目录中。它在这里工作得很好。
    • 感谢您的建议,我编辑了问题并提供了示例代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-21
    • 1970-01-01
    • 2015-06-21
    • 1970-01-01
    • 1970-01-01
    • 2022-11-25
    • 2020-08-17
    相关资源
    最近更新 更多