Mac build and python C API

Having trouble installing or compiling FreeCAD? Get help here.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
Jolbas
Posts: 327
Joined: Sat Mar 26, 2022 7:48 am
Location: Sweden

Mac build and python C API

Post by Jolbas »

I try to build FreeCAD. I succeeded a few times after passing a lot of arguments to cmake. Then I downloaded the source again and something happened and I loosed all settings. Now I run into a new error and I can't find a simliar error on the forum. Maybe someone knows where to look.

This is my cmake command:

Code: Select all

cmake \
-DCMAKE_BUILD_TYPE="Release" \
-DHOMEBREW_PREFIX="$bp" \
-DUSE_PYTHON3=1 \
-DPYTHON_INCLUDE_DIR="$bp/Cellar/python@3.9/3.9.13/Frameworks/Python.framework/Versions/3.9/include/python3.9" \
-DPYTHON_LIBRARY="$bp/Cellar/python@3.9/3.9.13/Frameworks/Python.framework/Versions/3.9/lib/libpython3.9.dylib" \
-DBUILD_QT5=1 \
-DBUILD_SMESH=1 \
-DBUILD_FEM_NETGEN=1 \
-DFREECAD_CREATE_MAC_APP=1 \
-DOCC_INCLUDE_DIR=$bp/Cellar/opencascade@7.5.3/7.5.3/include/opencascade \
-DOCE_DIR=$bp/Cellar/opencascade@7.5.3/7.5.3/include/opencascade \
-DOCC_LIBRARY=$bp/Cellar/opencascade@7.5.3/7.5.3/lib/libTKernel.so \
-DCMAKE_PREFIX_PATH="$bp/Cellar/qt@5/5.15.3/lib/cmake;$bp/Cellar/coin3d/4.0.0_3/lib/cmake;$bp/Cellar/pyside@2/5.15.3/lib/cmake;$bp/Cellar/llvm/13.0.1_1/lib/cmake;$bp/Cellar/vtk@8.2/8.2.0_8/lib/cmake;$bp/Cellar/nglib@6.2.2104/6.2.2104_1/Contents/Resources/CMake;" \
-DCMAKE_INSTALL_PREFIX="./.." ../freecad-source/
This is the summary from cmake

Code: Select all

==============
Summary report
==============

-- Build type:          Release
-- Compiler:            /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ (13.1.6.13160021)
-- Flags:               -Wall -Wextra -Wpedantic -Wno-write-strings -std=c++14 -Wno-undefined-var-template
-- Standard:            Requires C++17
-- Python:              3.9.13 [/usr/local/Frameworks/Python.framework/Versions/3.9/bin/python3.9] [.abi3]
-- PCL:                 not enabled
-- pybind11:            not enabled
-- Boost:               1.78.0 (1.78.0)
-- XercesC:             3.2.3 [/usr/local/lib/libxerces-c.dylib] [/usr/local/include]
-- ZLIB:                1.2.11
-- PyCXX:               6.2.8 [/Users/bj/FreeCAD/freecad-source/src]
-- OCC:                 7.5.3 [TKFillet;TKMesh;TKernel;TKG2d;TKG3d;TKMath;TKIGES;TKSTL;TKShHealing;TKXSBase;TKBool;TKBO;TKBRep;TKTopAlgo;TKGeomAlgo;TKGeomBase;TKOffset;TKPrim;TKSTEPBase;TKSTEPAttr;TKSTEP209;TKSTEP;TKHLR;TKFeat] [/usr/local/Cellar/opencascade@7.5.3/7.5.3/lib] [/usr/local/Cellar/opencascade@7.5.3/7.5.3/include/opencascade]
-- SMESH:               build internal
--  MEDFile:            4.1.0 [/usr/local/lib/libmedC.dylib;/usr/local/lib/libmed.dylib] [/usr/local/include]
--  HDF5:               1.12.2
--  VTK:                8.2.0
-- NETGEN:              6.2.2104 (6.2.2104) [-DNO_PARALLEL_THREADS;-DOCCGEOMETRY;-DNETGEN_VERSION=395832] [] [/usr/local/Cellar/nglib@6.2.2104/6.2.2104_1/Contents/Resources/include/include;/usr/local/Cellar/nglib@6.2.2104/6.2.2104_1/Contents/Resources/include] [nglib] [/usr/local/Cellar/nglib@6.2.2104/6.2.2104_1/Contents/Resources/include/include;/usr/local/Cellar/nglib@6.2.2104/6.2.2104_1/Contents/Resources/include]
-- SWIG:                4.0.2
-- Eigen3               3.4.0
-- Qt5Core:             5.15.3
-- Qt5Network:          5.15.3
-- Qt5Xml:              5.15.3
-- Qt5XmlPatterns:      5.15.3
-- Qt5Widgets:          5.15.3
-- Qt5PrintSupport:     5.15.3
-- Qt5OpenGL:           5.15.3
-- Qt5Svg:              5.15.3
-- Qt5UiTools:          5.15.3
-- Qt5Concurrent:       5.15.3
-- Qt5WebEngineWidgets: 5.15.8
-- Designer plugin:     not built per user request (BUILD_DESIGNER_PLUGIN)
-- Shiboken2:           5.15.3 [/usr/local/Cellar/pyside@2/5.15.3/lib/cmake/Shiboken2-5.15.3] [/usr/local/Cellar/pyside@2/5.15.3/include/shiboken2;/usr/local/Cellar/python@3.9/3.9.13/Frameworks/Python.framework/Versions/3.9/include/python3.9]
-- PySide2:             5.15.3 [/usr/local/Cellar/pyside@2/5.15.3/include/PySide2]
-- PySide2Tools:        [/usr/local/Cellar/qt@5/5.15.3/bin/uic] [/usr/local/Cellar/qt@5/5.15.3/bin/rcc]
-- Freetype:            2.12.0
-- OpenGL:              /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/System/Library/Frameworks/OpenGL.framework
-- OpenGLU:             [/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/System/Library/Frameworks/OpenGL.framework][/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/System/Library/Frameworks/OpenGL.framework]
-- Coin3D:              4.0.0 [/usr/local/lib/libCoin.dylib] [/usr/local/include]
-- Pivy:                
-- SPNAV:               [SPNAV_LIBRARY-NOTFOUND] [SPNAV_INCLUDE_DIR-NOTFOUND]
-- Matplotlib:          3.4.3
-- Rift:                not enabled (BUILD_VR)
-- Doxygen:             1.9.4
--  Language:           English
--  Coin3D_DOC:         not found
And then a few minutes after running

Code: Select all

cmake --build ~/FreeCAD/build
I get this error:

Code: Select all

[  9%] Building CXX object src/Gui/CMakeFiles/FreeCADGui.dir/Application.cpp.o
In file included from ~/FreeCAD/freecad-source/src/Gui/Application.cpp:43:
In file included from ~/FreeCAD/build/src/App/DocumentObjectPy.h:7:
In file included from ~/FreeCAD/build/src/App/ExtensionContainerPy.h:7:
In file included from ~/FreeCAD/build/src/App/PropertyContainerPy.h:7:
In file included from ~/FreeCAD/build/src/Base/PersistencePy.h:7:
In file included from ~/FreeCAD/build/src/Base/BaseClassPy.h:7:
In file included from ~/FreeCAD/freecad-source/src/Base/PyObjectBase.h:55:
In file included from ~/FreeCAD/freecad-source/src/CXX/Objects.hxx:42:
~/FreeCAD/freecad-source/src/CXX/Python3/Objects.hxx:1026:18: error: unknown type name 'Py_complex'; did you mean '_Complex'?
        operator Py_complex() const
                 ^~~~~~~~~~
                 _Complex
~/FreeCAD/freecad-source/src/CXX/Python3/Objects.hxx:1026:18: warning: '_Complex' is a C99 extension [-Wc99-extensions]
~/FreeCAD/freecad-source/src/CXX/Python3/Objects.hxx:1026:18: warning: plain '_Complex' requires a type specifier; assuming '_Complex double'
        operator Py_complex() const
                 ^
                            double
~/FreeCAD/freecad-source/src/CXX/Python3/Objects.hxx:1031:35: error: unknown type name 'Py_complex'; did you mean '_Complex'?
        Complex &operator=( const Py_complex &v )
                                  ^~~~~~~~~~
                                  _Complex
~/FreeCAD/freecad-source/src/CXX/Python3/Objects.hxx:1031:35: warning: '_Complex' is a C99 extension [-Wc99-extensions]
~/FreeCAD/freecad-source/src/CXX/Python3/Objects.hxx:1031:35: warning: plain '_Complex' requires a type specifier; assuming '_Complex double'
        Complex &operator=( const Py_complex &v )
                                  ^
                                             double
~/FreeCAD/freecad-source/src/CXX/Python3/Objects.hxx:1028:20: error: use of undeclared identifier 'PyComplex_AsCComplex'
There is a lot more errors about PyUnicode_4BYTE_KIND, Py_UNICODE, PyComplex_FromCComplex etc. suggesting there is no connection to the python C API. But I don't understand what's missing to make it work

This is on MacOS 12.3.1 and the source code is from cloning https://github.com/FreeCAD/FreeCAD.git today.
User avatar
Jolbas
Posts: 327
Joined: Sat Mar 26, 2022 7:48 am
Location: Sweden

Re: Mac build and python C API

Post by Jolbas »

I did some tests by adding references to python API in files that compiles earlier in the build process. There is no problems when compiling files with such references in target FreeCADBase or target FreeCADApp but suddenly after

Code: Select all

[  9%] Automatic MOC for target FreeCADGui
[  9%] Built target FreeCADGui_autogen
Consolidate compiler generated dependencies of target FreeCADGui
it won't recognize for example Py_UNICODE. There is no preceding error indicating a problem with #include <Python.h>
User avatar
doia
Posts: 251
Joined: Sat May 29, 2021 5:47 am
Location: Düsseldorf

Re: Mac build and python C API

Post by doia »

Let me test your setup on my old Intel machine 8-) (I assume your are on Intel by the dependency location paths in the cmake report)
But first some questions:
- at what commit did your build break? If you don't know that, which approximately date, maybe we can infer the commit from this. Test earlier commits if they fail too. If they do there might be some error in your setup.
- remove the lines "-DUSE_PYTHON3=1 \" and "-DBUILD_QT5=1 \" from your setup, the first is not in use, the later is set to ON by default
wmayer
Founder
Posts: 20241
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Mac build and python C API

Post by wmayer »

~/FreeCAD/freecad-source/src/CXX/Python3/Objects.hxx:1026:18: error: unknown type name 'Py_complex'; did you mean '_Complex'?
operator Py_complex() const
The struct Py_complex is defined in the Python header file complexobject.h. However, it's only active if Py_LIMITED_API is not set. I guess that this isn't the problem here but possibly a missing Python.h.
In file included from ~/FreeCAD/freecad-source/src/Gui/Application.cpp:43:
Does it solve the problem when you add Python.h to the #ifndef _PreComp_/#endif block?
User avatar
Jolbas
Posts: 327
Joined: Sat Mar 26, 2022 7:48 am
Location: Sweden

Re: Mac build and python C API

Post by Jolbas »

wmayer wrote: Thu May 26, 2022 9:11 am Does it solve the problem when you add Python.h to the #ifndef _PreComp_/#endif block?
No, it doesn't change anything.
doia wrote: Thu May 26, 2022 8:49 am at what commit did your build break? If you don't know that, which approximately date, maybe we can infer the commit from this. Test earlier commits if they fail too. If they do there might be some error in your setup.
I am very new to using git or any version control system and also to building large applications. But I started to download the FreeCAD source two weeks ago following the instruktions https://wiki.freecadweb.org/Compile_on_MacOS. After some struggling with updating DCMAKE_PREFIX_PATH I managed to finish de build and had a working FreeCAD.app

Then I wanted to redo it but with a personal fork on github about a week ago. And since then I'm stuck.

Now I tried to download an older revision using for example

Code: Select all

git checkout d1b6bb78d1
I think this should give me a 2 month old revision
I also emptied the build directory so there's no cache that can interfere.
The errors remain so it seems I have messed up something. But I don't understand why the errors doesn't show until target FreeCADGui
User avatar
Jolbas
Posts: 327
Joined: Sat Mar 26, 2022 7:48 am
Location: Sweden

Re: Mac build and python C API

Post by Jolbas »

I did change #include <Python.h> in CXX/WrapPython.h to:

Code: Select all

#pragma message("before include")
#include <Python.h>
#pragma message("after include")
The I put a #pragma message("Python.h top line") on top of not just the Python.h that is instructed to be used but every 15 different Python.h I found on my drive. And the messages is printed as expected a lot of times until it reaches Gui/Application.cpp. There I get the before message and then the after message but nothing in between.
What is it that makes it just ignore the #include <Python.h> at this stage when it works a lot of times earlier in the process? I'm out of ideas how to proceed.
User avatar
Jolbas
Posts: 327
Joined: Sat Mar 26, 2022 7:48 am
Location: Sweden

Re: Mac build and python C API

Post by Jolbas »

I still can't figure out what's wrong. At least I have learned that waiting for weeks and then try again doesn't help :)

Do anyone understand why the compiler suddenly forgets/refuses to include Python.h when it apparently includes it earlier?
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Mac build and python C API

Post by Kunda1 »

@ipatch have you seen this issue before?
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
FreddyFreddy
Posts: 176
Joined: Wed Mar 09, 2022 3:15 am
Location: Oz

Re: Mac build and python C API

Post by FreddyFreddy »

macOS 12.5 same problem now with

Code: Select all

/Users/bernie/CLionProjects/FreeCAD/src/CXX/Python3/Objects.hxx:1026:18: error: unknown type name 'Py_complex'; did you mean '_Complex'?
etc. I hadn't done a build for a few weeks.
FreddyFreddy
Posts: 176
Joined: Wed Mar 09, 2022 3:15 am
Location: Oz

Re: Mac build and python C API

Post by FreddyFreddy »

Also some funny "Traceback" bits in cmake run

Code: Select all

/usr/local/bin/cmake -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles" -W no-dev -D CMAKE_PREFIX_PATH=/usr/local/opt/coin3d;/usr/local/opt/hdf5;/usr/local/opt/opencascade@7.5.3;usr/local/opt/qt@5;/usr/local/opt/vtk@8.2;/usr/local/opt/xerces-c;/usr/local/opt/icu4c;/usr/local/Cellar/qt@5/5.15.3 -D CMAKE_BUILD_TYPE=Release -D PYTHON_EXECUTABLE=/usr/local/bin/python3 -D PYTHON_INCLUDE_DIR=/usr/local/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/include/python3.9 -D PYTHON_LIBRARY=/usr/local/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/lib/libpython3.9.dylib -D FREECAD_CREATE_MAC_APP=ON -D FREECAD_USE_PYBIND11=OFF -D FREECAD_USE_EXTERNAL_KDL=OFF -D BUILD_FEM=ON -D CMAKE_INSTALL_PREFIX=~/ -S /Users/bernie/CLionProjects/FreeCAD -B /Users/bernie/CLionProjects/FreeCAD/cmake-build-release
-- Compiler: Clang, version: 13.0.1
-- Force BOOST_PP_VARIADICS=1 for clang
-- prefix: /Users/bernie
-- bindir: bin
-- datadir: share
-- docdir: share/doc/FreeCAD
-- includedir: include
-- libdir: lib
-- cmake: 3.22.3
-- Detected Homebrew install at /usr/local
-- PyCXX found:
--   Headers:  /Users/bernie/CLionProjects/FreeCAD/src
--   Sources:  /Users/bernie/CLionProjects/FreeCAD/src/CXX
--   Version:  6.2.8
-- -- Found OCE/OpenCASCADE version: 7.5.3
-- -- OCE/OpenCASCADE include directory: /usr/local/opt/opencascade@7.5.3/include/opencascade
-- -- OCE/OpenCASCADE shared libraries directory: /usr/local/opt/opencascade@7.5.3/lib
-- VTK components: vtkCommonCore;vtkCommonDataModel;vtkFiltersVerdict;vtkIOXML;vtkFiltersCore;vtkFiltersGeneral;vtkIOLegacy;vtkFiltersExtraction;vtkFiltersSources;vtkFiltersGeometry;vtkhdf5;vtkRenderingCore;vtkInteractionStyle;vtkRenderingFreeType;vtkRenderingOpenGL2
-- Check for medfile (libmed and libmedc) ...
-- We guess that libmed was built using hdf5-serial version
-- Checking for one of the modules 'hdf5-serial'
-- Found Boost: /usr/local/lib/cmake/Boost-1.78.0/BoostConfig.cmake (found suitable version "1.78.0", minimum required is "1.55") found components: filesystem program_options regex system thread date_time 
-- ************ CMAKE_CURRENT_LIST_DIR: /usr/local/Cellar/qt@5/5.15.3/lib/cmake/Qt5Core
-- Coin3D libraries found
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: module 'pivy' has no attribute '__version__'
-- Shiboken2Config: Using default python: .abi3
-- SHIBOKEN_PYTHON_INCLUDE_DIRS computed to value: '/usr/local/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/include/python3.9'
-- SHIBOKEN_PYTHON_LIBRARIES computed to value: '-undefined dynamic_lookup'
-- libshiboken built for Release
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/Cellar/python@3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/posixpath.py", line 152, in dirname
    p = os.fspath(p)
TypeError: expected str, bytes or os.PathLike object, not NoneType
================================
PySide2 Python module not found.
================================

-- Found Matplotlib: /usr/local/lib/python3.9/site-packages/matplotlib (found version "3.4.3")
-- Platform is 64-bit, set -D_OCC64
-- Performing Test _flag_found
-- Performing Test _flag_found - Success
-- Performing Test _flag_found
-- Performing Test _flag_found - Success
-- Performing Test _flag_found
-- Performing Test _flag_found - Success
-- [E57] Revison ID: E57Format-2.2.1-x86_64-darwin
-- [E57] Building static library
-- Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES) 
-- Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES) 
-- Could NOT find OpenMP (missing: OpenMP_C_FOUND OpenMP_CXX_FOUND) 
-- setting gcc options: -Wall -Werror -Wno-deprecated -pedantic-errors
-- Found Boost: /usr/local/lib/cmake/Boost-1.78.0/BoostConfig.cmake (found version "1.78.0") found components: python39 
-- found Boost: 1_78
-- boost-incude dirs are: /usr/local/include
-- boost-python lib is: 
-- boost_LIBRARY_DIRS is: /usr/local/lib
-- Boost_LIBRARIES is: Boost::python
-- area module (for Path Workbench) will be installed to: /Users/bernie/FreeCAD.app/Contents/lib
-- Performing Test _flag_found
-- Performing Test _flag_found - Success
-- Performing Test _flag_found
-- Performing Test _flag_found - Success
-- Note: Doxygen docs will look better with graphviz's dot installed.
-- 
==============
Summary report
==============

-- Build type:          Release
-- Compiler:            /usr/local/opt/llvm/bin/clang++ (13.0.1)
-- Flags:               -Wall -Wextra -Wpedantic -Wno-write-strings  -Wno-undefined-var-template
-- Standard:            Requires C++17
-- Python:              3.9.13 [/usr/local/Frameworks/Python.framework/Versions/3.9/bin/python3.9] [.abi3]
-- PCL:                 not enabled
-- pybind11:            not enabled
-- Boost:               1.78.0
-- XercesC:             3.2.3 [/usr/local/opt/xerces-c/lib/libxerces-c.dylib] [/usr/local/opt/xerces-c/include]
-- ZLIB:                1.2.11
-- PyCXX:               6.2.8 [/Users/bernie/CLionProjects/FreeCAD/src]
-- OCC:                 7.5.3 [TKFillet;TKMesh;TKernel;TKG2d;TKG3d;TKMath;TKIGES;TKSTL;TKShHealing;TKXSBase;TKBool;TKBO;TKBRep;TKTopAlgo;TKGeomAlgo;TKGeomBase;TKOffset;TKPrim;TKSTEPBase;TKSTEPAttr;TKSTEP209;TKSTEP;TKHLR;TKFeat] [/usr/local/opt/opencascade@7.5.3/lib] [/usr/local/opt/opencascade@7.5.3/include/opencascade]
-- SMESH:               build internal
--  MEDFile:            4.1.0 [/usr/local/lib/libmedC.dylib;/usr/local/lib/libmed.dylib] [/usr/local/include]
--  HDF5:               1.12.1
--  VTK:                8.2.0
-- NETGEN:              not enabled
-- SWIG:                4.0.2
-- Eigen3               3.4.0
-- Qt5Core:             5.15.3
-- Qt5Network:          5.15.3
-- Qt5Xml:              5.15.3
-- Qt5XmlPatterns:      5.15.3
-- Qt5Widgets:          5.15.3
-- Qt5PrintSupport:     5.15.3
-- Qt5OpenGL:           5.15.3
-- Qt5Svg:              5.15.3
-- Qt5UiTools:          5.15.3
-- Qt5Concurrent:       5.15.3
-- Qt5WebEngineWidgets: 5.15.8
-- Designer plugin:     not built per user request (BUILD_DESIGNER_PLUGIN)
-- Shiboken2:           5.15.3 [/usr/local/lib/cmake/Shiboken2-5.15.3] [/usr/local/include/shiboken2;/usr/local/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/include/python3.9]
-- PySide2:             5.15.3 [/usr/local/include/PySide2]
-- PySide2Tools:        [/usr/local/Cellar/qt@5/5.15.3/bin/uic] [/usr/local/Cellar/qt@5/5.15.3/bin/rcc]
-- Freetype:            2.12.1
-- OpenGL:              /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/System/Library/Frameworks/OpenGL.framework
-- OpenGLU:             [/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/System/Library/Frameworks/OpenGL.framework][/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/System/Library/Frameworks/OpenGL.framework]
-- Coin3D:              4.0.0 [/usr/local/opt/coin3d/lib/libCoin.dylib] [/usr/local/opt/coin3d/include]
-- Pivy:                
-- SPNAV:               [/usr/local/lib/libspnav.dylib] [/usr/local/include]
-- Matplotlib:          3.4.3
-- Rift:                not enabled (BUILD_VR)
-- Doxygen:             1.9.3
--  Language:           English
--  Coin3D_DOC:         not found
=================================================
Now run 'cmake --build /Users/bernie/CLionProjects/FreeCAD/cmake-build-release' to build FreeCAD
=================================================

-- Configuring done
-- Generating done
-- Build files have been written to: /Users/bernie/CLionProjects/FreeCAD/cmake-build-release

[Finished]
Post Reply