Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/154.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 程序入口点uu gxx u个性u v0找不到libstdc++-6.dll_Python_C++_C_Ctypes - Fatal编程技术网

Python 程序入口点uu gxx u个性u v0找不到libstdc++-6.dll

Python 程序入口点uu gxx u个性u v0找不到libstdc++-6.dll,python,c++,c,ctypes,Python,C++,C,Ctypes,感谢这个问题已经被问到并回答了好几个案例,但我仍然有问题。我的目录结构如下所示: models/ bs/ __init__.py values.py optlib/ Makefile bin/ optlib.so # generated after compilation/linking libstdc++-6.dll inc/

感谢这个问题已经被问到并回答了好几个案例,但我仍然有问题。我的目录结构如下所示:

models/
    bs/
        __init__.py
        values.py
    optlib/
        Makefile
        bin/
            optlib.so       # generated after compilation/linking
            libstdc++-6.dll
        inc/
            optlib.h
            stats.h
        obj/
            optlib.o        # generated after compilation/linking
            stats.o         # generated after compilation/linking
        src/
            optlib.cc
            stats.cc
简而言之,我的源文件在
src
中,头文件在
inc
中,目标文件输出到
obj
,共享库文件输出到
bin

我使用以下命令编译并链接了C/C++库(从
Makefile
中提取):

我正在Windows7机器上使用MinGW,并试图使用
ctypes
从Python访问共享库。我已将
C:\MinGW\bin
中的
libstdc++-6.dll
文件放入
bin
目录,该目录包含共享库
optlib。因此,正如许多帖子所建议的那样

我的Python代码如下所示(注意
\uuu init\uu.py
imports
values.py
):

我得到以下错误:

C:\MinGW\bin
位于我的
PATH
变量上。源代码实际上是
C++
包装在
extern“C”
中,以便
ctypes
可以看到它。这些都是非常简单的
C++
函数。如果你需要查看源代码,我可以发布


那么问题有两个。首先,我如何解决眼前的问题。其次,是否有可能简化编译和链接过程,使其不受系统影响(即在Mac OSX和Linux上编译和链接)?

侵入性最小、线程安全性最高的选项是调用
kernel32=windell('kernel32')
kernel32.LoadLibraryExW.restype=c\u void\u p
hMod=kernel32.LoadLibraryExW(绝对路径到optlib,无,加载路径已更改)
。然后包装加载的模块引用,例如
lib=CDLL('optlib.so',handle=hMod)
。仅供参考,它应该是
lib.c\u func.argtypes=[c\u double]
。该属性为
argtypes
,末尾为“s”。但是,您的呼叫是错误的,因为您将类型指定为
double
,但通过
byref
传递了
double*
。为此,将对其进行快照和报告。这并没有解决问题,我仍然收到弹出错误。C函数的参数定义为
constdouble&x
。这将在与共享库相同的目录中解决此问题。但是,在尝试导入模块时,我收到了相同的错误。
g++ -c -Iinc -o obj/optlib.o src/optlib.cc
g++ -c -Iinc -o obj/stats.o src/stats.cc

g++ -shared -Wl,-soname,bin/optlib.so -o bin/optlib.so obj/optlib.o obj/stats.o
# neither the os.path.abspath method of building the path works...
fn = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'optlib', 'bin', 'optlib.so'))
print type(fn) # returns <type 'unicode'>
# or actually implicitly typing it out
#fn= u'C:\\Users\\striji\\Desktop\\models\\optlib\\bin\\optlib.so'
LOAD_WITH_ALTERED_SEARCH_PATH=0x00000008
kernel32 = WinDLL('kernel32')
kernel32.LoadLibraryExW.restype = c_void_p
hMod = kernel32.LoadLibraryExW(fn, None, LOAD_WITH_ALTERED_SEARCH_PATH)
lib = CDLL(fn, handle=hMod)

def fcn(x):
    lib.c_func.argtypes = [c_double]
    lib.c_func.restype = c_double
    x = byref(c_double(x))
    return lib.c_func(x)
>>> from models import bs