2

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.

Jiddoo
  • 1,091
  • 2
  • 9
  • 14

1 Answers1

0

Do the following in the build dir

mesonconf -Dcpp_std=c++11

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

Yasushi Shoji
  • 4,028
  • 1
  • 26
  • 47
  • Unfortunately, that did not solve the issue. I still get the following error: Undefined symbols for architecture x86_64: ... ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) ninja: build stopped: subcommand failed. I think it is not the C++11 but something with the linker which I don't get right. – Jiddoo Apr 17 '17 at 12:34
  • Ok, I found I forgot to include the Qt modules 'Gui' and 'Core' in the meson.build. Now it compiles and links fine, but now I get the following error, when starting the application: `dyld: Library not loaded: @rpath/QtCore.framework/Versions/5/QtCore Referenced from: /Users//sciebo/code/C++/QtDesignerCode/build/./qt5app Reason: image not found Abort trap: 6 ` – Jiddoo Apr 18 '17 at 09:42
  • You'd better edit your question and include minimum source code to reproduce the error you are seeing. Because, I can't reproduce it. All I did was to generate simple `mainwindow.cpp` and other files from qt creator, and put the `meson.build` from the URL you mentioned in the same dir. It just works fine here. – Yasushi Shoji Apr 19 '17 at 05:27
  • Thanks for the advice, I edited the question and provided the sample code. – Jiddoo Apr 20 '17 at 11:12