I have this prog.cpp
program:
#include <iostream>
using namespace std;
int main(int argc, char** argv){
printf("hello world\n");
return 0;
}
And I have this prog.py
program that should load main
into a python function:
import subprocess
import numpy.ctypeslib as npct
subprocess.call(['gcc', '-Wall','-c', '-fPIC', 'prog.cpp', '-o', 'prog.o'])
subprocess.call(['gcc', 'prog.o', '-shared', '-o', 'lib_prog.so'])
lib = npct.load_library('lib_prog', '.')
fun = getattr(lib,'main')
fun()
But I'm getting the following error:
Traceback (most recent call last):
File "prog.py", line 7, in <module>
lib = npct.load_library('lib_prog', '.')
(...)
OSError: /my_dir/lib_prog.so: undefined symbol: _ZSt4cout
My program seems identical to any example on how to use numpy.ctypeslib.load_library
. Would someone have any insights on what is going on?
Thanks in advance.