Opened 7 years ago

Last modified 3 years ago

#41343 assigned defect

python extension module builds missing -I/opt/local/include

Reported by: ned-deily (Ned Deily) Owned by: jmroot (Joshua Root)
Priority: Normal Milestone:
Component: ports Version: 2.2.1
Keywords: Cc: ci42, larryv (Lawrence Velázquez), chris.jerdonek@…, petrrr
Port: python27 python33 python34


When building third-party Python packages (i.e. those not in the Python standard library), the MacPorts configuration is causing C extension modules to be compiled without -I/opt/local/include but linked with -L/opt/local/lib. This definitely causes problems for packages that contain C modules that make use of OS X libraries that are shadowed in MacPorts. A good example are the openssl libraries, libssl and libcrypto, which are shipped with OS X and with newer versions provided in MacPorts.

The problem is caused by the port files only including -I/opt/local/include in CPPFLAGS but not in CFLAGS. For Python that is not enough because the value of CPPFLAGS does not influence extension modules built by Python's Distutils. There are a few long-open issues about this behavior, for example, but that's the way things have worked for a long time and continue to.

If you examine the logs of various py* ports which include C extension modules, you can see the difference between the compile and link compiler calls. This could affect ports in subtle ways if there is a library shadowing situation. The py*-openssl port seems to be vulnerable though I have not verified that it causes problems.

This issue came up while helping debug a segfault a user was seeing with a third-party Python package when built with a MacPorts Python. ( It was determined that the root cause was this issue in that the package was being compiled with system-provided openssl include files but linked with MacPorts openssl libs. Here is a simplified demo of the problem:

$ /opt/local/bin/python2.7 -c 'import sysconfig;print(sysconfig.get_config_var("CFLAGS"))'
-fno-strict-aliasing -fno-common -dynamic   -pipe -Os -fwrapv   -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes
$ /opt/local/bin/python2.7 -c 'import sysconfig;print(sysconfig.get_config_var("CPPFLAGS"))'
-I. -IInclude -I./Include -I/opt/local/include -I/opt/local/include/db46
$ /opt/local/bin/python2.7 -c 'import sysconfig;print(sysconfig.get_config_var("LDFLAGS"))'
  -isysroot / -L/opt/local/lib -Wl,-headerpad_max_install_names -L/opt/local/lib/db46

$ /opt/local/bin/pip-2.7 install
    building 'backports.pbkdf2._pbkdf2' extension
    /usr/bin/clang -fno-strict-aliasing -fno-common -dynamic -pipe -Os -fwrapv -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/opt/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c backports/pbkdf2/_pbkdf2.c -o build/temp.macosx-10.8-x86_64-2.7/backports/pbkdf2/_pbkdf2.o
    backports/pbkdf2/_pbkdf2.c:22:15: warning: 'ERR_peek_last_error' is deprecated [-Wdeprecated-declarations]
        errcode = ERR_peek_last_error();
    /usr/include/openssl/err.h:274:15: note: 'ERR_peek_last_error' declared here
    unsigned long ERR_peek_last_error(void) DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER;
    backports/pbkdf2/_pbkdf2.c:27:5: warning: 'ERR_clear_error' is deprecated [-Wdeprecated-declarations]
    /usr/include/openssl/err.h:278:6: note: 'ERR_clear_error' declared here
    void ERR_clear_error(void ) DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER;
    31 warnings generated.
    /usr/bin/clang -bundle -undefined dynamic_lookup -isysroot / -L/opt/local/lib -Wl,-headerpad_max_install_names -L/opt/local/lib/db46 build/temp.macosx-10.8-x86_64-2.7/backports/pbkdf2/_pbkdf2.o -lcrypto -o build/lib.macosx-10.8-x86_64-2.7/backports/pbkdf2/

$ /opt/local/bin/pip-2.7 uninstall backports.pbkdf2

$ export CFLAGS="$(/opt/local/bin/python2.7 -c 'import sysconfig;print(sysconfig.get_config_var("CFLAGS"))') -I/opt/local/include"
$ echo $CFLAGS
-fno-strict-aliasing -fno-common -dynamic -pipe -Os -fwrapv -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/opt/local/include
$ /opt/local/bin/pip-2.7 install --user
    building 'backports.pbkdf2._pbkdf2' extension
    /usr/bin/clang -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fno-strict-aliasing -fno-common -dynamic -pipe -Os -fwrapv -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/opt/local/include -I/opt/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c backports/pbkdf2/_pbkdf2.c -o build/temp.macosx-10.8-x86_64-2.7/backports/pbkdf2/_pbkdf2.o
    /usr/bin/clang -bundle -undefined dynamic_lookup -isysroot / -L/opt/local/lib -Wl,-headerpad_max_install_names -L/opt/local/lib/db46 -fno-strict-aliasing -fno-common -dynamic -pipe -Os -fwrapv -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/opt/local/include build/temp.macosx-10.8-x86_64-2.7/backports/pbkdf2/_pbkdf2.o -lcrypto -o build/lib.macosx-10.8-x86_64-2.7/backports/pbkdf2/

I have not looked at the older, non-current python ports to see if they are configured and behave the same but chances are that they do. It is also quite possible that other py*-* ports have unknowingly run into this problem in the past and have worked around it with patches to the package port rather than fixing the root problem in the python* port.

Change History (9)

comment:1 Changed 7 years ago by ci42

Cc: ciserlohn@… added

Cc Me!

comment:2 Changed 7 years ago by vergus@…

I was just about to submit a bug against pyyaml for not finding yaml.h, but this bug explains the issue.

comment:3 Changed 6 years ago by r.fagan@…

can somebody please fix this already.

comment:4 Changed 6 years ago by mf2k (Frank Schima)

Cc: jwa@… removed
Owner: changed from macports-tickets@… to jwa@…

Can someone please provide a patch?

comment:5 Changed 6 years ago by chris.jerdonek@…

I also ran into this issue when installing PyYAML using pip. It was not finding libyaml's /opt/local/include/yaml.h installed by MacPorts.

comment:6 Changed 6 years ago by larryv (Lawrence Velázquez)

Cc: larryv@… added

Cc Me!

comment:7 Changed 6 years ago by chris.jerdonek@…

Cc: chris.jerdonek@… added

Cc Me!

comment:8 Changed 5 years ago by petrrr

Cc: petr@… added

Cc Me!

comment:9 Changed 3 years ago by jmroot (Joshua Root)

Owner: changed from jyrkiwahlstedt to jmroot
Status: newassigned
Note: See TracTickets for help on using tickets.