Virtual
Virtual

Reputation: 131

symbol(s) not found for architecture x86_64 mac os 10.13.3

I know this question was already asked like a thousand times but i tried every solution and nothing helped.

I made a little program in Qt and after a while i got this error message:

symbol(s) not found for architecture x86_64
linker command failed with exit code 1 (use -v to see invocation)

I redid the qmake command and the rebuild project, nothing worked. I'm new in Qt. I am using Qt version 5.10.0 on mac os 10.13.3

Here are my files:

gui.h

#ifndef GUI_H
#define GUI_H

#include <QWidget>
#include <QPainter>

#include <QHBoxLayout>
#include <QVBoxLayout>

#include <QPushButton>
#include <QLineEdit>

class gui : public QWidget
{
    Q_OBJECT

public:
    gui(QWidget *parent = 0);
    ~gui();

private:
    QHBoxLayout *hbox1;
    QHBoxLayout *hbox2;
    QVBoxLayout *vbox;

    QPushButton *search;
    QPushButton *replace;

    QLineEdit *searchText;
    QLineEdit *replaceText;
    QLineEdit *textField;

public slots:

    void find();
    void replaceFuckingText();
};

#endif // GUI_H

gui.cpp

#include "gui.h"

gui::gui(QWidget *parent)
    : QWidget(parent)
{

    hbox1 = new QHBoxLayout();
    hbox2 = new QHBoxLayout();
    vbox = new QVBoxLayout();

    search = new QPushButton("Search");
    replace = new QPushButton("Replace");

    searchText = new QLineEdit();
    replaceText = new QLineEdit();
    textField = new QLineEdit();

    hbox1->addWidget(searchText);
    hbox1->addWidget(replaceText);

    vbox->addLayout(hbox1);

    hbox2->addWidget(search);
    hbox2->addWidget(replace);

    vbox->addLayout(hbox2);

    vbox->addWidget(textField);

    setLayout(vbox);
    show();

    connect(replace,SIGNAL(clicked()), this, SLOT(replaceFuckingText()));

}

gui::~gui()
{

}

void gui::replaceFuckingText() {
    QString searchTextValue = searchText->text();
    QString replaceTextValue = replaceText->text();
    QString textToReplace = textField->text();

    textToReplace.replace(searchTextValue,replaceTextValue);

    textField->setText(textToReplace);
}

main.cpp:

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

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    gui w;
    w.show();

    return a.exec();
}

I hope you can help me. I'm working on this error for over a week now. If you need more informations feel free to ask and I'll post them.

Upvotes: 1

Views: 17224

Answers (2)

Mitch
Mitch

Reputation: 24386

If you're really tired and accidentally add the .cpp file to HEADERS instead of SOURCES in your .pro file, you can also get this error.

Upvotes: 0

Mohammad Kanan
Mohammad Kanan

Reputation: 4582

symbol(s) not found for architecture x86_64

on MacOS generally is not difficult to diagnose and generally it comes from something you defined in headers but does not have proper implementation!

to know why exactly you got this message click Compiler Output in Qt Creator, most likely you will see where the make error is coming from, in your code case I see below error:

Undefined symbols for architecture x86_64: "gui::find()", referenced from: gui::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) in moc_gui.o ld: symbol(s) not found for architecture x86_64

from this message it looks that you have declared gui::find() slot or method in a header, but no where in your cpp that slot has any implementation! So all what you need is to add code for slot gui::find() in your cpp file.

When I add the following to your gui.cpp, the code compiles without issues:

void gui::find()
{
    // do some staff
}

Upvotes: 5

Related Questions