Jiddoo
Jiddoo

Reputation: 1111

Setting compiler right for meson

I am trying to build a basic Qt Application with the Meson Build System on my Mac (using macOS Sierra), following the tutorial on http://mesonbuild.com/samples.html.

My meson.build file looks like this:

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')

I have a small test program consisting of only four files: main.cpp, mainwindow.h, mainwindow.cpp, and mainwindow.ui.

The source code is as follows.

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;
}

The program compiles and executes as expected when I use qmake as a build system using the following qmake-file:

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

When I execute

meson build

it works fine, except for the warning:

WARNING: rcc dependencies will not work reliably until this upstream issue is fixed: 
https://bugreports.qt.io/browse/QTBUG-45460

It also compiles without errors, when I switch to the build directory and call

ninja

but when I execute the program I get the following error:

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

It seems like the linker cannot find the libraries? Which is weird, as in Qt Creator (using qmake) the source code compiles fine.

Thanks in advance for any help.

Upvotes: 2

Views: 12820

Answers (1)

Yasushi Shoji
Yasushi Shoji

Reputation: 4274

Do the following in the build dir

mesonconf -Dcpp_std=c++11

or, set the default language version in your meson.build file

Upvotes: 0

Related Questions