t_tuntap_log causing linking failure
Closed this issue · 8 comments
Hello. When using this library (with C++) I get an error by the linker stating that t_tuntap_log
is defined multiple times in tuntap.h
line 146. It seems that the problematic line is this:
Line 146 in b7e25a4
Removing that, after the lib installation, makes everything work, but if it's removed before the library compilation you get the following error:
[dpolonio@davmark build]$ make
Scanning dependencies of target tuntap-static
[ 10%] Building C object CMakeFiles/tuntap-static.dir/tuntap.c.o
/home/dpolonio/Desktop/Repo/libtuntap/tuntap.c: In function ‘tuntap_init’:
/home/dpolonio/Desktop/Repo/libtuntap/tuntap.c:48:2: error: ‘tuntap_log’ undeclared (first use in this function); did you mean ‘t_tuntap_log’?
tuntap_log = tuntap_log_default;
^~~~~~~~~~
t_tuntap_log
/home/dpolonio/Desktop/Repo/libtuntap/tuntap.c:48:2: note: each undeclared identifier is reported only once for each function it appears in
/home/dpolonio/Desktop/Repo/libtuntap/tuntap.c: In function ‘tuntap_set_ip’:
/home/dpolonio/Desktop/Repo/libtuntap/tuntap.c:77:3: warning: implicit declaration of function ‘tuntap_log’; did you mean ‘tuntap_down’? [-Wimplicit-function-declaration]
tuntap_log(TUNTAP_LOG_NOTICE, "Device is not started");
^~~~~~~~~~
tuntap_down
make[2]: *** [CMakeFiles/tuntap-static.dir/build.make:63: CMakeFiles/tuntap-static.dir/tuntap.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:73: CMakeFiles/tuntap-static.dir/all] Error 2
make: *** [Makefile:130: all] Error 2
Hello, and thanks for the report.
Can you tell me which compiler and OS are you using ? Also, are you trying to build the C++ wrapper tuntap++ ?
We are exporting tuntap_log
but I am not sure it is necessary, this symbol is an internal function pointer.
Regards.
Hello,
thanks for the reply. My specs are:
[dpolonio@davmark ~]$ g++ --version
g++ (GCC) 8.2.1 20180831
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[dpolonio@davmark ~]$ uname -a
Linux davmark 4.18.5-arch1-1-ARCH #1 SMP PREEMPT Fri Aug 24 12:48:58 UTC 2018 x86_64 GNU/Linux
In particular, the error I obtain is:
connection/astaire-ConnectionManager.o:(.bss+0x0): multiple definition of `tuntap_log'
Makefile:434: recipe for target 'astaire' failed
make[2]: Leaving directory '/home/dpolonio/Desktop/Repo/Astaire/src'
Makefile:307: recipe for target 'all' failed
make[1]: Leaving directory '/home/dpolonio/Desktop/Repo/Astaire/src'
Makefile:362: recipe for target 'all-recursive' failed
astaire-Astaire.o:(.bss+0x0): first defined here
connection/astaire-tuntap++.o:(.bss+0x0): multiple definition of `tuntap_log'
astaire-Astaire.o:/home/dpolonio/Desktop/Repo/Astaire/src/Astaire.cpp:34: first defined here
collect2: error: ld returned 1 exit status
make[2]: *** [astaire] Error 1
make[1]: *** [all] Error 2
make: *** [all-recursive] Error 1
Yes, I've included tuntap++
in our project (I copied the class because we want to integrate it in our codebase), but even without it and working on a minimal example the error I obtain is still this:
[dpolonio@davmark test]$ cat test.cpp
#include <tuntap.h>
int main() {
tuntap_init();
return 0;
}
[dpolonio@davmark test]$ g++ -I/usr/include test.cpp
In file included from test.cpp:1:
/usr/include/tuntap.h:146:28: error: ‘void (* t_tuntap_log)(int, const char*)’ redeclared as different kind of symbol
TUNTAP_EXPORT t_tuntap_log t_tuntap_log;
^~~~~~~~~~~~
/usr/include/tuntap.h:145:16: note: previous declaration ‘typedef void (* t_tuntap_log)(int, const char*)’
typedef void (*t_tuntap_log)(int, const char *);
^~~~~~~~~~~~
In any case, our project is open, and you can find it here if you want to try to compile it yourself (the branch is libtuntap
and a working commit is afa68b9dba9a0abe5e9c4c877240d1fbe408735f
).
Best regards! And thank you for your time.
I tested the minimal example you provided without problems with the following C++ compliers:
- clang (OpenBSD clang version 6.0.0) ;
- eg++ (4.9.4)
- g++ (4.2.1)
Anyway I pushed a few commits on branch issue-3
, can you test them ? They basically hid the wrongdoing symbol.
FYI: this g++ is provided from the base OpenBSD system while eg++ is the “external” one from the packages.
Hey, we've tried the branch and it works like a charm! We made a PR adding the tuntap++
module in the make install
command when ENABLE_CXX
flag is activated.
Thanks for your time, cheers!
I am slowly getting back on this project so don't hesitate to suggest enhancements and ask about missing features.
Nice! Sure, if we came up with other enhancements for this library we'll open a pr/issue! 👍
Likewise for the current version, I'm getting multiple definitions of tuntap_log
:
/usr/bin/ld: ../lib/libtuntap.a(tuntap_log.c.o):(.bss+0x0): multiple definition of `tuntap_log'; ../lib/libtuntap.a(tuntap.c.o):(.bss+0x0): first defined here
/usr/bin/ld: ../lib/libtuntap.a(tuntap-unix.c.o):(.bss+0x0): multiple definition of `tuntap_log'; ../lib/libtuntap.a(tuntap.c.o):(.bss+0x0): first defined here
/usr/bin/ld: ../lib/libtuntap.a(tuntap-unix-linux.c.o):(.bss+0x0): multiple definition of `tuntap_log'; ../lib/libtuntap.a(tuntap.c.o):(.bss+0x0): first defined here
Simply declaring it static fixes that, though:
diff --git a/private.h b/private.h
index 743b228..2e38255 100644
--- a/private.h
+++ b/private.h
@@ -105,7 +105,7 @@ struct device {
# endif
/* Internal log facilities */
-t_tuntap_log tuntap_log;
+static t_tuntap_log tuntap_log;
void tuntap_log_default(int, const char *);
void tuntap_log_hexdump(void *, size_t);
void tuntap_log_chksum(void *, int);