我创建了一个python扩展,它在Linux中正常工作,但在os x中不工作。
C代码使用openmp库。
在os x中预装的C编译器是clang,预安装的python是用clang构建的。那种嘎嘎声不支持开胃。
通过安装gcc-6,我可以编译和运行代码:
brew install gcc我可以通过在文件setup.py中包含环境变量CC来构建我的libary:
os.environ["CC"]="/usr/local/Cellar/gcc/6.2.0/bin/gcc-6"我在设置配置中包括gcc库路径:
library_dirs = ["/usr/local/Cellar/gcc/6.2.0/lib/gcc/6/","../build/"],但是,当我从python加载库时,我获得了错误:
import myLibraryNamedlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/LIBIRWLS.so,2):符号未找到:___emutls_get_address引用自:/usr/local/___emutls_get_address/gcc/lib/6/libgomp.1.dylib预期在: /usr/lib/libSystem.B.dylib中/usr/local/opt/lib//6/libgomp.1.dylib。
我该怎么办?在OS中创建使用openmp库的python扩展的正确过程是什么?
发布于 2016-11-02 20:50:16
我知道我已经解决了这个问题。这是我正在做的项目:
https://github.com/RobeDM/LIBIRWLS
简历:
1-我安装了gcc6
brew install gcc2-然后我在文件setup.py中的环境变量中声明了gcc的路径:
os.environ["CC"]=/usr/local/Cellar/gcc/6.2.0/bin/gcc-63-我把CFLAGS环境变量空了:
os.environ["CFLGAS"]=""4-在扩展模块中,我包含了与gcc6关联的文件libgomp.a,并使用了额外的ling arg“静态”:
ext_modules = [
Extension('LIBIRWLS',
include_dirs=['.','../include/',np.get_include()],
sources = ['myexample.c'],
extra_objects = ["/usr/local/Cellar/gcc/6.2.0/lib/gcc/6/libgomp.a",
....Object files of my library
],
library_dirs = ["../build/"],
extra_compile_args=['-Wno-cpp','-static','-lgomp','-lblas','-llapack'],
extra_link_args=['-static']
)
]安装程序(名称= 'LIBNAME',version = '1.0',description=“”,install_requires= 'numpy','scipy',url='https://myurl.com',ext_modules = ext_modules )
https://stackoverflow.com/questions/40317813
复制相似问题