我试图在Mac OS X上构建llvm-py。
这是我尝试做的,我需要下载11vm-2.7,而README文件有这样的评论:确保'--enable-pic'传递给LLVM的'configure'
./configure --prefix=LLVM_DIRECTORY --enable-pic
python setup.py build --llvm-config=LLVM_DIRECTORY/bin/llvm-config
一切都编译没有错误,但当我尝试运行测试文件时,我收到此错误消息。
ImportError: 'dlopen(/Library/Python/2.7/site-packages/llvm/_core.so, 2): Symbol not found: __ZTVN4llvm16ExtractValueInstE\n Referenced from: /Library/Python/2.7/site-packages/llvm/_core.so\n Expected in: flat namespace\n in /Library/Python/2.7/site-packages/llvm/_core.so'
消息错误似乎表明缺少具有平面namemspace问题的函数“llvmExtractValueInst”。这有什么问题?
在llvm 2.7中,Makefile.rules有这一行
SharedLinkOptions=-Wl,-flat_namespace -Wl,-undefined -Wl,suppress \
-dynamiclib
我尝试删除flat_namespace
,但我收到了编译错误。
按照locojay的回答,我可以建立brew和llvmpy。
export REQUIRES_RTTI=1
brew install llvm --rtti
sudo pip install git+https://github.com/llvmpy/llvmpy
但是,当我尝试在test目录中执行示例时,我仍然遇到了不同类型的错误 -
test> python example.py
Traceback (most recent call last):
File "example.py", line 4, in <module>
from llvm import *
File "/Library/Python/2.7/site-packages/llvm/__init__.py", line 11, in <module>
from llvm import _core
ImportError: dlopen(/Library/Python/2.7/site-packages/llvm/_core.so, 2): Symbol not found: __ZN4llvm10DataLayout2IDE
Referenced from: /Library/Python/2.7/site-packages/llvm/_core.so
Expected in: flat namespace
in /Library/Python/2.7/site-packages/llvm/_core.so
这是我运行otool -L /Library/Python/2.7/site-packages/llvm/_core.so
/Library/Python/2.7/site-packages/llvm/_core.so:
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 52.0.0)
答案 0 :(得分:4)
看看llvmpy的@ docs
对于LLVM 3.2,请确保环境变量REQUIRES_RTTI = 1 在运行make时定义。否则,您可能会看到“未定义的符号: _ZTIN4llvm24PassRegistrationListenerE“。有关详细信息,请参阅http://llvm.org/docs/Packaging.html#c-features。
所以对我来说这很有用
export REQUIRES_RTTI=1
brew install llvm --rtti
pip install git+https://github.com/llvmpy/llvmpy
我想在最糟糕的情况下,我总能给anaconda一个尝试....
答案 1 :(得分:1)
这就是我的工作方式。
export REQUIRES_RTTI=1
brew install llvm --enable-shared --with-clang --with-asan --rtti --enable-jit
git clone https://github.com/llvmpy/llvmpy.git
LLVM_CONFIG_PATH=/usr/local/opt/llvm/bin/llvm-config python setup.py install
python -c 'import llvm; llvm.test()'
它在OS X Mavericks下的llvm 3.3下工作。
test_scalar_type (llvm.tests.test_type_hash.TestTypeHash) ... ok
test_struct_type (llvm.tests.test_type_hash.TestTypeHash) ... ok
test_uses (llvm.tests.test_uses.TestUses) ... ok
test_volatile (llvm.tests.test_volatile.TestVolatile) ... ok
test_volatile_another (llvm.tests.test_volatile.TestVolatile) ... ok
----------------------------------------------------------------------
Ran 75 tests in 0.249s
OK (skipped=4)
-------------------------------run isolated tests-------------------------------
testing llvm.tests.test_intel_native_asm
.
----------------------------------------------------------------------
Ran 1 test in 0.008s
OK
我也试过了kaleidoscope,似乎工作正常:
$ python kaleidoscope.py
ready> 3+5
Evaluated to: 8.0
ready> 1-34-5
Evaluated to: -38.0
ready>
在/Library/Python/2.7/site-packages/llvmpy/capsule.py
第114行进行了一次修改。我不确定这是否有害,但它适用于此更改。
def release_ownership(old):
logger.debug('Release %s', old)
addr = getPointer(old)
name = getName(old)
if _addr2dtor.get((name, addr)) is None:
clsname = getClassName(old)
if not _pyclasses[clsname]._has_dtor():
return
# Guard duplicated release <-- raises an error
return
raise Exception("Already released")
_addr2dtor[(name, addr)] = None