Issue
I was trying use picoTCP on Windows. I was following the how to compile on Windows from here. This compiled the library successfully with only notes of usleep being deprecated. The next step was to use it.
The example code I wanted to compile was this (main.c):
#include <time.h>
#include "pico_stack.h"
#include "pico_ipv4.h"
#include "pico_icmp4.h"
int main() {
pico_stack_init();
return 0;
}
With a makefile I tried to compile it, which did not work.
compile:
gcc -c -o main.o -Ipicotcp/build/include main.c
gcc -o main.elf main.o picotcp/build/lib/libpicotcp.a
The error message says, that it can't find some random functions
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
I downloaded picoTCP from here
From the error messages I can see that it is failing to link the functions, even though they exist but, I could not find a answer on Google for it. Also this is not a PicoTCP bug, since the example ran on my Linux laptop.
Solution
I figured out, what caused the missing functions. It is basicly a weak reference to those functions, wich MinGW seems to ignore... By commenting out the define in pico_config.h like this '# define WEAK /* attribute((weak)) */' I was able to fix the problem. The github issue can be found here
Answered By - Ensber Answer Checked By - Robin (WPSolving Admin)