Hi all,
I am currently writing a program in C where I need to embed a python script as it is part of a testbench that will be comparing many implementation of Datalog in various language. Beside the point.
I have been following this documentation (section 5.3) for an example of how to embed a script into C via calling a function. The example uses input arguments to get the information but I will be needing to hardcode the filenames etc so I have the various properties hardcoded into char* etc.
My current implementation boils down to
I am getting the following memory error:
The script is called python_queens.py and resides in the same directory as the executable. I have tried both
and
As I was not sure if the file extension needed to be included. I am quite sure it has to do with the filename I am passing in but I am not sure what I am missing.
Any help would be appreciated.
Cheers
I have since tried this example and also had it seg fault on me. I copied his exact two file and made the following CMake file for it but it still does not work.
Executing via
I am currently writing a program in C where I need to embed a python script as it is part of a testbench that will be comparing many implementation of Datalog in various language. Beside the point.
I have been following this documentation (section 5.3) for an example of how to embed a script into C via calling a function. The example uses input arguments to get the information but I will be needing to hardcode the filenames etc so I have the various properties hardcoded into char* etc.
My current implementation boils down to
Quote://globals
char* python_script_file = "python_queens.py";
//in my run benchmark function
Py_Initialize(); //init python
PyObject *pName, *pModule, *pDict, *pFunc;
PyObject *pArgs, *pValue;
pName = PyString_FromString(python_script_file); //prepare file path
pModule = PyImport_Import(pName); <<< CULPRIT
--** the rest of the implementation is commented out as it crashes on the above line **--
Py_Finalize();
I am getting the following memory error:
Quote: “./TARS” terminated by signal SIGSEGV (Address boundary error)
The script is called python_queens.py and resides in the same directory as the executable. I have tried both
Quote: char* python_script_file = "python_queens.py";
and
Quote: char* python_script_file = "python_queens";
As I was not sure if the file extension needed to be included. I am quite sure it has to do with the filename I am passing in but I am not sure what I am missing.
Any help would be appreciated.
Cheers
I have since tried this example and also had it seg fault on me. I copied his exact two file and made the following CMake file for it but it still does not work.
Quote:project(pythontest)
cmake_minimum_required (VERSION 3.4 FATAL_ERROR)
set(CMAKE_BUILD_TYPE Debug)
#packages
find_package(PythonLibs 2.7 REQUIRED)
set(PYTHON_EXECUTABLE "/usr/bin/python2.7")
set(PYTHON_INCLUDE_DIR "/usr/include/python2.7")
set(PYTHON_LIBRARIES "/usr/lib/x86_64-linux-gnu/libpython2.7.so")
#includes
include_directories(${PYTHON_INCLUDE_DIRS})
#source files
file(GLOB SOURCES "*.c")
add_executable(call_function ${SOURCES})
target_link_libraries(call_function ${PYTHON_LIBRARIES})
Executing via
Quote:./call_function py_function multiply