未找到架构 x86_64 mac os 10.13.3 的符号

Vir*_*ual 1 c++ macos qt compiler-errors

我知道这个问题已经被问过一千次了,但我尝试了所有解决方案,但没有任何帮助。

我在 Qt 中编写了一个小程序,过了一会儿我收到了以下错误消息:

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

我重新执行了qmake命令和重建项目,但没有任何效果。我是 Qt 新手。我在 mac os 10.13.3 上使用 Qt 版本 5.10.0

这是我的文件:

图形用户界面

#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
Run Code Online (Sandbox Code Playgroud)

图形用户界面.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);
}
Run Code Online (Sandbox Code Playgroud)

主要.cpp:

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

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

    return a.exec();
}
Run Code Online (Sandbox Code Playgroud)

我希望你可以帮助我。我已经解决这个错误一个多星期了。如果您需要更多信息,请随时询问,我会将其发布。

Moh*_*nan 5

未找到架构 x86_64 的符号

在 MacOS 上通常不难诊断,并且通常它来自您在标头中定义的内容,但没有正确的实现!

要知道您收到此消息的确切原因,请单击Compiler OutputQt Creator,很可能您会看到错误make来自何处,在您的代码案例中,我看到以下错误:

体系结构 x86_64 的未定义符号:“gui::find()”,引用自: moc_gui.o 中的 gui::qt_static_metacall(QObject*, QMetaObject::Call, int, void**):未找到符号架构 x86_64

从这条消息看来,您已经gui::find()在标头中声明了插槽或方法,但cpp该插槽中没有任何位置有任何实现!gui::find()因此,您所需要做的就是在文件中添加插槽代码cpp

当我将以下内容添加到您的 gui.cpp 中时,代码编译时没有问题:

void gui::find()
{
    // do some staff
}
Run Code Online (Sandbox Code Playgroud)