【问题标题】:Undefined symbols for architecture x86_64 with Qt create使用 Qt 创建的架构 x86_64 的未定义符号
【发布时间】:2021-10-08 20:02:59
【问题描述】:

所以我试图将数据推送到游戏的数据库中,但我不断收到“架构 x86_64 的未定义符号”错误。我对 c++ 相当陌生(今天才学到所以我感谢任何帮助,无论是修复我的错误还是我应该知道的任何代码礼仪。 这是数据库处理程序 .cpp:

#include "databasehandler.h"
#include "global_objects.hpp"
#include <QNetworkRequest>
#include <QDebug>
#include <QJsonDocument>
#include <QVariantMap>
#include <iostream>

DatabaseHandler::DatabaseHandler(QObject *parent) : QObject(parent)
{
    m_networkManager = new QNetworkAccessManager ( this );
    QVariantMap newUser;
    newUser[ "Stress" ] = QString::number(stressed);
    newUser[ "Sleep" ] = QString::number(tired);
    newUser[ "Hungry" ] = QString::number(hungry);
    newUser[ "Happy" ] = QString::number(happy);
    newUser[ "Grade" ] = QString::number(grade);
    newUser[ "Date" ] = "1/10/21";
    newUser[ "Gender" ] = QString::number(gender);
    newUser[ "Aid" ] = QString::number(help);
    QJsonDocument jsonDoc = QJsonDocument::fromVariant( newUser );

    QNetworkRequest newUserRequest( QUrl( "url.json"));
    newUserRequest.setHeader( QNetworkRequest::ContentTypeHeader, QString( "application/json" ));
    m_networkManager->post( newUserRequest, jsonDoc.toJson() );

}

DatabaseHandler::~DatabaseHandler()
{
    m_networkManager->deleteLater();
}

void DatabaseHandler::networkReplyReadyRead()
{
    qDebug() << m_networkReply->readAll();
}

全局对象.hpp:

#define GLOBAL_OBJECTS_HPP

extern int happy;
extern int happy;
extern int hungry;
extern int tired;
extern int stressed;
extern int gender;
extern bool help;
extern int grade;


#endif // GLOBAL_OBJECTS_HPP

全局对象 .cpp:


namespace
{
    int happy;
    int hungry;
    int tired;
    int stressed;
    int gender;
    bool help;
    int grade;
}

和 checkinapp.cpp:

#include "checkinapp.h"
#include "ui_checkinapp.h"
#include "databasehandler.h"
#include "global_objects.hpp"
#include <QNetworkRequest>
#include <QDebug>
#include <QJsonDocument>
#include <QVariantMap>
#include <iostream>

using namespace std;

checkinapp::checkinapp(QWidget *parent)
    : QMainWindow(parent),
    ui(new Ui::checkinapp)
{
    ui->setupUi(this);
}

checkinapp::~checkinapp()
{
    if(help == 0)
    {
        delete ui;
    }
    if(help == 1)
    {
        cout << "help";
    }
}

void checkinapp::on_happy_valueChanged(int value)
{
    happy = value;
}

void checkinapp::on_hungry_valueChanged(int value)
{
    hungry = value;
}


void checkinapp::on_sleep_valueChanged(int value)
{
    tired = value;
}


void checkinapp::on_stress_valueChanged(int value)
{
    stressed = value;
}


void checkinapp::on_male_toggled(bool checked)
{
    if(checked == true)
    {
        gender = 0;
    }
}

void checkinapp::on_female_toggled(bool checked)
{
    if(checked == true)
    {
        gender = 1;
    }
}

void checkinapp::on_other_toggled(bool checked)
{
    if(checked == true)
    {
        gender = 2;
    }
}

void checkinapp::on_help_toggled(bool checked)
{
    if(checked == true)
    {
        help = 1;
    }
}

错误说明如下:

error photo

.pro 文件:

QT += network

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11 console

# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    databasehandler.cpp \
    global_objects.cpp \
    main.cpp \
    checkinapp.cpp

HEADERS += \
    checkinapp.h \
    databasehandler.h \
    global_objects.hpp

FORMS += \
    checkinapp.ui

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

【问题讨论】:

  • 看起来您没有将编译后的 checkinapp.cpp (checkinapp.o) 带入最终链接阶段。向我们展示您的构建系统。
  • 对不起@Botje 我在哪里可以找到我的构建系统
  • 它要么在一个名为 CMakeLists.txt 的文件中,要么在一个名为 qmake.pro 的文件中
  • 我在项目文件夹中没有 qmake.pro,它是否存储在其他地方,如果是,我如何访问它。我唯一的 .pro 文件是 AppCheckIn.pro
  • 在你的全局变量周围去掉namespace{}

标签: c++ qt


【解决方案1】:

正如 Botje 在 cmets 中所说,从 globalvarible.cpp 中删除 namespace{} 已修复它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-07
    • 2012-07-20
    • 2015-03-09
    相关资源
    最近更新 更多