~mcepl/m2crypto#366: 
Error: CPP error "Unsupported architecture". Use the -cpperraswarn option to continue swig processing

my Environment: macos:15.2 x86_64 python version: 3.11.10 swig version:

SWIG Version 4.2.1

Compiled with /Applications/Xcode_15.0.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ [Darwin]

Configured options: +pcre

Please see https://www.swig.org for reporting bugs and further information

When I use pip install m2crypto==0.40.1, an error occurs:

INFO:spawn:swig -python -py3 -I/usr/local/include -I/Library/Developer/CommandLineTools/usr/lib/clang/16/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -I/Library/Developer/CommandLineTools/usr/include "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)" -I/usr/local/include -I/Library/Developer/CommandLineTools/usr/lib/clang/16/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -I/Library/Developer/CommandLineTools/usr/include "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)" -I/Users/xxxx/opt/anaconda3/envs/python3.11.10/include/python3.11 -I/usr/include/openssl -includeall -modern -builtin -outdir /private/var/folders/d_/f5d257050b1g1h8xtxnpxfr00000gp/T/pip-install-fn7rv1um/m2crypto_47e165cda08a48f19c3aa6e93e463980/src/M2Crypto -o src/SWIG/_m2crypto_wrap.c src/SWIG/_m2crypto.i Deprecated command line option: -py3. Ignored, this option is no longer supported. Deprecated command line option: -modern. Ignored, this option is now always on. /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/cdefs.h:81: Warning 204: CPP #warning, ""Unsupported compiler detected"". /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/cdefs.h:1037: Error: CPP #error "Unsupported architecture". Use the -cpperraswarn option to continue swig processing. /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/machine/types.h:39: Error: CPP #error "architecture not supported". Use the -cpperraswarn option to continue swig processing. /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/machine/_types.h:36: Error: CPP #error "architecture not supported". Use the -cpperraswarn option to continue swig processing. /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/machine/endian.h:39: Error: CPP #error "architecture not supported". Use the -cpperraswarn option to continue swig processing. /Library/Developer/CommandLineTools/usr/lib/clang/16/include/stdint.h:20: Warning 202: Could not evaluate expression '__STDC_HOSTED__ && __has_include_next(<stdint.h>)' /Library/Developer/CommandLineTools/usr/lib/clang/16/include/stdint.h:20: Warning 202: Use of undefined function-like macro
Status
REPORTED
Submitter
~shawnwang
Assigned to
No-one
Submitted
4 months ago
Updated
3 months ago
Labels
helpneeded macOS needinfo

~mcepl 4 months ago

I am sorry, but M2Crypto has C extension, not the C++ one. And C++ compiler is not the same as C. Please, use C compiler instead.

~shawnwang (edited) 4 months ago*

Xcode Command Line Tools used on macOS. still error:

INFO:spawn:swig -python -py3 -I/usr/local/include -I/Library/Developer/CommandLineTools/usr/lib/clang/16/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -I/Library/Developer/CommandLineTools/usr/include "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)" -I/usr/local/include -I/Library/Developer/CommandLineTools/usr/lib/clang/16/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -I/Library/Developer/CommandLineTools/usr/include "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)" -I/Users/xxx/opt/anaconda3/envs/python3.11.10/include/python3.11 -I/usr/include/openssl -includeall -modern -builtin -outdir /private/var/folders/d_/f5d257050b1g1h8xtxnpxfr00000gp/T/pip-install-53y_xhus/m2crypto_1a00af39d40c426e89adfaa17cdf93d5/src/M2Crypto -o src/SWIG/_m2crypto_wrap.c src/SWIG/_m2crypto.i
      Deprecated command line option: -py3. Ignored, this option is no longer supported.
      Deprecated command line option: -modern. Ignored, this option is now always on.
      /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/cdefs.h:81: Warning 204: CPP #warning, ""Unsupported compiler detected"".
      /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/cdefs.h:1037: Error: CPP #error "Unsupported architecture". Use the -cpperraswarn option to continue swig processing.
      /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/machine/types.h:39: Error: CPP #error "architecture not supported". Use the -cpperraswarn option to continue swig processing.
      /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/machine/_types.h:36: Error: CPP #error "architecture not supported". Use the -cpperraswarn option to continue swig processing.
      /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/machine/endian.h:39: Error: CPP #error "architecture not supported". Use the -cpperraswarn option to continue swig processing.
      /Library/Developer/CommandLineTools/usr/lib/clang/16/include/stdint.h:20: Warning 202: Could not evaluate expression '__STDC_HOSTED__ && __has_include_next(<stdint.h>)'
      /Library/Developer/CommandLineTools/usr/lib/clang/16/include/stdint.h:20: Warning 202: Use of undefined function-like macro
      error: command '/Users/xxxx/opt/anaconda3/envs/python3.11.6/bin/swig' failed with exit code 1

~mcepl 4 months ago

I don’t have access to a Mac computer, so I am completely dependent on the help from outside. Any patches would be gratefully considered.

~mcepl 4 months ago

Also, 0.40.1 is a year and two months old. Please, reproduce, with the latest PyPI release (which is 0.43.0 at the moment).

~shawnwang 3 months ago*

I found the problem and the solution. This issue is caused by the _get_additional_includes method returning too many header files. On macOS 15.2, running the following code in a subprocess or terminal: cpp + ['-Wp,-v', '-']

return: #include "..." search starts here: #include <...> search starts here: /usr/local/include /Library/Developer/CommandLineTools/usr/lib/clang/16/include /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include /Library/Developer/CommandLineTools/usr/include /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory) End of search list.

~shawnwang 3 months ago*

So I modified the _get_additional_includes method:

if platform.system() == "Darwin":
    sdk_path = subprocess.check_output(['xcrun', '--show-sdk-path']).decode().strip()
    return [os.path.join(sdk_path, 'usr', 'include')]


cpp = shlex.split(os.environ.get('CPP', 'cpp'))
cflags = os.environ.get("CFLAGS")
if cflags is not None:
    cpp += cflags.split()
pid = subprocess.Popen(
    cpp + ['-Wp,-v', '-'],
    stdin=open(os.devnull, 'r'),
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE,
)
_, err = pid.communicate()
err = [
    line.lstrip()
    for line in err.decode('utf8').split('\n')
    if line and line.startswith(' /')
]

log.debug('additional includes:\n%s', err) return err

And for SWIG, the -cpperraswarn parameter needs to be added: self.swig_opts.append("-cpperraswarn")

Register here or Log in to comment, or comment via email.