Menu

#34 1.8.0: patch for FreeBSD compilation

closed-accepted
None
5
2010-03-20
2010-03-12
No

Fix the order of header inclusion for FreeBSD

Discussion

  • Nick Leverton

    Nick Leverton - 2010-03-12
     
  • Marcelo Roberto Jimenez

    • assigned_to: nobody --> mroberto
     
  • Marcelo Roberto Jimenez

    Hi nick,

    That's odd, you mean that there is an imposed order on the include files in FreeBSD? Do you mind pointing me a reference to this problem, I have never heard about something like that. Anyway, sounds more like a bug in FreeBSD, look:

    http://www.gnu.org/s/libc/manual/html_node/Header-Files.html

    "Compatibility Note: Inclusion of standard header files in any order and any number of times works in any ISO C implementation. However, this has traditionally not been the case in many older C implementations."

    If you assure me that it won't compile the way it is today, I can commit it, but with a statement that it is due to a broken FreeBSD issue.

    Regards,
    Marcelo.

     
  • Nick Leverton

    Nick Leverton - 2010-03-13

    Hmm, let me look more into it then. I just remember the programming days too well when you did have to #include headers in the right order. Maybe there's another explanation for my problem!

     
  • Nick Leverton

    Nick Leverton - 2010-03-14

    Yes, confirmed that both parts of the patch are needed (on FreeBSD 7.2 at least). These are the errors without the uri.h inclusion of sys/socket.h:

    gcc -DHAVE_CONFIG_H -I. -I.. -I../upnp/inc -I./inc -I../threadutil/inc -I../ixml/inc -I./src/inc -D_THREAD_SAFE -pthread -g -O0 -Wall -MT src/genlib/net/uri/libupnp_la-uri.lo -MD -MP -MF src/genlib/net/uri/.deps/libupnp_la-uri.Tpo -c src/genlib/net/uri/uri.c -fPIC -DPIC -o src/genlib/net/uri/.libs/libupnp_la-uri.o
    src/genlib/net/uri/uri.c: In function 'parse_hostport':
    src/genlib/net/uri/uri.c:338: error: 'AF_UNSPEC' undeclared (first use in this function)
    src/genlib/net/uri/uri.c:338: error: (Each undeclared identifier is reported only once
    src/genlib/net/uri/uri.c:338: error: for each function it appears in.)
    src/genlib/net/uri/uri.c:365: error: 'AF_INET6' undeclared (first use in this function)
    src/genlib/net/uri/uri.c:383: error: 'AF_INET' undeclared (first use in this function)
    src/genlib/net/uri/uri.c:391: error: 'SOCK_STREAM' undeclared (first use in this function)
    *** Error code 1

    These are the errors in upnpapi.c if net/if.h precedes sys/socket.h:

    gcc -DHAVE_CONFIG_H -I. -I.. -I../upnp/inc -I./inc -I../threadutil/inc -I../ixml/inc -I./src/inc -D_THREAD_SAFE -pthread -g -O0 -Wall -MT src/api/libupnp_la-upnpapi.lo -MD -MP -MF src/api/.deps/libupnp_la-upnpapi.Tpo -c src/api/upnpapi.c -fPIC -DPIC -o src/api/.libs/libupnp_la-upnpapi.o
    In file included from src/api/upnpapi.c:55:
    /usr/include/net/if.h:293: error: field 'ifru_addr' has incomplete type
    /usr/include/net/if.h:294: error: field 'ifru_dstaddr' has incomplete type
    /usr/include/net/if.h:295: error: field 'ifru_broadaddr' has incomplete type
    /usr/include/net/if.h:327: error: field 'ifra_addr' has incomplete type
    /usr/include/net/if.h:328: error: field 'ifra_broadaddr' has incomplete type
    /usr/include/net/if.h:329: error: field 'ifra_mask' has incomplete type
    /usr/include/net/if.h:427: error: field 'addr' has incomplete type
    /usr/include/net/if.h:428: error: field 'dstaddr' has incomplete type
    *** Error code 1

    FreeBSD ports even includes a patch to libupnp 1.6.6 for the header inclusion order, so it looks as though it's a real issue. I don't have a freeBSD 8.x virtual machine to check if it's still outstanding, but it apparently is needed for 7.x.

     
  • Marcelo Roberto Jimenez

    Nick, please try the new version of the patch to see if it works. I want to be sure that testing for defined(BSD) is ok.

     
  • Nick Leverton

    Nick Leverton - 2010-03-19

    Hi Roberto,

    To test for defined(BSD) we need to include sys/param.h. Would you have a look at my newer version of the patch ? By including this header, we can simplify some of the other checks for BSD flavours too.

    The only ones which need explicit tests now are FreeBSD_kernel, for the Debian Gnu/FreeBSD hybrid, and NetBSD, which doesn't include POSIX scheduling in the default kernel.

    With the version 3 patch, libupnp will compile on all of {Free,Open,Net,kFree}BSD. I just need to bring my other *BSD patches up to date to match, and then it will actually initialise successfully too.

     
  • Nick Leverton

    Nick Leverton - 2010-03-19

    Oops, the patch as originally uploaded depended on the ones I'm re-working. Give me a while to re-upload ...

     
  • Nick Leverton

    Nick Leverton - 2010-03-19

    Rolled-up patch for all *~BSD issues

     
  • Nick Leverton

    Nick Leverton - 2010-03-19

    Now uploaded, a rolled-up patch for all BSD include/compile/initialisation issues.

     
  • Marcelo Roberto Jimenez

    Committed.

     
  • Marcelo Roberto Jimenez

    • status: open --> closed-accepted
     
MongoDB Logo MongoDB