Bug 413 - python bindings not portable to OS X
python bindings not portable to OS X
Status: RESOLVED FIXED
Product: ns-3
Classification: Unclassified
Component: python bindings
ns-3-dev
Mac Intel Mac OS
: P1 normal
Assigned To: Gustavo J. A. M. Carneiro
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2008-11-17 17:13 EST by Tom Henderson
Modified: 2008-11-25 07:48 EST (History)
3 users (show)

See Also:


Attachments
darwin-ppc build fix (5.33 KB, patch)
2008-11-20 07:11 EST, Gustavo J. A. M. Carneiro
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Henderson 2008-11-17 17:13:22 EST
I'm getting the following error when trying to enable Python on OS X:
[531/532] cxx_link: build/debug/bindings/python/ns3module_3.o build/debug/bindings/python/ns3module_helpers_3.o build/debug/bindings/python/ns3_module_bridge_3.o build/debug/bindings/python/ns3_module_common_3.o build/debug/bindings/python/ns3_module_contrib_3.o build/debug/bindings/python/ns3_module_core_3.o build/debug/bindings/python/ns3_module_csma_3.o build/debug/bindings/python/ns3_module_global_routing_3.o build/debug/bindings/python/ns3_module_helper_3.o build/debug/bindings/python/ns3_module_internet_stack_3.o build/debug/bindings/python/ns3_module_mobility_3.o build/debug/bindings/python/ns3_module_node_3.o build/debug/bindings/python/ns3_module_olsr_3.o build/debug/bindings/python/ns3_module_onoff_3.o build/debug/bindings/python/ns3_module_packet_sink_3.o build/debug/bindings/python/ns3_module_point_to_point_3.o build/debug/bindings/python/ns3_module_simulator_3.o build/debug/bindings/python/ns3_module_stats_3.o build/debug/bindings/python/ns3_module_udp_echo_3.o build/debug/bindings/python/ns3_module_wifi_3.o -> build/debug/bindings/python/ns3/_ns3.so
/usr/bin/ld: Undefined symbols:
_environ
collect2: ld returned 1 exit status

This seems to be a common problem for OS X, but am not sure how to best address it in our codebase:
http://wiki.finkproject.org/index.php/Fink:Porting_Notes#The__environ_symbol
Comment 1 Gustavo J. A. M. Carneiro 2008-11-18 08:47:45 EST
I don't get it.  Neither the NS-3 library nor the NS-3 Python module use any kind of '_environ' symbol.

Moreover I am no longer able to ssh into darwin-ppc like I used to, so I am not able to test this.
Comment 2 Gustavo J. A. M. Carneiro 2008-11-20 07:11:01 EST
Created attachment 311 [details]
darwin-ppc build fix

This patch fixes build errors on the darwin-ppc regression host.  It builds fine there and runs Python unit tests.  Still no idea about this _environ issue reported here.
Comment 3 Gustavo J. A. M. Carneiro 2008-11-22 07:09:33 EST
Comment on attachment 311 [details]
darwin-ppc build fix

I am waiting for approval from whoever owns the icmpv4 code to commit this.
Comment 4 Mathieu Lacage 2008-11-24 00:35:31 EST
(In reply to comment #2)
> Created an attachment (id=311) [details]
> darwin-ppc build fix
> 
> This patch fixes build errors on the darwin-ppc regression host.  It builds
> fine there and runs Python unit tests.  Still no idea about this _environ issue
> reported here.
> 

I really don't like this patch: the code should be fine without it. Would you mind show me the compiler error message together with compiler version ?
Comment 5 Mathieu Lacage 2008-11-24 03:02:41 EST
(In reply to comment #4)
> (In reply to comment #2)
> > Created an attachment (id=311) [details] [details]
> > darwin-ppc build fix
> > 
> > This patch fixes build errors on the darwin-ppc regression host.  It builds
> > fine there and runs Python unit tests.  Still no idea about this _environ issue
> > reported here.
> > 
> 
> I really don't like this patch: the code should be fine without it. Would you
> mind show me the compiler error message together with compiler version ?

The bug happens because the python headers include /usr/include/sys/termios.h which defines the macro ECHO to 0x000008 

This is really butt-ugly, especially since if you grep for ICMP_ECHO in /usr/include/*, you will find netinet/ip_icmp.h which defines it so, adding the ICMP prefix is not bullet-proof.

I don't really know what to do: the C preprocessor is a killer.

Comment 6 Gustavo J. A. M. Carneiro 2008-11-24 06:34:11 EST
(In reply to comment #5)
> The bug happens because the python headers include /usr/include/sys/termios.h
> which defines the macro ECHO to 0x000008 
> 
> This is really butt-ugly, especially since if you grep for ICMP_ECHO in
> /usr/include/*, you will find netinet/ip_icmp.h which defines it so, adding the
> ICMP prefix is not bullet-proof.

Similar approach was followed by e.g. SocketError.

> 
> I don't really know what to do: the C preprocessor is a killer.

If it were up to me I would still commit this patch as is.  It may not be bullet proof, but it fixes our immediate problem.  I don't like fixing potential/unlikely problems.

Another approach would be to #ifdef ECHO #undef ECHO #endif, after including <Python.h> but before including ns-3 headers.
Comment 7 Mathieu Lacage 2008-11-24 06:47:00 EST
(In reply to comment #6)

> Another approach would be to #ifdef ECHO #undef ECHO #endif, after including
> <Python.h> but before including ns-3 headers.

If that works, I would very much prefer this.

Comment 8 Gustavo J. A. M. Carneiro 2008-11-24 07:40:59 EST
(In reply to comment #7)
> (In reply to comment #6)
> 
> > Another approach would be to #ifdef ECHO #undef ECHO #endif, after including
> > <Python.h> but before including ns-3 headers.
> 
> If that works, I would very much prefer this.
> 

In that case, let's not argue about it.  Committed.

Only problem remaining is the _environ issue, which I cannot reproduce on darwin-ppc unfortunately.
Comment 9 Tom Henderson 2008-11-24 23:14:52 EST
(In reply to comment #8)
> (In reply to comment #7)
> > (In reply to comment #6)
> > 
> > > Another approach would be to #ifdef ECHO #undef ECHO #endif, after including
> > > <Python.h> but before including ns-3 headers.
> > 
> > If that works, I would very much prefer this.
> > 
> 
> In that case, let's not argue about it.  Committed.
> 
> Only problem remaining is the _environ issue, which I cannot reproduce on
> darwin-ppc unfortunately.
> 

I cannot reproduce the _environ issue anymore either, so please mark as fixed if it passes the overnight tests.