简体   繁体   中英

Qt error: symbol(s) not found for architecture x86_64 on Mac OS X Yosemite

Working on a program with qt5.4 on mac OS X 10.10 and Xcode 6.1.1 that gets the following error when trying to compile:

error: symbol(s) not found for architecture x86_64

And the compiler output says:

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"

Here is my 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

And my 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;
}

I believe the error occurs when there is a function declared in the header file but then not implemented in the .cpp file. As far as I can see both of the pushbuttons are implemented in the .cpp file, and this is what the compiler is complaining about.

Any ideas? Thanks Mitch

The compiler is complaining that it can't find where data::SingleLineData is defined. It knows it has been declared but since it is a static member it must be defined in file scope so that the memory for it exists somewhere and can be linked to. see here .

Add QVector<double> data::SingleLineData; to your .cpp file to define the static member.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM