2017-10-22 9 views
1

Segmentationというヘッダファイルがsegmentation.hと表示されています。ヘッダーで宣言された関数は、実装ファイルsegmentation.cppに定義されています。名前空間はmainwindow.cppで使用されているため、このファイルには名前空間が含まれています。私はプロジェクトをコンパイルしようとしているときしかし、私はあなたがリンク時にモジュールを複数回含めるしようとすると、私はduplicate symbols found for architecture x86_64エラーが発生理解してQtアーキテクチャx86_64で重複したシンボルが見つかりました

1 duplicate symbols found for architecture x86_64

を取得します。しかし、私はsegmentation.hを上記のファイルに1回だけ含めました。

segmentation.h

#ifndef SEGMENTATION_H 
#define SEGMENTATION_H 

#include <QObject> 
#include <opencv2/opencv.hpp> 
#include <QPixmap> 

namespace Segmentation 
{ 
    int k; 
    cv::Mat getSegments(cv::Mat inputImage); 
    cv::Mat sampleInput(cv::Mat &inputImage); 
} 

#endif // SEGMENTATION_H 

segmentation.cpp

#include "segmentation.h" 
#include <opencv2/opencv.hpp> 
#include <iostream> 

cv::Mat Segmentation::getSegments(cv::Mat inputImage) 
{ 

    Segmentation::sampleInput(inputImage); 

    //Incomplete code 

    return inputImage; 
} 

cv::Mat Segmentation::sampleInput(cv::Mat &inputImage) 
{ 
    std::cout << "Size: " << inputImage.size << std::endl; 
    std::cout << "Rows: " << inputImage.rows << std::endl; 
    std::cout << "Cols: " << inputImage.cols << std::endl; 
    std::cout << "Size rows x cols: " << inputImage.rows * inputImage.cols << std::endl; 

    //Incomplete code 

    return inputImage; 
} 

mainwindow.h

#ifndef MAINWINDOW_H 
#define MAINWINDOW_H 

#include <QMainWindow> 
#include <QPixmap> 
#include <QGraphicsView> 
#include <QLabel> 
#include <QGraphicsScene> 
#include <QGraphicsPixmapItem> 
#include <opencv2/opencv.hpp> 

namespace Ui { 
class MainWindow; 
} 

class MainWindow : public QMainWindow 
{ 
    Q_OBJECT 

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

private slots: 
    void on_loadImageButton_clicked(); 
    void on_clearScreenButton_clicked(); 
    void on_segmentButton_clicked(); 

private: 
    Ui::MainWindow *ui; 
    cv::Mat _rawInputImage; 
    QPixmap _inputImage; 
    QPixmap _outputImage; 
    QGraphicsScene _scene; 
    QGraphicsPixmapItem _inputImagePixmapItem; 

}; 

#endif // MAINWINDOW_H 

mainwindow.cpp

#include "mainwindow.h" 
#include "ui_mainwindow.h" 
#include <QFileDialog> 
#include <QString> 
#include <QDebug> 
#include <QRectF> 
#include <segmentation.h> 

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

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

void MainWindow::on_loadImageButton_clicked() 
{ 
    QFileDialog fileDialog(this, Qt::Dialog); 
    fileDialog.setFileMode(QFileDialog::ExistingFile); 
    fileDialog.setNameFilter("*.jpg *.png *.jpeg"); 
    fileDialog.setViewMode(QFileDialog::Detail); 
    fileDialog.exec(); 

    QStringList selectedFileName = fileDialog.selectedFiles(); 
    QString selectedFile = selectedFileName.at(0); 
    _inputImage.load(selectedFile); 
    _rawInputImage = cv::imread(selectedFile.toStdString()); 

    _inputImagePixmapItem.setPixmap((_inputImage)); 
    _scene.addItem(&_inputImagePixmapItem); 
    this->ui->inputImageViewWidget->setScene(&_scene); 
    this->ui->inputImageViewWidget->fitInView(&_inputImagePixmapItem, Qt::KeepAspectRatio); 

    fileDialog.saveState(); 
    return; 
} 

void MainWindow::on_clearScreenButton_clicked() 
{ 
    _scene.removeItem(&_inputImagePixmapItem); 
    return; 
} 

void MainWindow::on_segmentButton_clicked() 
{ 
    cv::Mat segmentedOutputImage = Segmentation::getSegments(_rawInputImage); 
} 

コンパイル出力

14:15:59: Running steps for project LaundroBotQt... 
14:15:59: Configuration unchanged, skipping qmake step. 
14:15:59: Starting: "/usr/bin/make" 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -headerpad_max_install_names -stdlib=libc++ -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -mmacosx-version-min=10.9 -Wl,-rpath,/Users/Vino/Documents/Qt/5.8/clang_64/lib -o LaundroBotQt.app/Contents/MacOS/LaundroBotQt main.o mainwindow.o segmentation.o moc_mainwindow.o -F/Users/Vino/Documents/Qt/5.8/clang_64/lib -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -lopencv_highgui -lopencv_features2d -lopencv_ml -lopencv_flann -lopencv_imgproc -lopencv_photo -framework QtWidgets -framework QtGui -framework QtCore -framework DiskArbitration -framework IOKit -framework OpenGL -framework AGL 
duplicate symbol __ZN12Segmentation1kE in: 
    mainwindow.o 
    segmentation.o 
ld: 1 duplicate symbol for architecture x86_64 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 
make: *** [LaundroBotQt.app/Contents/MacOS/LaundroBotQt] Error 1 
14:15:59: The process "/usr/bin/make" exited with code 2. 
Error while building/deploying project LaundroBotQt (kit: Desktop Qt 5.8.0 clang 64bit) 
When executing step "Make" 
14:15:59: Elapsed time: 00:01. 

GitHub repo link

私はこの問題を解決するかどうかはかなりわかりません。私はStackOverflowを読んだが、私の問題は奇妙に思える。どんな助けもありがとうございます。

+0

githubまたはgist経由でプロジェクトを共有して、すぐにテストすることができます。 – eyllanesc

+0

GitHubリポジトリリンクが追加されました。チェックしてください。ありがとう。 int型のk – Vino

+0

変更 ';' 'にextern int型kまで;' – eyllanesc

答えて

1

問題がsegmentation.hで、ここにある:ここで

namespace Segmentation 
{ 
    int k; 
    [...] 

あなたは両方の宣言とセグメンテーションの名前空間にkという名前の変数のための記憶領域を定義しています。それに伴う問題は、複数の.cppファイル#が(ほぼ確実に起こるであろう)のsegmentation.hが含まれている場合、その変数セグメンテーション:: kがにつながる、複数の.cppファイルでそれを宣言したストレージを持っているということです重複シンボルエラーが表示されます。

は、その問題を回避するには、代わりにsegmentation.hでこれを行う:

namespace Segmentation 
{ 
    extern int k; 
    [...] 

が...そして、あなたの.cppファイルのいずれかで(おそらくsegmentation.cppが最も適切なものであろう)、このように、個別にストレージを追加します。

namespace Segmentation 
{ 
    int k; 
}; 

セグメンテーションのためにそのように収納スペース:: kは唯一の代わりに、それらの多くのその1つの.cppファイルに割り当てられます。

+0

重複:https://stackoverflow.com/questions/8971824/multiple-definition-of-namespace-variable-c-compilation – eyllanesc

+0

はどうもありがとうございました:)それをそれを固定した。なぜそれが下落したのかわからない:/ – Vino

関連する問題