this is my test.cpp file.(I also used makefile to create dll file)
JavaScript
x
10
10
1
//#include <iostream>
2
3
int foo(int a)
4
{
5
if (a > 1)
6
return a + 1;
7
else
8
return a + 2;
9
}
10
when I run following code in python
JavaScript
1
6
1
import os
2
import ctypes
3
4
lib_bfs = ctypes.WinDLL("D:\advanced_programming\HW7\cpp_part\libtest.dll")
5
print(lib_bfs)
6
everything is ok and I get this output from python.
JavaScript
1
2
1
<CDLL 'D:advanced_programmingHW7cpp_partlibtest.dll', handle 69d00000 at 0x2b7677e6400>
2
but when I change my test.cpp in this way(I just uncommented iostream):
JavaScript
1
11
11
1
#include <iostream>
2
3
int foo(int a)
4
{
5
if (a > 1)
6
return a + 1;
7
else
8
return a + 2;
9
}
10
11
I get the following error from python.
JavaScript
1
7
1
Traceback (most recent call last):
2
File "d:/advanced_programming/HW7/cpp_part/connector.py", line 4, in <module>
3
lib_bfs = ctypes.WinDLL("D:\advanced_programming\HW7\cpp_part\libtest.dll")
4
File "c:usersaliappdatalocalprogramspythonpython38libctypes__init__.py", line 373, in __init__
5
self._handle = _dlopen(self._name, mode)
6
FileNotFoundError: Could not find module 'D:advanced_programmingHW7cpp_partlibtest.dll' (or one of its dependencies). Try using the full path with constructor syntax.
7
this is also my dependencies enter image description here
by the way I have to mention that when I use Linux, everything is just fine.(I just used .so files) but there might be some problem with windows
I appreciate your help.
Advertisement
Answer
thanks to @DhirajWishal first I added the following line in my makefile.
JavaScript
1
2
1
g++ -std=c++17 -O3 -I./h -g -fPIC -shared ./cpp/test.cpp -o ./libtest.dll -static-libgcc -static-libstdc++
2
then I placed libwindpthread-1.dll
(which was in F:/strawberry/c/bin/
dir ) next to my makefile and the problem was solved.