2016-08-03 15 views
0

私のプログラムをlinuxでコンパイルしようとしています。 Windows上でうまく動作します(Visual Studio 2015でコンパイルされます)。私はLinux上で同じことをしようとする。しかし、私はこのエラーを取得する:g ++コンパイル時に定義されていない参照エラー

g++ -std=c++0x -std=c++0x Prueba1.cpp -o Prueba1 
/tmp/cc9HTgYi.o: In function `Escuchador::onFrame(Leap::Controller const&)': 
Prueba1.cpp:(.text+0x51): undefined reference to `Leap::Controller::frame(int) const' 
Prueba1.cpp:(.text+0x6c): undefined reference to `Leap::Frame::fingers() const' 
Prueba1.cpp:(.text+0x7d): undefined reference to `Leap::FingerList::count() const' 
Prueba1.cpp:(.text+0x97): undefined reference to `Leap::Frame::hands() const' 
Prueba1.cpp:(.text+0xa8): undefined reference to `Leap::HandList::count() const' 
Prueba1.cpp:(.text+0xbc): undefined reference to `Leap::Frame::timestamp() const' 
Prueba1.cpp:(.text+0xce): undefined reference to `Leap::Frame::id() const' 
Prueba1.cpp:(.text+0x1ac): undefined reference to `Leap::Frame::hands() const' 
Prueba1.cpp:(.text+0x1c7): undefined reference to `Leap::HandList::begin() const' 
Prueba1.cpp:(.text+0x203): undefined reference to `Leap::Hand::isLeft() const' 
Prueba1.cpp:(.text+0x245): undefined reference to `Leap::Hand::id() const' 
Prueba1.cpp:(.text+0x2fc): undefined reference to `Leap::Hand::palmNormal() const' 
Prueba1.cpp:(.text+0x317): undefined reference to `Leap::Hand::direction() const' 
Prueba1.cpp:(.text+0x332): undefined reference to `Leap::Hand::fingers() const' 
Prueba1.cpp:(.text+0x34d): undefined reference to `Leap::FingerList::begin() const' 
Prueba1.cpp:(.text+0x37e): undefined reference to `Leap::Pointable::id() const' 
Prueba1.cpp:(.text+0x38e): undefined reference to `Leap::Finger::type() const' 
Prueba1.cpp:(.text+0x47b): undefined reference to `Leap::Finger::bone(Leap::Bone::Type) const' 
Prueba1.cpp:(.text+0x510): undefined reference to `Leap::Frame::hands() const' 
Prueba1.cpp:(.text+0x533): undefined reference to `Leap::HandList::operator[](int) const' 
Prueba1.cpp:(.text+0x54e): undefined reference to `Leap::Hand::fingers() const' 
Prueba1.cpp:(.text+0x582): undefined reference to `Leap::FingerList::begin() const' 
Prueba1.cpp:(.text+0x595): undefined reference to `Leap::Bone::Bone()' 
Prueba1.cpp:(.text+0x5ea): undefined reference to `Leap::Finger::bone(Leap::Bone::Type) const' 
Prueba1.cpp:(.text+0x63e): undefined reference to `Leap::Finger::type() const' 
Prueba1.cpp:(.text+0x67f): undefined reference to `Leap::operator<<(std::ostream&, Leap::Bone const&)' 
Prueba1.cpp:(.text+0x6ee): undefined reference to `Leap::FingerList::end() const' 
Prueba1.cpp:(.text+0x726): undefined reference to `Leap::Hand::fingers() const' 
Prueba1.cpp:(.text+0x74d): undefined reference to `Leap::FingerList::begin() const' 
Prueba1.cpp:(.text+0x768): undefined reference to `Leap::FingerList::end() const' 
Prueba1.cpp:(.text+0x7ab): undefined reference to `Leap::Finger::bone(Leap::Bone::Type) const' 
Prueba1.cpp:(.text+0x7ce): undefined reference to `Leap::Finger::bone(Leap::Bone::Type) const' 
Prueba1.cpp:(.text+0x7f1): undefined reference to `Leap::Finger::bone(Leap::Bone::Type) const' 
Prueba1.cpp:(.text+0x814): undefined reference to `Leap::Finger::bone(Leap::Bone::Type) const' 
Prueba1.cpp:(.text+0x825): undefined reference to `Leap::Finger::type() const' 
Prueba1.cpp:(.text+0x848): undefined reference to `Leap::Bone::direction() const' 
Prueba1.cpp:(.text+0x863): undefined reference to `Leap::Bone::direction() const' 
Prueba1.cpp:(.text+0x89e): undefined reference to `Leap::Bone::direction() const' 
Prueba1.cpp:(.text+0x8b9): undefined reference to `Leap::Bone::direction() const' 
Prueba1.cpp:(.text+0x8f4): undefined reference to `Leap::Bone::direction() const' 
/tmp/cc9HTgYi.o:Prueba1.cpp:(.text+0x90c): more undefined references to `Leap::Bone::direction() const' follow 
/tmp/cc9HTgYi.o: In function `Escuchador::onFrame(Leap::Controller const&)': 
Prueba1.cpp:(.text+0xa15): undefined reference to `Leap::Finger::type() const' 
Prueba1.cpp:(.text+0xa37): undefined reference to `Leap::Bone::direction() const' 
Prueba1.cpp:(.text+0xa4f): undefined reference to `Leap::Bone::direction() const' 
Prueba1.cpp:(.text+0xa87): undefined reference to `Leap::Bone::direction() const' 
Prueba1.cpp:(.text+0xa9f): undefined reference to `Leap::Bone::direction() const' 
Prueba1.cpp:(.text+0xad7): undefined reference to `Leap::Bone::direction() const' 
/tmp/cc9HTgYi.o:Prueba1.cpp:(.text+0xaef): more undefined references to `Leap::Bone::direction() const' follow 
/tmp/cc9HTgYi.o: In function `Escuchador::onFrame(Leap::Controller const&)': 
Prueba1.cpp:(.text+0xbf8): undefined reference to `Leap::Finger::type() const' 
Prueba1.cpp:(.text+0xc1b): undefined reference to `Leap::Bone::direction() const' 
Prueba1.cpp:(.text+0xc33): undefined reference to `Leap::Bone::direction() const' 
Prueba1.cpp:(.text+0xc6b): undefined reference to `Leap::Bone::direction() const' 
Prueba1.cpp:(.text+0xc83): undefined reference to `Leap::Bone::direction() const' 
Prueba1.cpp:(.text+0xcbb): undefined reference to `Leap::Bone::direction() const' 
/tmp/cc9HTgYi.o:Prueba1.cpp:(.text+0xcd3): more undefined references to `Leap::Bone::direction() const' follow 
/tmp/cc9HTgYi.o: In function `Escuchador::onFrame(Leap::Controller const&)': 
Prueba1.cpp:(.text+0xeb4): undefined reference to `Leap::FingerList::end() const' 
Prueba1.cpp:(.text+0xf27): undefined reference to `Leap::HandList::end() const' 
/tmp/cc9HTgYi.o: In function `main': 
Prueba1.cpp:(.text+0x11a3): undefined reference to `Leap::Controller::Controller()' 
Prueba1.cpp:(.text+0x11b7): undefined reference to `Leap::Controller::addListener(Leap::Listener&)' 
Prueba1.cpp:(.text+0x11fb): undefined reference to `Leap::Controller::removeListener(Leap::Listener&)' 
Prueba1.cpp:(.text+0x120c): undefined reference to `Leap::Controller::~Controller()' 
Prueba1.cpp:(.text+0x122a): undefined reference to `Leap::Controller::~Controller()' 
/tmp/cc9HTgYi.o: In function `Leap::Pointable::~Pointable()': 
Prueba1.cpp:(.text._ZN4Leap9PointableD2Ev[_ZN4Leap9PointableD5Ev]+0x16): undefined reference to `Leap::Interface::~Interface()' 
/tmp/cc9HTgYi.o: In function `Leap::Bone::operator=(Leap::Bone&&)': 
Prueba1.cpp:(.text._ZN4Leap4BoneaSEOS0_[_ZN4Leap4BoneaSEOS0_]+0x14): undefined reference to `Leap::Interface::operator=(Leap::Interface const&)' 
/tmp/cc9HTgYi.o: In function `Leap::ConstListIterator<Leap::HandList, Leap::Hand>::operator*() const': 
Prueba1.cpp:(.text._ZNK4Leap17ConstListIteratorINS_8HandListENS_4HandEEdeEv[_ZNK4Leap17ConstListIteratorINS_8HandListENS_4HandEEdeEv]+0x20): undefined reference to `Leap::HandList::operator[](int) const' 
/tmp/cc9HTgYi.o: In function `Leap::ConstListIterator<Leap::FingerList, Leap::Finger>::operator*() const': 
Prueba1.cpp:(.text._ZNK4Leap17ConstListIteratorINS_10FingerListENS_6FingerEEdeEv[_ZNK4Leap17ConstListIteratorINS_10FingerListENS_6FingerEEdeEv]+0x20): undefined reference to `Leap::FingerList::operator[](int) const' 
/tmp/cc9HTgYi.o: In function `Leap::Frame::~Frame()': 
Prueba1.cpp:(.text._ZN4Leap5FrameD2Ev[_ZN4Leap5FrameD5Ev]+0x16): undefined reference to `Leap::Interface::~Interface()' 
/tmp/cc9HTgYi.o: In function `Leap::HandList::~HandList()': 
Prueba1.cpp:(.text._ZN4Leap8HandListD2Ev[_ZN4Leap8HandListD5Ev]+0x16): undefined reference to `Leap::Interface::~Interface()' 
/tmp/cc9HTgYi.o: In function `Leap::FingerList::~FingerList()': 
Prueba1.cpp:(.text._ZN4Leap10FingerListD2Ev[_ZN4Leap10FingerListD5Ev]+0x16): undefined reference to `Leap::Interface::~Interface()' 
/tmp/cc9HTgYi.o: In function `Leap::Hand::~Hand()': 
Prueba1.cpp:(.text._ZN4Leap4HandD2Ev[_ZN4Leap4HandD5Ev]+0x16): undefined reference to `Leap::Interface::~Interface()' 
/tmp/cc9HTgYi.o: In function `Leap::Bone::~Bone()': 
Prueba1.cpp:(.text._ZN4Leap4BoneD2Ev[_ZN4Leap4BoneD5Ev]+0x16): undefined reference to `Leap::Interface::~Interface()' 
/tmp/cc9HTgYi.o:(.rodata._ZTIN4Leap5FrameE[_ZTIN4Leap5FrameE]+0x8): undefined reference to `typeinfo for Leap::Interface' 
/tmp/cc9HTgYi.o:(.rodata._ZTIN4Leap8HandListE[_ZTIN4Leap8HandListE]+0x8): undefined reference to `typeinfo for Leap::Interface' 
/tmp/cc9HTgYi.o:(.rodata._ZTIN4Leap10FingerListE[_ZTIN4Leap10FingerListE]+0x8): undefined reference to `typeinfo for Leap::Interface' 
/tmp/cc9HTgYi.o:(.rodata._ZTIN4Leap4HandE[_ZTIN4Leap4HandE]+0x8): undefined reference to `typeinfo for Leap::Interface' 
/tmp/cc9HTgYi.o:(.rodata._ZTIN4Leap4BoneE[_ZTIN4Leap4BoneE]+0x8): undefined reference to `typeinfo for Leap::Interface' 
/tmp/cc9HTgYi.o:(.rodata._ZTIN4Leap9PointableE[_ZTIN4Leap9PointableE]+0x8): more undefined references to `typeinfo for Leap::Interface' follow 
collect2: error: ld returned 1 exit status 
make: *** [Prueba1] Error 1 

私の#includeは、次のとおりです。

#include <iostream> 
#include <cstring> 
#include "Leap.h" 

だから、問題はLeap.hヘッダであるようです。 SDKには、私がコンパイルして実行できるSample.cppがあります。私は同じメイクファイルと同じファイルシステムを使用しています。 Sample.cppと同じ#includeを使用しているので、.cppファイルをSample.cppと同じフォルダに移動してコンパイルしようとすると、エラーが発生します。私はそれを解決する方法、任意のアイデアを知りませんか?ここにメークファイルがあります:

OS := $(shell uname) 
ARCH := $(shell uname -m) 
CXXFLAGS := -std=c++0x -std=c++0x 

ifeq ($(OS), Linux) 
    ifeq ($(ARCH), x86_64) 
LEAP_LIBRARY := ../lib/x64/libLeap.so -Wl,-rpath,../lib/x64 
    else 
LEAP_LIBRARY := ../lib/x86/libLeap.so -Wl,-rpath,../lib/x86 
    endif 
else 
    # OS X 
LEAP_LIBRARY := ../lib/libLeap.dylib 
endif 

Sample: Sample.cpp 
$(CXX) -Wall -g -I../include Sample.cpp -o Sample $(LEAP_LIBRARY) 

ifeq ($(OS), Darwin) 
install_name_tool -change @loader_path/libLeap.dylib ../lib/libLeap.dylib Sample 
endif 

clean: 
rm -rf Sample Sample.dSYM 

CXXFLAGSを追加してC + 98コンパイラエラーを解決しました。私はこの方法でもSample.cppをコンパイルすることができますが、私がファイルで同じことをしようとすると、エラーが発生します。助けてくれてありがとう!

+1

私はmakeがOSを正しく認識していないと感じました。試してみてください:UNAME_S:= $(shell uname -s) ifeq($(UNAME_S)、Linux) ---ここには--- endif ....もっと見る:http://stackoverflow.com/質問/ 714100/os検出メイクファイル – fritzone

+1

@fritzone OPはメイクファイルをまったく使用していないようです。 –

+3

コンパイル行にlibLeap.soがありません。これは、あなたがmakefileを使用していないか、あなたのプログラムのためにそれを更新することなくそれを使用していることを意味します。書かれているように、これはSampleという名前のプログラムでのみ動作します。プログラム名で動作するようにメークファイルを変更するか(高度なミッション)、プログラム名で動作し、LDLIBSのような標準マクロを使用するように改善する必要があります。 –

答えて

1

So it seems the problem is with the Leap.h header.

いいえ、ヘッダーに問題はありません。これらの関数の定義を提供するライブラリにリンクしていないだけです。それはlibleap.soにリンクし、

をあなたが同じことを実行する必要があります:メイクファイルは、サンプル・プログラムを構築する方法で

見て、あなたがにしている場合

g++ -std=c++0x -std=c++0x Prueba1.cpp -o Prueba1 ../lib/x64/libleap.so -Wl,-rpath,../lib/x64 

は(のx86とx64のを交換する32ビットシステム)。

1

最初に、必要な読書:What is an undefined reference/unresolved external symbol error and how do I fix it?少なくとも外部のライブラリコンポーネントに関する回答を読んでから、この質問に戻ってください。


この場合、外部ライブラリを指定せずにリンクコマンドを実行しています。どうして?なぜパッケージに付属のサンプルをコンパイルできますか?

makefileを見てください。 (コロンの後)からそれを構築するために何を、(コロンの前の最初の行)を構築するためにどのような、およびどのへ:それはこのルールmake 3つのことを伝え

Sample: Sample.cpp 
    $(CXX) -Wall -g -I../include Sample.cpp -o Sample $(LEAP_LIBRARY) 

を語りますビルドしてください(2行目)。あなたは

make Sample 

make次のようなコマンドを実行するときに何をすべきかかなり良いアイデアを持っています。

は今、あなたは

make Prueba1 

物事は少し異なっていると言う場合。メイクファイルにはPrueba1という特別なルールはありませんので、makeは、(巨大な)組込みルールを取り出し、Prueba1をビルドするルールを探します。確かにこのような組み込みルールがありますが、libLeap.soについてはわかりません。このため、ビルドログには表示されません。

Prueba1: Prueba1.cpp 
    $(CXX) -Wall -g -I../include Prueba1.cpp -o Prueba1 $(LEAP_LIBRARY) 

を、私はあなたがPrueba99に得るとき、それはやや古い成長すると推測するベンチャーたい:

もちろん、あなたのメイクファイルに次のようなものを追加することができます。私たちはもっとうまくできますか?

はい、可能ですが、まず別の質問に回答しましょう。あなたのコンパイルコマンドは、どのようにして-std=c++0xについて知っていますか?

これは、ビルトインマクロCXXFLAGSにこのフラグを追加し、ビルトインルールでこのマクロを使用したためです。ところで、-std=c++0xを2回指定する必要はありません。

コンパイラフラグと同様にライブラリを扱う方法はありますか?絶対に!マクロはLDLIBSLDFLAGSの2種類あります。あなたがそれらをこのように定義した場合:(代わりに)

LDLIBS := ../lib/x64/libLeap.so 
LDFLAGS := -Wl,-rpath,../lib/x64 

かを

LDLIBS := -lLeap 
LDFLAGS := -L ../lib/x64 -Wl,-rpath,../lib/x64 

あなたのメイクファイルは、(それは、単一のC++ソースファイルとして書かれている場合)libLeapに対する任意のC++プログラムを構築することができるはずです。

-I../includeCPPFLAGSに追加することをお勧めします。これは、サンプルルールで使用されるためです。あなたの編集はそれなしではうまくいくようですが、あなたの編集が失敗する可能性があります。作業ディレクトリを変更してください。

関連する問題