Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Undefined symbols for architecture x86_64:



  • Hey gang,

    I've got a brand new laptop with Xcode 11, QT Creator 4.10.1 Based on QT 5.13.1 and OSX SDK 5.12.4 compiling with c++ 11

    I'm attempting to simply create a new project, and add a keyPressEvent. It's failing right away.

    Here's my entire .h file:

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include <QKeyEvent>
    
    QT_BEGIN_NAMESPACE
    namespace Ui { class MainWindow; }
    QT_END_NAMESPACE
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        MainWindow(QWidget *parent = nullptr);
        ~MainWindow();
    
    protected:
        void keyPressEvent( QKeyEvent *e );
    
    private:
        Ui::MainWindow *ui;
    };
    #endif // MAINWINDOW_H
    

    From project creation, I added these lines:

    #include <QKeyEvent>

    and

    protected:
    void keyPressEvent( QKeyEvent *e );

    That's it.

    Here's my entire .cpp (unchanged from project creation):

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    
    

    Here's the error I get:

    Undefined symbols for architecture x86_64:
    "MainWindow::keyPressEvent(QKeyEvent*)", referenced from:
    vtable for MainWindow in moc_mainwindow.o
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    make: *** [ScrollingText3.app/Contents/MacOS/ScrollingText3] Error 1
    12:01:04: The process "/usr/bin/make" exited with code 2.
    Error while building/deploying project ScrollingText3 (kit: Desktop Qt 5.12.4 clang 64bit)
    When executing step "Make"

    I'm following this example:
    https://www.youtube.com/watch?v=44fCm1KlQGY

    Under General messages, I see this:

    "Project WARNING: Qt has only been tested with version 10.14 of the platform SDK, you're using 10.15.
    Project WARNING: This is an unsupported configuration. You may experience build issues, and by using
    Project WARNING: the 10.15 SDK you are opting in to new features that Qt has not been prepared for.
    Project WARNING: Please downgrade the SDK you use to build your app to version 10.14, or configure
    Project WARNING: with CONFIG+=sdk_no_version_check when running qmake to silence this warning."

    Questions:

    1. What does this mean, and how does one address it?:
      Undefined symbols for architecture x86_64:

    2. How does one downgrade from platform SDK 10.15 to 10.14 (I'm attempting to download Xcode 10 to accomplish this)

    3. Are the two above connected? Am I getting the undefined symbols error because of the SDK version impropriety?

    4. Is the QKeyEvent still the proper function to use in the latest QT for capturing key presses and calling functions from them?

    5. How do I correct this?


  • Lifetime Qt Champion

    So where did you implement your MainWindow::keyPressEvent() function?



  • @Christian-Ehrlicher In this example I haven't yet. I did in the c++ file in another test project, but in this one I've narrowed it to the minimal code necessary to reproduce the error.

    Interestingly, if I right click over the function, I don't get the usual Refactor -> add definition in .cpp. So it isn't recognizing it as a valid function (unless I eliminate the QKeyEvent *e from the parens).


  • Lifetime Qt Champion

    So you wonder that the compiler complains that it doesn't find a function when you declare it but did not define it? Mhhh...
    Either remove the definition or implement your function.



  • @Christian-Ehrlicher Good catch. Adding the definition in the c++ file eliminated the error. :P


Log in to reply