Skip to content

Building PYCC for MacOS issues

dimxy edited this page Aug 18, 2020 · 25 revisions

Several issues when building PYCC komodod and pycctx.so lib for MacOS

Used MacOS: Catalyna

Building komodod with Python Engine on MacOS

Note: To build komodod with pycc support you also need to pass --enable-pycc flag to configure.

Where the reference to the python lib is. The ref to Python lib is defined in src/Makefile.am. Be careful it defines both version numbers (3.n), you should install the exact version as default. It was initially set by -lpython3.6m but I changed it to 3.7 as 3.6 installation is not directly supported on my MacOS.

To make headers like "Python.h" and lib libpython3.7m.dylib available for the compiler I added
-I /usr/local/opt/[email protected]/Frameworks/Python.framework/Headers and
-L /usr/local/opt/[email protected]/3.7.8_1/Frameworks/Python.framework/Versions/3.7/lib/ to CPPFLAGS var in build-mac.sh

this is how env vars in build-mac.sh look like:

CPPFLAGS="-I$PREFIX/include -I/usr/local/opt/[email protected]/Frameworks/Python.framework/Headers -arch x86_64" \
LDFLAGS="-L$PREFIX/lib -L/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/Current/lib -arch x86_64 -Wl,-no_pie" \
CXXFLAGS='-arch x86_64 -I/usr/local/Cellar/gcc\@8/8.3.0/include/c++/8.3.0/ -I$PREFIX/include -fwrapv -fno-strict-aliasing -Wno-builtin-declaration-mismatch -Werror -g -Wl,-undefined -Wl,dynamic_lookup -Wno-attributes' 
./configure --prefix="${PREFIX}" --with-gui=no "$HARDENING_ARG" "$LCOV_ARG" --enable-pycc

(Note: first I tried these params:
I added -L/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/headers to CPPFLAGS and yet I added -Wl,-rpath,/Library/Developer/CommandLineTools/Library/Frameworks to CXXFLAGS to resolve relative dependency to the python3 that was added: @rpath/Python3.framework/Versions/3.7/Python3. Then it was built okay but komodod began to print errors like base58.py is not installed. Installing base58 with pip3 did not resolve the issue so it looks like this python in /Library... folder is a different installation, and it did not have pip3 in itself)

Building libpycctx.dylib on MacOS

When I built libpycctx.dylib (running make) make ended with a lot of errors like:

Undefined symbols for architecture x86_64:
            "_PyImport_ExecCodeModuleEx", referenced from:
                pyo3::types::module::PyModule::from_code::h5221d5256e3ab9a9 in libpyo3-a79a90d0681fac3f.rlib(pyo3-a79a90d0681fac3f.pyo3.dl3qelwn-cgu.9.rcgu.o)

The solution to fix those build errors for Mac was found here: https://github.com/PyO3/pyo3, it is to create a ~/.cargo/config with params (or add to an existing config):

[target.x86_64-apple-darwin]
rustflags = [
  "-C", "link-arg=-undefined",
  "-C", "link-arg=dynamic_lookup",
]

When libpycc.dylib is built successfully it is needed to make a link to it from the ./pycc directory

pycc % ln -s ./target/release/libpycctx.dylib pycctx.so

(note .so extension)

Clone this wiki locally