【问题标题】:compile c++ file includes are not being found [duplicate]找不到编译c ++文件包含[重复]
【发布时间】:2014-10-17 18:01:04
【问题描述】:

我在编译程序时遇到了一些错误,由于某种原因它无法获取我包含的库。

我是否正确使用了编译器?我在下面列出了我的目录和编译器的输出。

谢谢,

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



pi@raspberrypigym ~/sandbox $ ls
examples  lib  Makefile  readme.md  test.cpp

pi@raspberrypigym ~/sandbox/lib $ ls
RF24

pi@raspberrypigym ~/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


pi@raspberrypigym ~/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 

【问题讨论】:

    标签: c++ compilation include


    【解决方案1】:
    g++ -Wall test.cpp -o test
    

    你没有链接你的图书馆。

    【讨论】:

    • 我试过了,但我确实遇到了同样的错误,我读过另一篇文章但我不明白。
    • 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 个退出状态
    • @Pato 您没有正确使用-L-l.h 是标头而不是库!
    • 正确的用法是什么?我的问题中有我的目录列表,请帮忙?
    猜你喜欢
    • 1970-01-01
    • 2022-01-16
    • 2022-12-01
    • 1970-01-01
    • 2016-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-17
    相关资源
    最近更新 更多