CPP calling Python, undefined references (Raspberry Pi)

Home / Uncategorized / CPP calling Python, undefined references (Raspberry Pi)

Question:
I am trying to call a python script from my cpp script using the below programs, however the cpp script will not compile saying that there is an undefined reference to Py_Initialize and PyRun_SimpleString.

What do I need to do to fix the makefile?

(Cpp 11, python 2.7)

Cpp:#include
#include
#include
#include
#include

using namespace std;

int main()
{
Py_Initialize();
while(1)
{
PyRun_SimpleString("print ‘a’");
usleep(1000);
}
Py_Finalize();
return 0;
}

My Makefile is:all: myserver

myserver: myserver.o
g++ myserver.o -o myserver

myserver.o: myserver.cpp
g++ -c myserver.cpp -std=c++11 -I/usr/include/python2.7 -lpython2.7 -L/usr/lib/python2.7/config/

clean:rm -rf *o myserver

This seemed to work, not a good solution though:all: myserver

myserver:g++ myserver.cpp -std=c++11 -I/usr/include/python2.7 -lpython2.7 -L/usr/lib/python2.7/config/ -o myserver

clean:rm -rf *o myserver


Answer:

Read more

Leave a Reply

Your email address will not be published. Required fields are marked *