Compile C++ with OpenMP on Mac OSX with dynamic linking -
summary
how compile c++ code openmp on mac osx in portable manner?
there many sources suggest solutions compiling c++ openmp on osx, e.g.:
most of them suggest install more recent llvm/clang (or gcc) instead of default clang. on osx 10.12.6 (sierra), using llvm (via brew install llvm) works me.
however, resulting binary not seem portable. if possible, want provide binary users don't have compile on own.
here tried
running otool -l my_binary yields
/usr/local/opt/llvm/lib/libomp.dylib (compatibility version 5.0.0, current version 5.0.0) /usr/local/opt/llvm/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0) /usr/lib/libsystem.b.dylib (compatibility version 1.0.0, current version 1238.0.0) /usr/lib/libc++abi.dylib (compatibility version 1.0.0, current version 307.2.0) the first 2 lines not hand binary user , expect work. user have install llvm first.
so, found install_name_tool able change that. see https://blogs.oracle.com/dipol/dynamic-libraries,-rpath,-and-mac-os
thus, ran
cp /usr/local/opt/llvm/lib/libomp.dylib . cp /usr/local/opt/llvm/lib/libc++.1.dylib . install_name_tool -change /usr/local/opt/llvm/lib/libomp.dylib @executable_path/libomp.dylib my_binary install_name_tool -change /usr/local/opt/llvm/lib/libc++.1.dylib @executable_path/libc++.1.dylib my_binary install_name_tool -id "@loader_path/libomp.dylib" libomp.dylib install_name_tool -id "@loader_path/libc++.1.dylib" libc++.1.dylib unfortunately, don't have mac test on. so, don't know whether works.
questions
is right way this? somehow feels wrong have modify 2 libraries way... "usual" solution issue?
additional minor issue: cmake not find openmp (using find_package), have hard-code needed flag (-fopenmp=libomp). flag tried cmake, not recognized working. idea why, or how fix this?
Comments
Post a Comment