LinkStage3 assembly3 MAC build

Having trouble installing or compiling FreeCAD? Get help here.
User avatar
dulouie
Posts: 84
Joined: Tue Oct 03, 2017 4:14 pm

LinkStage3 assembly3 MAC build

Postby dulouie » Sat Mar 31, 2018 12:37 pm

Now im able to compile and run realthunders LinkStage3 branch on mac platform.
I followed these https://github.com/FreeCAD/homebrew-freecad instructions for dependencies.
After that, i git clone his LinkStage3 branch. Create out-of-source build directory and run cmake.

Code: Select all

cmake \
  -DCMAKE_BUILD_TYPE=„Release“   \
  -DBUILD_QT5=1                  \
  -DCMAKE_PREFIX_PATH="/usr/local/Cellar/qt/5.10.1/lib/cmake"  \
  -DFREECAD_USE_EXTERNAL_KDL=1   \
  -DBUILD_FEM_NETGEN=1           \
  -DFREECAD_CREATE_MAC_APP=1     \
  -DCMAKE_INSTALL_PREFIX="./.."  \
  ../../FreeCADLink/
Then i can compile and run it. The next step is assembly3 workbench described here https://github.com/realthunder/FreeCAD_ ... nstruction

I compile solvespace bindings successfully with a modified CMakeLists.txt:

Code: Select all

# NOTE TO PACKAGERS: The embedded git commit hash is critical for rapid bug triage when the builds
# can come from a variety of sources. If you are mirroring the sources or otherwise build when
# the .git directory is not present, please comment the following line:
#include(GetGitCommitHash)
# and instead uncomment the following, adding the complete git hash of the checkout you are using:
 set(GIT_COMMIT_HASH 665f4a65a3bc57abc13335c787bf5033394baa42)
Then i copy slvs.py and _slvs.so from asm3/slvs/build/src/swig/python/CMakeFiles to asm3/py_slvs.
And now when i try to run FreeCAD:

Code: Select all

Fatal Python error: PyThreadState_Get: no current thread
Abort trap: 6
When i remove these two files, FreeCAD runs properly. On the other hand i can compile and run solvespace standalone without any issue.
realthunder
Posts: 1715
Joined: Tue Jan 03, 2017 10:55 am

Re: LinkStage3 assembly3 MAC build

Postby realthunder » Sat Mar 31, 2018 1:29 pm

The error may indicate you are using the wrong version of python. You may need to change the python finding code in slvs cmake.
Try Assembly3 (latest version 0.11) along with my custom build of FreeCAD at here.
And if you'd like to show your support, you can donate through patreon, liberapay, or paypal
User avatar
dulouie
Posts: 84
Joined: Tue Oct 03, 2017 4:14 pm

Re: LinkStage3 assembly3 MAC build

Postby dulouie » Sun Apr 01, 2018 11:28 am

Yeah it works! There are two version of python2.7 when you have brew python installed.

This slvs cmake works for me :

Code: Select all

cmake \
-DBUILD_PYTHON=1 \
-DPYTHON_EXECUTABLE:FILEPATH=/usr/local/bin/python2 \
-DPYTHON_INCLUDE_DIR=/usr/local/Frameworks/Python.framework/Headers/ \
-DPYTHON_LIBRARY=/usr/local/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib  \
-DPython_FRAMEWORKS=/usr/local/Frameworks/Python.framework ..
User avatar
dulouie
Posts: 84
Joined: Tue Oct 03, 2017 4:14 pm

Re: LinkStage3 assembly3 MAC build

Postby dulouie » Wed Apr 04, 2018 6:55 pm

Unfortunately this works just only in the out-of-source build directory. I can run ./bin/FreeCAD and the solver works.
If i create a mac.app bundle, it doesn't work.

I tried to compile slvs with different python path and librarys, but no success.
So i checked the python version bundled with freecad decribed in the following MacAppBundle cmake_install.cmake file form build directory:

Code: Select all

/usr/local/Cellar/cmake/3.11.0/bin/cmake -E copy_directory /usr/local/opt/python@2/Frameworks/Python.framework/Versions/Current/lib/python2.7 /Users/arne/src/build/FreeCAD.app/Contents/lib/python2.7
set slvs to this:

Code: Select all

cmake \
-DBUILD_PYTHON=1 \
-DPYTHON_EXECUTABLE:FILEPATH=/usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/bin/python2.7 \
-DPYTHON_INCLUDE_DIR=/usr/local/opt/python@2/Frameworks/Python.framework/Headers/ \
-DPYTHON_LIBRARY=/usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib  \
-DPython_FRAMEWORKS=/usr/local/opt/python@2/Frameworks/Python.framework/ ..
build it:

Code: Select all

-- The CXX compiler identification is AppleClang 9.1.0.9020039
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenGL: /System/Library/Frameworks/OpenGL.framework   
-- Using in-tree libdxfrw
-- Found ZLIB: /usr/lib/libz.dylib (found version "1.2.11") 
-- Found PNG: /usr/local/lib/libpng.dylib (found version "1.6.34") 
-- Found Freetype: /usr/local/lib/libfreetype.dylib (found version "2.9.0") 
-- Found SWIG: /usr/local/bin/swig (found version "3.0.12") 
-- Found PythonInterp: /usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/bin/python2.7 (found version "2.7.14") 
-- python version 2.7
-- Found PythonLibs: /usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib (found suitable exact version "2.7.14") 
-- Configuring done
-- Generating done
and move the asm3 with python bindings py_slvs directory inside FreeCAD.app
If i start the FreeCAD.app

Code: Select all

Fatal Python error: PyThreadState_Get: no current thread
Abort trap: 6
python version is 2.7.14 in freecad and slvs. I'm new to cmake so if there are special cmake settings please tell me.
peterl94
Posts: 1001
Joined: Thu May 23, 2013 7:31 pm
Location: United States

Re: LinkStage3 assembly3 MAC build

Postby peterl94 » Wed Apr 04, 2018 11:04 pm

Does the app start if you don't "move the asm3 with python bindings py_slvs directory inside FreeCAD.app"?
realthunder
Posts: 1715
Joined: Tue Jan 03, 2017 10:55 am

Re: LinkStage3 assembly3 MAC build

Postby realthunder » Wed Apr 04, 2018 11:14 pm

I only have limited knowledge of MacOS, only guessing here. If it's an app bundle, then the binary inside may have their rpath changed to look for the dylib inside the bundle only. So you can't simply move something outside into the bundle and expect it to link to the same dylib at runtime. You'll either need to add them as dependents into the project, and then build the bundle, or find a way to change rpath yourself after manually move them into the bundle.
Try Assembly3 (latest version 0.11) along with my custom build of FreeCAD at here.
And if you'd like to show your support, you can donate through patreon, liberapay, or paypal
User avatar
sgrogan
Posts: 5969
Joined: Wed Oct 22, 2014 5:02 pm

Re: LinkStage3 assembly3 MAC build

Postby sgrogan » Wed Apr 04, 2018 11:20 pm

I think a directory structure like

Code: Select all

...\Ext\freecad\asm3
is required
User avatar
dulouie
Posts: 84
Joined: Tue Oct 03, 2017 4:14 pm

Re: LinkStage3 assembly3 MAC build

Postby dulouie » Fri Apr 06, 2018 8:07 am

peterl94 wrote:
Wed Apr 04, 2018 11:04 pm
Does the app start if you don't "move the asm3 with python bindings py_slvs directory inside FreeCAD.app"?
If i remove _slvs.so and slvs.py the App working flawless.
realthunder wrote:
Wed Apr 04, 2018 11:14 pm
You'll either need to add them as dependents into the project, and then build the bundle, or find a way to change rpath yourself after manually move them into the bundle.
I try to figure it out. I'm look to change the rpath or include asm3 and especially slsvs into the freecad cmake build script.
peterl94
Posts: 1001
Joined: Thu May 23, 2013 7:31 pm
Location: United States

Re: LinkStage3 assembly3 MAC build

Postby peterl94 » Fri Apr 06, 2018 4:58 pm

If you copy the library into the bundle before the call to MakeMacBundleRelocatable.py, then it should be taken care of automatically if it is in a standard location (Mod, MacOS, lib, site-packages). See src/MacAppBundle/CMakeLists.txt

Or you can use install_name_tool manually (see man install_name_tool) to make the install paths relative to the bundle.

Also you can use otool -L _slvs.so to check what it is linked to.
realthunder
Posts: 1715
Joined: Tue Jan 03, 2017 10:55 am

Re: LinkStage3 assembly3 MAC build

Postby realthunder » Wed Apr 11, 2018 7:04 am

I have just made slvs working in the bundle. Please sync my asm git master branch if you are using git. Mac binaries will be located at py_slvs_mac. I will be releasing mac builds from now on.

The necessary command to make a dynamic library relocatable is as follow.

First, set bundle id. I am not sure if this is necessary.

Code: Select all

install_name_tool -id "_slvs.so" _slvs.so

Second, set loader rpath. This will be a string of format @loader_path/<relative_path_from_your_library_to_bundle_lib_path>

Code: Select all

install_name_tool -add_rpath "@loader_path/../../../../lib/" _slvs.so

Use the following command to obtain the absolute library path, assuming those libraries are already in the bundle

Code: Select all

otool -L _slvs.so
It outputs,

Code: Select all

_slvs.so:
       /usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.0)
...

Finally, change the absolute path(es) to the corresponding library in the bundle. This will be a string of format @rpath/<path_to_bundled_library>. Now this is where I am not sure. I guess the <path_to_bundled_library> must be relative to the loader. And since the loader is at the same directory as the Python library, the following command works.

Code: Select all

install_name_tool -change " /usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/Python" "@rpath/Python" _slvs.so
Try Assembly3 (latest version 0.11) along with my custom build of FreeCAD at here.
And if you'd like to show your support, you can donate through patreon, liberapay, or paypal