I am trying to embed Python into C++ following this guide here:
https://docs.python.org/3.7/extending/embedding.html
This works very well for an older system-wide Python 2.7 installation. I am now trying to do the same using a particular Anaconda enviroment where I installed a library I want to use.
My hello world example for this is
#include <iostream>
#include <Python.h>
int main(int argc, char* argv[]){
wchar_t *program = Py_DecodeLocale(argv[0], NULL);
Py_SetProgramName(program);
Py_Initialize();
std::cout << "trying to import dolfin" << std::endl;
PyRun_SimpleString("import dolfin");
std::cout << "success?" << std::endl;
Py_Finalize();
return 0;
}
Trying to compile this via
g++ -I/home/peter/anaconda3/envs/fenicsproject/include/python3.7m/ python_from_cpp.cpp -L/home/peter/anaconda3/envs/fenicsproject/lib/python3.7/config-3.7m-x86_64-linux-gnu/ -lpython3.7m
(Note1: The include part works, the other flags are recommended linking flags, see 1.6. in above link) (Note2: I want to compile via mpic++ in the end, but trying to get this going first.)
This gives the output:
lto1: internal compiler error: in lto_tag_to_tree_code, at lto-streamer.h:1005
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-7/README.Bugs> for instructions.
lto-wrapper: fatal error: g++ returned 1 exit status
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
Any help/insights are appreciated.