jacobstanley/network-info

inline usage in cbits/common.h is invalid C99

23Skidoo opened this issue · 2 comments

Newer versions of gcc default to -std=gnu11, which uses C99 inline semantics, while older ones default to -std=gnu89, which uses traditional GNU inline semantics. C99 inline works differently than both C++ and traditional GNU inline -- in particular, it doesn't emit an externally visible symbol for the function unless there's a external inline declaration in one of the .c files.

This means that when compiled with a newer gcc, programs using network-info can fail during the linking step with the following error:

[...](network-unix.o):function add_interface: error: undefined reference to 'wcsempty'
[...](network-unix.o):function add_interface: error: undefined reference to 'wszcopy'
[...](network-unix.o):function count_interfaces: error: undefined reference to 'wcsempty'
[...](network-unix.o):function c_get_network_interfaces: error: undefined reference to 'mbswszcopy'
[...](network-unix.o):function c_get_network_interfaces: error: undefined reference to 'ipv4copy'
[...](network-unix.o):function c_get_network_interfaces: error: undefined reference to 'ipv6copy'
collect2: error: ld returned 1 exit status
`gcc' failed in phase `Linker'. (Exit code: 1)

See https://gustedt.wordpress.com/2010/11/29/myth-and-reality-about-inline-in-c99/, https://gcc.gnu.org/onlinedocs/gcc/Inline.html, https://en.wikipedia.org/wiki/Inline_function#gnu89 and https://stackoverflow.com/questions/16245521/c99-inline-function-in-c-file/16245669#16245669 for more details.

Potential solutions:

  • add -fgnu89-inline to cc-options
  • add -std=c99 to cc-options and add external inline declarations for all inline functions to some .c file.
  • replace inline in common.h with static.

We verified that adding -fgnu89-inline to cc-options fixes the problem.

I'm happy to accept this change. My only concern is that I don't have access to a windows box at the moment to test it on. I would expect that -fgnu89-inline should be just fine though.