3

I would like to embed python into my C++ code. In C++ I am constructing a matrix and vector and would like to use Python's Numpy to solve the linear system. In order to build up to this: I am following this example: http://realgonegeek.blogspot.com/2013/08/how-to-pass-c-array-to-python-solution.html

however this particular line: import_array ();
is not working with my code. I am getting the following error:

1678:144: error: return-statement with no value, in function returning 'int' [-fpermissive] #define import_array() {if (_import_array() < 0) {PyErr_Print(); PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import"); return NUMPY_IMPORT_ARRAY_RETVAL; } }

Has anyone successfully embedded python code into their C++ code? or may know why that particular line may not work. I am using python 3.4

3
  • 1
    Your link clearly says it works for Python 3.3. Python 3.3 is very different from Python 2.7. Thus it is not surprising that the code doesn't work. Commented Jun 10, 2014 at 5:33
  • just updated. still gives me errors. Commented Jun 10, 2014 at 5:49
  • Did you manage to work this out? I have the same error... Commented Feb 4, 2016 at 17:27

1 Answer 1

0

one of the suggestions for that: if your matrix, vector, or array is static, you can set an argument for the c file just like this:

program.exe -array "[[2,2],[3,3],[4,4]]"

and use strtok or substr in c/c++ for splitting the string.

or if your program dynamically uses a new matrix/vector/array you can save it to a temp file or memory(C/C++) and if all above couldn't solve your problem you may finally re-write that part of the code in C++ language.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.