使用Makefile编译Contiki程序时遇tsch_set_coordinator未定义引用错误
Contiki TSCH编译错误:undefined reference to
tsch_set_coordinator 最近我在基于Contiki的TSCH MAC写一个自定义示例程序,想实现每隔约1秒发送消息并验证TSCH接收功能(代码里有些冗余,后续会优化),但编译时遇到了链接错误,提示找不到tsch_set_coordinator函数。下面是我的相关代码、配置以及遇到的问题,想请教下哪里操作有误?
待编译的示例代码
#include "contiki.h" #include "contiki-net.h" // 尝试修复问题时改成了绝对路径 #include "/home/user/contiki-master/core/net/mac/tsch/tsch.h" // 原本应该写的相对路径 // #include "net/mac/tsch/tsch.h" /* * 控制LED的头文件 */ #include "dev/leds.h" #include <stdio.h> #define DEBUG DEBUG_PRINT #include "net/ip/uip-debug.h" // 本示例的自定义头文件,包含常量定义 #include "./example-tsch-common.h" #define UIP_IP_BUF ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN]) static struct etimer tsch_example_etimer_struct_timer; PROCESS(coord_process, "TSCH Coordinator"); AUTOSTART_PROCESSES(&coord_process); PROCESS_THREAD(coord_process, ev, data) { static uip_ds6_addr_t *myaddr; static uip_ipaddr_t ipaddr; static uip_ipaddr_t linklocal_all_node; static struct uip_udp_conn *conn_unicast; static struct uip_udp_conn *conn_broadcast; static int unicast_received = 0; static int broadcast_received = 0; linkaddr_t *dest_lladdr; PROCESS_BEGIN(); uiplib_ip6addrconv(NODE_ADDR, &ipaddr); conn_unicast = udp_new(&ipaddr, UIP_HTONS(APP_PORT), NULL); uip_udp_bind(conn_unicast, UIP_HTONS(APP_PORT)); myaddr = uip_ds6_get_link_local(-1); tsch_set_coordinator(1); while(1) { PROCESS_YIELD(); etimer_set(&tsch_example_etimer_struct_timer, CLOCK_SECOND); PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER); printf("COORD TX\n"); uip_udp_packet_send(conn_unicast, uip_appdata, uip_datalen()); } PRINTF("APP: done\n"); PROCESS_END(); }
编译命令
我执行的编译命令是:
make TARGET=sky example-tsch-coord
编译错误信息
编译时出现如下链接错误:
example-tsch-coord.co: In function `process_thread_coord_process': /home/user/contikiProgramSourceFiles/tschTest1/example-tsch-coord.c:145: undefined reference to `tsch_set_coordinator' collect2: ld returned 1 exit status make: *** [example-tsch-coord.sky] Error 1 rm example-tsch-coord.co obj_sky/contiki-sky-main.o
我的Makefile配置
代码路径是/home/user/contikiProgramSourceFiles/tschTest1,对应的Makefile内容如下:
CONTIKI = /home/user/contiki-master CONTIKI_WITH_IPV6 = 1 MODULES += $(CONTIKI)/core/net/mac/tsch MODULES += /home/user/contikiProgramSourceFiles/tschTest1 include $(CONTIKI)/Makefile.include
project-conf.h配置
#undef UIP_CONF_IPV6_RPL #define UIP_CONF_IPV6_RPL 0 #define TSCH_SCHEDULE_CONF_WITH_6TISCH_MINIMAL 1 /* 网络栈层配置 */ #undef NETSTACK_CONF_MAC #define NETSTACK_CONF_MAC tschmac_driver #undef NETSTACK_CONF_RDC #define NETSTACK_CONF_RDC nordc_driver #undef NETSTACK_CONF_FRAMER #define NETSTACK_CONF_FRAMER framer_802154 /* IEEE802.15.4帧版本 */ #undef FRAME802154_CONF_VERSION #define FRAME802154_CONF_VERSION FRAME802154_IEEE802154E_2012 /* 需要NDP */ #undef UIP_CONF_ND6_SEND_NA #define UIP_CONF_ND6_SEND_NA 1 #undef UIP_CONF_IPV6_QUEUE_PKT #define UIP_CONF_IPV6_QUEUE_PKT 1 /* 仅cc2420平台需要 */ /* 禁用DCO校准(使用timerB) */ #undef DCOSYNCH_CONF_ENABLED #define DCOSYNCH_CONF_ENABLED 0 /* 启用SFD时间戳(使用timerB) */ #undef CC2420_CONF_SFD_TIMESTAMPS #define CC2420_CONF_SFD_TIMESTAMPS 1 #undef TSCH_CONF_DEFAULT_TIMESLOT_LENGTH #define TSCH_CONF_DEFAULT_TIMESLOT_LENGTH 10000
我的困惑
我认为问题出在编译器无法找到定义在/home/user/contiki-master/core/net/mac/tsch/tsch.h中的tsch_set_coordinator函数。我参考了Contiki仓库自带的examples/ipv6/rpl-tsch/Makefile来编写自己的Makefile,后来还尝试把代码中的头文件引用改成绝对路径,但问题还是没解决。按我的理解,指定绝对路径后编译器应该能找到这个函数才对,到底哪里操作错了呢?
内容的提问来源于stack exchange,提问作者HXSP1947
相关产品推荐
相关产品推荐

