3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

duplicate symbol for architecture i386 のありがちなミス

Last updated at Posted at 2016-03-28

記事にするようなことでもないですが

duplicate symbol for architecture i386 のありがちなミス

Addonを使っている場合に疑うべきミス

例えばこんなプロジェクト
スクリーンショット 2016-04-01 14.23.48.png

Addon内にexampleプロジェクトも追加されている場合は、このまま実行すると以下のようなエラーが出ることがあります。

duplicate symbol _main in:
    /Users/hirokinaganuma/Library/Developer/Xcode/DerivedData/GameOfLifeSample-bahthplrmhmmtrgrzcvxgfdgmjng/Build/Intermediates/GameOfLifeSample.build/Debug/GameOfLifeSample.build/Objects-normal/x86_64/main-82227D70F1DD098B.o
    -----省略-----
ld: 16 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

_main inが重複しまっくってるみたいです。

解決策

以下のようにaddons内のexampleをフォルダごとreferenceから削除します。

スクリーンショット 2016-04-01 14.25.20.png
スクリーンショット 2016-04-01 14.25.29.png

これにて解決です。

Addonとかにかかわらず最近よくみかけたいかのようなエラーについて

こんなかんじ

duplicate symbol _lineColor in:
    /Users/t80/Library/Developer/Xcode/DerivedData/BasicMath-grbicvozblpeqdcbpzfehtkvlyej/Build/Intermediates/BasicMath.build/Debug/BasicMath.build/Objects-normal/i386/main.o
    /Users/t80/Library/Developer/Xcode/DerivedData/BasicMath-grbicvozblpeqdcbpzfehtkvlyej/Build/Intermediates/BasicMath.build/Debug/BasicMath.build/Objects-normal/i386/ofApp.o
ld: 1 duplicate symbol for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

1 duplicate symbol for architecture i386
ってなんだ、となりますが、

上記のエラーメッセージをよく読むと、

main.o,ofApp.oの実行ファイルに同じsymbolがあって重複しています、ということが言われており、そのsymbolは_lineColor(大域変数をコンパイルした後の変数の名称かな)である、とも教えてくれています。

ofApp.hを見てみると、クラス外にint lineColor[100]と宣言されており

ofApp.h

# pragma once

# include "ofMain.h"

class ofApp : public ofBaseApp{

	public:
		void setup();
		void update();
		void draw();

		void keyPressed(int key);
		void keyReleased(int key);
		void mouseMoved(int x, int y );
		void mouseDragged(int x, int y, int button);
		void mousePressed(int x, int y, int button);
		void mouseReleased(int x, int y, int button);
		void windowResized(int w, int h);
		void dragEvent(ofDragInfo dragInfo);
		void gotMessage(ofMessage msg);
		
};

int lineColor[100];

main.cppでは

main.cpp
# include "ofMain.h"
# include "ofApp.h"

//========================================================================
int main( ){
	ofSetupOpenGL(1024,768,OF_WINDOW);			// <-------- setup the GL context

	// this kicks off the running of my app
	// can be OF_WINDOW or OF_FULLSCREEN
	// pass in width and height too:
	ofRunApp(new ofApp());

}

のように、ofApp.hをincludeしており、
そもそも#includeは指定されたファイルをその位置に単純に展開するだけの機能なので、どちらのファイルからも実行ファイルとして_lineColorというsymbolが作られています。

解決策

class内に変数を定義してあげるだけです。

ofApp.h

# pragma once

# include "ofMain.h"

class ofApp : public ofBaseApp{

	public:
		void setup();
		void update();
		void draw();

		void keyPressed(int key);
		void keyReleased(int key);
		void mouseMoved(int x, int y );
		void mouseDragged(int x, int y, int button);
		void mousePressed(int x, int y, int button);
		void mouseReleased(int x, int y, int button);
		void windowResized(int w, int h);
		void dragEvent(ofDragInfo dragInfo);
		void gotMessage(ofMessage msg);
		int lineColor[100];
};


これにて解決です!
間違ってるとこなどご指摘等ありましたら、コメントお願いいたします。

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?