2014-10-17 26 views
1

我編寫一個程序時出現一些錯誤,出於某種原因它不會得到我包含的庫。編譯C++文件包括沒有被發現

我是否正確使用編譯器?即時列出我的目錄下面和編譯器的輸出。

感謝,

im including like this : #include "lib/RF24/RF24.h" 



[email protected] ~/sandbox $ ls 
examples lib Makefile readme.md test.cpp 

[email protected] ~/sandbox/lib $ ls 
RF24 

[email protected] ~/sandbox/lib/RF24 $ ls 
bcm2835.c bcm2835.o   nRF24L01.h  RF24.cpp RF24.o 
bcm2835.h librf24-bcm.so.1.0 RF24_config.h RF24.h 


[email protected] ~/sandbox $ g++ -Wall test.cpp -o test 
/tmp/ccXhlYKu.o: In function `setup()': 
test.cpp:(.text+0x14): undefined reference to `RF24::begin()' 
test.cpp:(.text+0x24): undefined reference to `RF24::setRetries(unsigned char, unsigned char)' 
test.cpp:(.text+0x3c): undefined reference to `RF24::setChannel(unsigned char)' 
test.cpp:(.text+0x48): undefined reference to `RF24::setPALevel(unsigned char)' 
test.cpp:(.text+0x54): undefined reference to `RF24::setPALevel(unsigned char)' 
test.cpp:(.text+0x60): undefined reference to `RF24::setDataRate(rf24_datarate_e)' 
test.cpp:(.text+0x70): undefined reference to `RF24::openWritingPipe(unsigned long long)' 
test.cpp:(.text+0x84): undefined reference to `RF24::openReadingPipe(unsigned char, unsigned long  long)' 
test.cpp:(.text+0x8c): undefined reference to `RF24::startListening()' 
test.cpp:(.text+0x94): undefined reference to `RF24::printDetails()' 
/tmp/ccXhlYKu.o: In function `main': 
test.cpp:(.text+0x138): undefined reference to `RF24::stopListening()' 
test.cpp:(.text+0x154): undefined reference to `RF24::write(void const*, unsigned char)' 
test.cpp:(.text+0x15c): undefined reference to `RF24::startListening()' 
test.cpp:(.text+0x164): undefined reference to `RF24::available()' 
test.cpp:(.text+0x180): undefined reference to `RF24::read(void*, unsigned char)' 
/tmp/ccXhlYKu.o: In function `__static_initialization_and_destruction_0(int, int)': 
test.cpp:(.text+0x22c): undefined reference to `RF24::RF24(unsigned char, unsigned char, unsigned int)' 
collect2: ld returned 1 exit status 

回答

0
g++ -Wall test.cpp -o test 

你不鏈接庫中。

+1

我曾嘗試過,但我確實得到了同樣的錯誤,我已閱讀其他帖子,但我不明白。 – 2014-10-18 20:40:13

+0

pi @ raspberrypigym〜/ sandbox $ g ++ -Wall -Llib/RF24 -llib/RF24/RF24.h test.cpp -o test /usr/bin/ld:找不到-llib/RF24/RF24.h collect2: ld返回1退出狀態 – 2014-10-18 21:03:27

+0

@Pato你沒有正確使用'-L'和'-l','.h'是一個頭文件而不是庫! – 2014-10-18 22:42:05