【发布时间】:2014-08-30 16:12:34
【问题描述】:
我正在使用 Eclipse 开普勒进行 AVR 开发。 我拥有的代码是 C(开源),我已经对其进行了调整,因此它可以完美运行。我的目标是 arduino mega2560 形式的 ATmega2560。 使用arduino板严格是为了硬件方便;我们正在将硬件开发为具有大多数核心 arduino mega2560 组件的定制板。
我需要在这个项目中使用几个库,这些库只能作为 arduino 库使用,即用于电子纸屏幕的库(来自 seeedstudio)和 Nordic 的 BLE nRF8001。
如果我在 eclipse 中使用插件创建一个新的 arduino 项目,我可以完美地为 arduino 库构建和运行测试。
当我尝试将 2 个代码库合并在一起时,我似乎无法调用添加的 arduino 库中的函数 - 如果我调用它们,编译器会引发链接错误。
Building target: Virgin2ManualArdInsert.elf
Invoking: AVR C Linker
avr-gcc -Wl,-Map,Virgin2ManualArdInsert.map -mmcu=atmega2560 -o "Virgin2ManualArdInsert.elf" ./avr/adc.o ./avr/eeprom.o ./avr/lcd_and_input.o ./avr/main.o ./avr/strings.o ./avr/unimplemented.o ./avr/usart.o ./aes.o ./baseconv.o ./bignum256.o ./ecdsa.o ./endian.o ./fft.o ./fix16.o ./hash.o ./hmac_sha512.o ./messages.pb.o ./p2sh_addr_gen.o ./pb_decode.o ./pb_encode.o ./pbkdf2.o ./prandom.o ./ripemd160.o ./sha256.o ./statistics.o ./stream_comm.o ./test_helpers.o ./transaction.o ./wallet.o ./xex.o
./avr/main.o: In function `main':
main.c:(.text.startup.main+0xc): undefined reference to `writeEink'
collect2: error: ld returned 1 exit status
makefile:53: recipe for target 'Virgin2ManualArdInsert.elf' failed
make: *** [Virgin2ManualArdInsert.elf] Error 1
作为测试,我只是想从 main.c 调用 eInk.cpp 中的基本“写入显示”调用:
extern "C"{
void writeEink()
{
EPAPER.begin(EPD_SIZE); // setup epaper, size
EPAPER.setDirection(DIRNORMAL); // set display direction
eSD.begin(EPD_SIZE);
GT20L16.begin();
// int timer1 = millis();
EPAPER.drawString("testing", 10, 10);
EPAPER.drawNumber(12345, 60, 40);
EPAPER.drawFloat(-1.25, 2, 80, 65);
EPAPER.display(); // use only once
}
从 arduino 内核构建的静态库是否可以实现?我已经尝试过了(尽管似乎大多数程序都已过时)并且库不想链接/被调用。
在我的 C 代码中包含 C++/Arduino 调用的正确程序是什么? 我试过使用 extern "C" {function()};在我的 .cpp 文件和 .h 文件中,但没有用。
感谢您提供任何帮助或指示我可以自己解决的问题。
【问题讨论】:
-
“编译器抛出链接错误” - 那会是什么错误?
-
您可以使用 gcc 选项 -Wl,--verbose 查看有关链接错误的详细信息
-
为清楚起见添加了代码 sn-ps。
-
您是否尝试过使用 C++ 编译器进行编译?它仍应编译您的代码,并且本机支持 C++。