我尝试在python中运行v8(google javascript引擎)。尝试执行此示例https://developers.google.com/v8/get_started:
setup.py
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
from Cython.Distutils import build_ext
import os
from distutils.sysconfig import get_config_vars
(opt,) = get_config_vars('OPT')
os.environ['OPT'] = " ".join(
flag for flag in opt.split() if flag != '-Wstrict-prototypes'
)
setup(
name = 'helloworld',
ext_modules = cythonize(
Extension(
"helloworld",
["helloworld.pyx"],
language = "c++",
libraries = ["v8"],
library_dirs = ["v8"],
include_dirs = ["v8/include"],
extra_compile_args = ["-std=c++11"],
extra_link_args = ["-std=c++11"],
cmdclass = {'build_ext': build_ext}
)
)
)
helloworld.pyx
from libcpp cimport bool
cdef extern from "v8.h":
cdef bool c_initx "v8::V8::InitializeICU"()
cdef class Script:
def test(self):
c_initx()
return "wow"
编译过程没问题,但我无法导入helloworld:
Traceback (most recent call last):
File "test.py", line 1, in <module>
import helloworld
ImportError: /opt/cython/helloworld.so: undefined symbol: _ZN2v82V813InitializeICUEPKc
我使用github https://github.com/v8/v8
中的最新v8版本