Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post Amitesh's Mac build fix #9

Open
dsteinberg opened this issue Mar 1, 2018 · 0 comments
Open

Post Amitesh's Mac build fix #9

dsteinberg opened this issue Mar 1, 2018 · 0 comments

Comments

@dsteinberg
Copy link
Owner

To solve the libclusterpy.dylib vs libclusterpy.so issue I found this code snippet which I included in the CMakeLists.txt just after 'library build instructions'. 

if(APPLE)
  set(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
endif(APPLE)

This forced the creation of libclusterpy.so, which python3 was able recognise.

 
Here are the details of the steps I had to take. I am hoping that you can distill some of this information and add to your installation instruction for OSX users. 

1. Installing LLVM (non-Apple): execute: 'brew install --with-toolchain llvm' (comes with clang, check successful installation by executing 'clang --version' or 'which clang')
2. brew install eigen
3. brew install boost

### python3 and numpy
4. brew install python3 
5. pip3 install --upgrade pip setuptools wheels
6. pip3 install numpy
7. brew install boost-python3

### openmp installation
8. cd /Users/me/
9. svn co http://llvm.org/svn/llvm-project/openmp/trunk openmp
10. cd /Users/me/openmp/
11. mkdir build && cd build
12. brew install cmake
12a. cmake path/to/openmp -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
13. make

### editing paths in the .bash_profile for openmp
The dir location for openmp library and header file: '/Users/me/openmp/build/runtime/src' contains both the header file omp.h and libomp.dylib (libomp.so in linux)
13a. Add the following to your .bash_profile:
export DYLD_LIBRARY_PATH="/Users/me/openmp/build/runtime/src"
export LIBRARY_PATH="/Users/me/openmp/build/runtime/src"
export C_INCLUDE_PATH="/Users/me/openmp/build/runtime/src"
export CPLUS_INCLUDE_PATH="/Users/me/openmp/build/runtime/src"
export DYLD_LIBRARY_PATH="/opt/intel/mkl/lib:$DYLD_LIBRARY_PATH"
export DYLD_LIBRARY_PATH="/opt/intel/compilers_and_libraries_2017.*.***/mac/mkl/lib:$DYLD_LIBRARY_PATH"

export PATH="/usr/local/opt/llvm/bin:$PATH"
export PATH="/usr/local/opt/llvm/bin:$PATH"
export PATH="/usr/local/opt/eigen/include/eigen3/:$PATH"
export PATH="/usr/local/opt/llvm/bin:$PATH"
export PATH="/Users/me/openmp/build/runtime/src/:$PATH"

### check installation of OpenMP by compiling hello.c code below using 'clang -fopenmp hello.c -o hello'
#include <omp.h>
#include <stdio.h>
int main() {
#pragma omp parallel
printf("Hello from thread %d, nthreads %d\n", omp_get_thread_num(), omp_get_num_threads());
}

and running ./hello. Should produce no errors.

### Installing libcluster 
14. mkdir build
15. cd build
15a. Makes sure that the following lines of code are present in the CMakeLists.txt

if(APPLE)
  set(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
endif(APPLE)

16. cmake .. -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DUSE_WERROR=ON (the extra flags are different from Linux installation and were needed for openmp)

Should proceed with the following message
----------
----------
-- Found OpenMP_CXX: -fopenmp=libomp
-- Found OpenMP: TRUE
-- Configuring done
----------
----------

17. make

The following error may arise when anaconda python3.6 and python3 are both present.
----------
----------
python/CMakeFiles/clusterpy.dir/flags.make:10: *** multiple target patterns.  Stop.
make[1]: *** [python/CMakeFiles/clusterpy.dir/all] Error 2
make: *** [all] Error 2
----------

To fix this, comment out the anaconda path from the .bash_profile, restart the terminal, delete the contents of the build directory, do a fresh install starting from step 16. If the same error arrises, uninstall python3 
'brew uninstall python3', then follow the instructions here https://stackoverflow.com/questions/3819449/how-to-uninstall-python-2-7-on-a-mac-os-x-10-6-4/3819829#3819829. Remove python3 and python@3 directories from /usr/local/opt and /usr/local/Cellar/. Do a fresh install 'brew install python3', delete the contents of the build directory, do a fresh install starting from step 16.

18. sudo make install

### python interface
19. ccmake. 
set the 'buiild_python_interface' and 'build_use_python3' to ON
and 'eigen_include_dirs' to '/usr/local/opt/eigen/include/eigen3' (or the path to eigen3 )
press [c], [e], and [q]

20. cmake .. -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DUSE_WERROR=ON -BUILD_PYTHON_INTERFACE=ON -BUILD_USE_PYTHON3=ON (note extra flags)
21. make
22. sudo make install

should see the following libcluster.so in the following locations
-- Install configuration: "Release"
-- Installing: /usr/local/lib/libcluster.so
-- Up-to-date: /usr/local/include/libcluster/libcluster.h
-- Up-to-date: /usr/local/include/libcluster/probutils.h
-- Up-to-date: /usr/local/include/libcluster/distributions.h
-- Installing: /usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/libclusterpy.so

to check dependencies of libclusterpy.so 
execute: otool -L /usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/libclusterpy.so

should see no paths pointing to anaconda lib, something similar to:

libclusterpy.so (compatibility version 0.0.0, current version 0.0.0)
	/usr/local/opt/boost-python3/lib/libboost_python3.dylib (compatibility version 0.0.0, current version 0.0.0)
	/usr/local/opt/python3/Frameworks/Python.framework/Versions/3.6/Python (compatibility version 3.6.0, current version 3.6.0)
	/usr/local/opt/boost-python3/lib/libboost_python3-mt.dylib (compatibility version 0.0.0, current version 0.0.0)
	libcluster.so (compatibility version 0.0.0, current version 0.0.0)
	@rpath/libomp.dylib (compatibility version 5.0.0, current version 5.0.0)
	/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 307.5.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.60.2)
23. run python3
24. import libclusterpy
should proceed with no errors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant