在我的main.c
计划中,我包含了这个库:
#include "coap_api.h"
这也包括在内
Properties -> C/C++ Build -> Settings -> Cross ARM GNU Assembler -> Includes
和
Properties -> C/C++ Build -> Settings -> Cross ARM C Compiler -> Includes
构建项目我收到了这个错误:
./src/main.o: In function `main':
/Users/joanet/Development/Embedded/eclipseWS/EHAL-master/ARM/Nordic/nRF51/ipv6_coap_server/Release/../src/main.c:708: undefined reference to `coap_init'
我在另一篇文章中读到我必须链接库(http://whatwouldnickdo.com/wordpress/328/eclipse-cdt-and-linux-libraries/)
我尝试添加名为coap_api
的库,但我无效
lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld: cannot find -lcoap_api
在编译中包含了coap目录:
arm-none-eabi-gcc -mcpu=cortex-m0 -mthumb -Os -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -Wall -g -DBLE_STACK_SUPPORT_REQD -DNRF51 -D__CORTEX_M0 -DBOARD_PCA10028 -DSOFTDEVICE_PRESENT -DS110 -I/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/ipv6_coap_server/bsp -I/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/nrf51_sdk/components/iot/ipv6_stack/pbuffer -I"/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/nrf51_sdk/components/libraries/util/" -I"/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/nrf51_sdk/components/drivers_nrf/hal/" -I"/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/../../../ARM/CMSIS/CMSIS/Include/" -I"/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/../../../ARM/Nordic/nRF51/CMSIS/include/" -I"/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/nrf51_sdk/components/softdevice/s110/headers/" -I"/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/nrf51_sdk/components/ble/common/" -I"/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/nrf51_sdk/components/ble/ble_services/ble_bas/" -I"/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/nrf51_sdk/components/ble/ble_services/ble_dis/" -I"/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/nrf51_sdk/components/ble/device_manager/" -I"/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/nrf51_sdk/components/softdevice/common/softdevice_handler/" -I"/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/nrf51_sdk/components/libraries/scheduler/" -I"/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/nrf51_sdk/components/ble/ble_error_log/" -I"/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/nrf51_sdk/components/drivers_nrf/ble_flash/" -I"/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/nrf51_sdk/components/ble/ble_debug_assert_handler/" -I"/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/nrf51_sdk/components/libraries/timer/" -I"/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/nrf51_sdk/components/libraries/gpiote/" -I"/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/nrf51_sdk/components/drivers_nrf/pstorage/" -I"/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/nrf51_sdk/components/ble/ble_services/ble_dfu/" -I"/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/nrf51_sdk/components/libraries/bootloader_dfu/experimental/" -I"/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/nrf51_sdk/components/libraries/bootloader_dfu/" -I"/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/../../../include/" -I"/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/nrf51_sdk/components/ble/ble_services/ble_hids/" -I"/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/../../../ARM/CMSIS/CMSIS_RTX/INC/" -I"/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/nrf51_sdk/components/libraries/trace/" -I"/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/nrf51_sdk/components/device/" -I"/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/nrf51_sdk/components/ble/ble_services/ble_tps/" -I"/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/nrf51_sdk/components/libraries/button/" -I"/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/nrf51_sdk/components/ble/device_manager/config/" -I"/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/ipv6_coap_client/src" -I/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/nrf51_sdk/components/toolchain/gcc -I/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/nrf51_sdk/components/libraries/mem_manager -I/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/nrf51_sdk/components/ble/ble_services/ble_ipsp -I/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/nrf51_sdk/components/iot/include -I/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/nrf51_sdk/components/iot/ipv6_stack/include -I/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/nrf51_sdk/components/iot/coap -std=gnu99 -MMD -MP -MF"src/Vectors_nRF51.d" -MT"src/Vectors_nRF51.o" -c -o "src/Vectors_nRF51.o" "/Users/nullpointer/Development/Embedded/eclipseWS/EHAL-master-Hoan/ARM/Nordic/nRF51/src/Vectors_nRF51.c"
答案 0 :(得分:3)
该行:
#include "coap_api.h"
不包含库,它包含一个包含其他地方定义的声明的头文件。 do 必须链接包含这些定义的单独编译的目标代码。
如果是库文件,则需要以与包含路径类似的方式设置库路径。如果库的名称为GNU常规格式libXXX.a
,则它与交换机-lXXX
链接,否则您必须指定完整的文件名。
但是,如果coap_api.h中的声明引用了源代码形式的定义,那么必须将源添加到项目中以进行单独的编译和链接。
答案 1 :(得分:1)
您需要链接来自coap.c的生成对象文件,然后从此.o创建一个库,或者直接使用此先生成的coap.o文件编译您的项目。
您应该阅读一些有关编译和链接的文档。在这里,您的编译器会告诉您它具有对coap_init
的未定义引用,该引用实际上由您的程序调用并由coap_api.h
文件引用。问题是它无法找到相关的机器代码。你可能已经包含了coap.c目录,它只不过是一个文本文件。
您首先需要编译它,然后创建一个链接到项目的库,或者复制导入项目中的coap.c,以便在其余的工作中编译它。