lwip and C++ compilation/linking issue
Hello, I want to use TCP/IP (and therefore ankh and lwip) inside a C++ application. The unmodified lwip example (src/l4/pkg/ankh/examples/lwip) compiles fine (and also works without DHCP and with a little tweaking), but it is written and configured as C and not C++. So if I change the filename of main.c to main.cc and the Makefile accordingly, unfortunately it doesn't compile. Following error: ---------------- ... Compiling main.o In file included from /home/josef/Desktop/l4re-snapshot-2014053111/obj/l4/x86/include/contrib/lwip/contrib/src/include/lwip/arch.h:46:0, from /home/josef/Desktop/l4re-snapshot-2014053111/obj/l4/x86/include/contrib/lwip/contrib/src/include/lwip/debug.h:35, from /home/josef/Desktop/l4re-snapshot-2014053111/obj/l4/x86/include/contrib/lwip/contrib/src/include/lwip/opt.h:46, from /home/josef/Desktop/l4re-snapshot-2014053111/obj/l4/x86/include/contrib/lwip/contrib/src/include/lwip/tcpip.h:35, from /home/josef/Desktop/l4re-snapshot-2014053111/obj/l4/x86/include/l4/ankh/lwip-ankh.h:3, from /home/josef/Desktop/test/main.cc:10: /home/josef/Desktop/l4re-snapshot-2014053111/obj/l4/x86/include/contrib/lwip/arch/cc.h:48:13: error: previous declaration of ‘int* __h_errno_location()’ with ‘C++’ linkage extern int *__h_errno_location (void) __THROW __attribute__ ((__const__)); ^ In file included from /home/josef/Desktop/test/main.cc:19:0: /home/josef/Desktop/l4re-snapshot-2014053111/obj/l4/x86/include/uclibc/netdb.h:61:73: error: conflicts with new declaration with ‘C’ linkage extern int *__h_errno_location (void) __THROW __attribute__ ((__const__)); ^ make[1]: *** [main.o] Error 1 make: *** [/home/josef/Desktop/l4re-snapshot-2014053111/obj/l4/x86/ext-pkg/home/josef/Desktop/test/OBJ-x86_586-l4f] Error 2 ----------------- Alright, so I tried surrounding the offending include with 'extern "C" ' (as well as moving it above #include <l4/ankh/lwip-ankh.h> since this file also includes it): extern "C" { #include "arch/cc.h" } I think that it solved the problem, because the error went away, but another error appeared (see below), so I also tried doing the same only to the offending line inside arch/cc.h instead: extern "C" { extern int *__h_errno_location (void) __THROW __attribute__ ((__const__)); } Both approaches led to the same linker error: ------------------ main.o: In function `main': main.cc:(.text.startup+0x11c): undefined reference to `ankhif_init(netif*)' make[1]: *** [test] Error 1 make: *** [/home/josef/Desktop/l4re-snapshot-2014053111/obj/l4/x86/ext-pkg/home/josef/Desktop/test/OBJ-x86_586-l4f] Error 2 ------------------ This is the Makefile (only the line SRC_CC is different to the original example Makefile) ------------------ PKGDIR ?= . L4DIR ?= $(PKGDIR)/../l4re-snapshot-2014053111/src/l4 TARGET = test SRC_CC = main.cc SYSTEMS = x86-l4f arm-l4f REQUIRES_LIBS = lwip libc_be_socket_lwip liblwip_netif_ankh libc_support_misc include $(L4DIR)/mk/prog.mk ------------------ Which library is missing here, or what else could be going wrong? Cheers, Josef
Seems that the mail from Martin Küttler in another thread a few minutes ago solved my problem. Surrounding the ankhif_init() prototype in main.cc like this: extern "C" { extern err_t ankhif_init(struct netif*); } leads to a successful compilation. Thanks! Josef
participants (1)
-
Stark, Josef