gpt4 book ai didi

c++ - Qt错误: symbol(s) not found for architecture x86_64 on Mac OS X Yosemite

转载 作者:行者123 更新时间:2023-11-28 06:24:16 24 4
gpt4 key购买 nike

在 mac OS X 10.10 和 Xcode 6.1.1 上使用 qt5.4 的程序在尝试编译时出现以下错误:

error: symbol(s) not found for architecture x86_64

编译器的输出是这样的:

Undefined symbols for architecture x86_64:
"data::SingleLineData", referenced from:
MainWindow::on_pushButton_clicked() in mainwindow.o
MainWindow::on_pushButton_2_clicked() in 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: *** [Integral.app/Contents/MacOS/Integral] Error 1
22:52:25: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project Integral (kit: Desktop Qt 5.4.0 clang 64bit)
When executing step "Make"

这是我的mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

namespace Ui {
class MainWindow;
}

class data{
public:
static QVector<double> SingleLineData;
};

class MainWindow : public QMainWindow
{
Q_OBJECT


public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();

private slots:
void on_pushButton_clicked();
void on_pushButton_2_clicked();

private:
Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H

还有我的mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFile>
#include <QTextStream>
#include <QtCore>
#include <QTextBrowser>
#include <QCheckBox>
#include <QDebug>
#include <QFileDialog>

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

}

MainWindow::~MainWindow()
{
delete ui;
}

void MainWindow::on_pushButton_clicked()
{


data::SingleLineData.resize(512);
QString test;
QString inputfile = QFileDialog::getOpenFileName(
this,
tr("Open File"),
"/Users",
"All files (*.*)"
);

if(inputfile != ""){
QFile file(inputfile);


if(!file.open(QFile::ReadOnly)){
}
QTextStream in(&file);


double buffer;

while(!file.atEnd()){
in.readLine();
for(int i=0; i<512; i++){
in >> buffer;
data::SingleLineData[i]+=buffer;
}
}

}
qDebug() << data::SingleLineData;
// ************* file output **************************************************

QString filename = "/Users/Mitch/Desktop/integral.txt";
QFile fileout(filename);
if (fileout.open(QFile::ReadWrite | QFile::Truncate)){
QTextStream out(&fileout);
for (QVector<double>::iterator iter = data::SingleLineData.begin(); iter != data::SingleLineData.end(); iter++){
out << *iter <<", ";
}
fileout.close();
}
}


void MainWindow::on_pushButton_2_clicked()
{
QString inputfile = QFileDialog::getOpenFileName(
this,
tr("Open File"),
"/Users",
"All files (*.*)"
);
QVector<double> SingleChannel;
if (inputfile != ""){
QFile file(inputfile);

if (!file.open(QIODevice::ReadOnly)){
}
QTextStream in(&file);
SingleChannel.resize(1);
double buffer;
int channelnumber = ui->spinBox->value();
while(!file.atEnd()){
in.readLine();
for (int i = 0; i < 512; i++){
in >> buffer;
if (i == channelnumber){
SingleChannel.push_back(buffer);
}
data::SingleLineData[i]+=buffer;
}
}
}
qDebug() << SingleChannel;
}

我认为当头文件中声明了一个函数但未在 .cpp 文件中实现时会发生错误。据我所知,这两个按钮都是在 .cpp 文件中实现的,这就是编译器所提示的。

有什么想法吗?谢谢米奇

最佳答案

编译器提示找不到其中 data::SingleLineData被定义为。它知道它已被声明,但由于它是一个静态成员,它必须在文件范围内定义,以便它的内存存在于某处并可以链接到。 see here .

添加QVector<double> data::SingleLineData;到您的 .cpp 文件以定义静态成员。

关于c++ - Qt错误: symbol(s) not found for architecture x86_64 on Mac OS X Yosemite,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28799074/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com