如何在 Windows 上编译 PicoTCP 最小示例
How to compile PicoTCP minimal example on Windows
我尝试在 Windows 上使用 picoTCP。我正在关注如何从 here 编译 Windows。这成功地编译了库,只有 usleep 被弃用。下一步就是使用它了。
我想编译的示例代码是这样的 (main.c):
#include <time.h>
#include "pico_stack.h"
#include "pico_ipv4.h"
#include "pico_icmp4.h"
int main() {
pico_stack_init();
return 0;
}
我尝试用 makefile 编译它,但没有成功。
compile:
gcc -c -o main.o -Ipicotcp/build/include main.c
gcc -o main.elf main.o picotcp/build/lib/libpicotcp.a
错误消息说,它找不到一些 运行dom 函数
C:\Users\______\repos\fsync\df-sync\modules\protoConv>gcc -o main.elf main.o picotcp/build/lib/libpicotcp.a
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: picotcp/build/lib/libpicotcp.a(pico_stack.o): in function `pico_rand':
c:\Users\niklas\repos\fsync\df-sync\modules\protoConv\picotcp/stack/pico_stack.c:61: undefined reference to `pico_rand_feed'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: picotcp/build/lib/libpicotcp.a(pico_stack.o): in function `pico_stack_recv_new_frame':
c:\Users\niklas\repos\fsync\df-sync\modules\protoConv\picotcp/stack/pico_stack.c:453: undefined reference to `pico_rand_feed'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: picotcp/build/lib/libpicotcp.a(pico_stack.o): in function `pico_sendto_dev':
c:\Users\niklas\repos\fsync\df-sync\modules\protoConv\picotcp/stack/pico_stack.c:539: undefined reference to `pico_rand_feed'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: picotcp/build/lib/libpicotcp.a(pico_stack.o): in function `pico_stack_tick':
c:\Users\niklas\repos\fsync\df-sync\modules\protoConv\picotcp/stack/pico_stack.c:767: undefined reference to `pico_rand_feed'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: c:\Users\niklas\repos\fsync\df-sync\modules\protoConv\picotcp/stack/pico_stack.c:770: undefined reference to `pico_rand_feed'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: picotcp/build/lib/libpicotcp.a(pico_stack.o):c:\Users\niklas\repos\fsync\df-sync\modules\protoConv\picotcp/stack/pico_stack.c:773: more undefined references to `pico_rand_feed' follow
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: picotcp/build/lib/libpicotcp.a(pico_aodv.o): in function `pico_aodv_init':
c:\Users\niklas\repos\fsync\df-sync\modules\protoConv\picotcp/modules/pico_aodv.c:626: undefined reference to `pico_rand'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: picotcp/build/lib/libpicotcp.a(pico_dns_client.o): in function `pico_dns_client_query_header':
c:\Users\niklas\repos\fsync\df-sync\modules\protoConv\picotcp/modules/pico_dns_client.c:247: undefined reference to `pico_rand'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: picotcp/build/lib/libpicotcp.a(pico_igmp.o): in function `srsfst':
c:\Users\niklas\repos\fsync\df-sync\modules\protoConv\picotcp/modules/pico_igmp.c:885: undefined reference to `pico_rand'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: picotcp/build/lib/libpicotcp.a(pico_igmp.o): in function `mrsrrt':
c:\Users\niklas\repos\fsync\df-sync\modules\protoConv\picotcp/modules/pico_igmp.c:927: undefined reference to `pico_rand'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: picotcp/build/lib/libpicotcp.a(pico_igmp.o): in function `srst':
c:\Users\niklas\repos\fsync\df-sync\modules\protoConv\picotcp/modules/pico_igmp.c:971: undefined reference to `pico_rand'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: picotcp/build/lib/libpicotcp.a(pico_igmp.o):c:\Users\niklas\repos\fsync\df-sync\modules\protoConv\picotcp/modules/pico_igmp.c:1020: more undefined references to `pico_rand' follow
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: picotcp/build/lib/libpicotcp.a(pico_device.o): in function `pico_device_ipv6_random_ll':
c:\Users\niklas\repos\fsync\df-sync\modules\protoConv\picotcp/stack/pico_device.c:180: undefined reference to `pico_rand_feed'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: picotcp/build/lib/libpicotcp.a(pico_socket.o): in function `pico_socket_high_port':
c:\Users\niklas\repos\fsync\df-sync\modules\protoConv\picotcp/stack/pico_socket.c:808: undefined reference to `pico_rand'
collect2.exe: error: ld returned 1 exit status
The folder structure is as follows
|-main.c
|-Makefile
|-picotcp
我从 here
下载了 picoTCP
从错误消息中我可以看到它无法 link 函数,即使它们存在,但我无法在 Google 上找到它的答案。
这也不是 PicoTCP 错误,因为示例 运行 在我的 Linux 笔记本电脑上。
我想通了,是什么导致了功能缺失。它基本上是对那些功能的弱引用,而 MinGW 似乎忽略了......
通过像这样注释掉 pico_config.h 中的定义 '# define WEAK /* attribute((weak)) */' 我能够解决问题。
github 问题可以在 here
找到
我尝试在 Windows 上使用 picoTCP。我正在关注如何从 here 编译 Windows。这成功地编译了库,只有 usleep 被弃用。下一步就是使用它了。
我想编译的示例代码是这样的 (main.c):
#include <time.h>
#include "pico_stack.h"
#include "pico_ipv4.h"
#include "pico_icmp4.h"
int main() {
pico_stack_init();
return 0;
}
我尝试用 makefile 编译它,但没有成功。
compile:
gcc -c -o main.o -Ipicotcp/build/include main.c
gcc -o main.elf main.o picotcp/build/lib/libpicotcp.a
错误消息说,它找不到一些 运行dom 函数
C:\Users\______\repos\fsync\df-sync\modules\protoConv>gcc -o main.elf main.o picotcp/build/lib/libpicotcp.a
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: picotcp/build/lib/libpicotcp.a(pico_stack.o): in function `pico_rand':
c:\Users\niklas\repos\fsync\df-sync\modules\protoConv\picotcp/stack/pico_stack.c:61: undefined reference to `pico_rand_feed'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: picotcp/build/lib/libpicotcp.a(pico_stack.o): in function `pico_stack_recv_new_frame':
c:\Users\niklas\repos\fsync\df-sync\modules\protoConv\picotcp/stack/pico_stack.c:453: undefined reference to `pico_rand_feed'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: picotcp/build/lib/libpicotcp.a(pico_stack.o): in function `pico_sendto_dev':
c:\Users\niklas\repos\fsync\df-sync\modules\protoConv\picotcp/stack/pico_stack.c:539: undefined reference to `pico_rand_feed'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: picotcp/build/lib/libpicotcp.a(pico_stack.o): in function `pico_stack_tick':
c:\Users\niklas\repos\fsync\df-sync\modules\protoConv\picotcp/stack/pico_stack.c:767: undefined reference to `pico_rand_feed'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: c:\Users\niklas\repos\fsync\df-sync\modules\protoConv\picotcp/stack/pico_stack.c:770: undefined reference to `pico_rand_feed'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: picotcp/build/lib/libpicotcp.a(pico_stack.o):c:\Users\niklas\repos\fsync\df-sync\modules\protoConv\picotcp/stack/pico_stack.c:773: more undefined references to `pico_rand_feed' follow
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: picotcp/build/lib/libpicotcp.a(pico_aodv.o): in function `pico_aodv_init':
c:\Users\niklas\repos\fsync\df-sync\modules\protoConv\picotcp/modules/pico_aodv.c:626: undefined reference to `pico_rand'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: picotcp/build/lib/libpicotcp.a(pico_dns_client.o): in function `pico_dns_client_query_header':
c:\Users\niklas\repos\fsync\df-sync\modules\protoConv\picotcp/modules/pico_dns_client.c:247: undefined reference to `pico_rand'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: picotcp/build/lib/libpicotcp.a(pico_igmp.o): in function `srsfst':
c:\Users\niklas\repos\fsync\df-sync\modules\protoConv\picotcp/modules/pico_igmp.c:885: undefined reference to `pico_rand'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: picotcp/build/lib/libpicotcp.a(pico_igmp.o): in function `mrsrrt':
c:\Users\niklas\repos\fsync\df-sync\modules\protoConv\picotcp/modules/pico_igmp.c:927: undefined reference to `pico_rand'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: picotcp/build/lib/libpicotcp.a(pico_igmp.o): in function `srst':
c:\Users\niklas\repos\fsync\df-sync\modules\protoConv\picotcp/modules/pico_igmp.c:971: undefined reference to `pico_rand'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: picotcp/build/lib/libpicotcp.a(pico_igmp.o):c:\Users\niklas\repos\fsync\df-sync\modules\protoConv\picotcp/modules/pico_igmp.c:1020: more undefined references to `pico_rand' follow
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: picotcp/build/lib/libpicotcp.a(pico_device.o): in function `pico_device_ipv6_random_ll':
c:\Users\niklas\repos\fsync\df-sync\modules\protoConv\picotcp/stack/pico_device.c:180: undefined reference to `pico_rand_feed'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: picotcp/build/lib/libpicotcp.a(pico_socket.o): in function `pico_socket_high_port':
c:\Users\niklas\repos\fsync\df-sync\modules\protoConv\picotcp/stack/pico_socket.c:808: undefined reference to `pico_rand'
collect2.exe: error: ld returned 1 exit status
The folder structure is as follows
|-main.c
|-Makefile
|-picotcp
我从 here
下载了 picoTCP从错误消息中我可以看到它无法 link 函数,即使它们存在,但我无法在 Google 上找到它的答案。 这也不是 PicoTCP 错误,因为示例 运行 在我的 Linux 笔记本电脑上。
我想通了,是什么导致了功能缺失。它基本上是对那些功能的弱引用,而 MinGW 似乎忽略了...... 通过像这样注释掉 pico_config.h 中的定义 '# define WEAK /* attribute((weak)) */' 我能够解决问题。 github 问题可以在 here
找到