1

I am trying to interface python with C++. I am using Visual Studio Express 2012. I also have an enthought python 2.7 distribution. When I tried to build a Release on Win 32 with the following code:

#include "stdafx.h"
#include "C:/Python27/include/Python.h"
#include "C:/Python27/Lib/site-packages/numpy/core/include/numpy/arrayobject.h"

using namespace std;


int main( int argc, char* argv[] )
{  
   int x = 1;
   PyObject *mod1;
   Py_Initialize();
   return 0;
}

I get the following error:

Error   1   error LNK2001: unresolved external symbol __imp__Py_Initialize

Please help, any ideas more than welcome.

4
  • Uh... did you try linking? Commented Sep 13, 2013 at 5:46
  • It is a linking issue you can read the already asked question stackoverflow.com/questions/658879/… Commented Sep 13, 2013 at 5:47
  • also add Python to your include path instead of using absolute path Commented Sep 13, 2013 at 5:47
  • Sorry I am at a loss as to how you mean, I am trying to build it, which automatically links it. I just cant build it due to those errors. I also tried to go through that post but wasnt clear. I apologize if I am being clumsy, but please let me know how to fix that error to build my application. Thanks. Commented Sep 13, 2013 at 5:50

2 Answers 2

1

You should add C:\Python27\libs to your library paths and add python27.lib to your dependencies.

For that:

Go to project properties -> Configuration properties -> Linker.
Go to ->General and set the "Additional Library directories"

In this field you add C:\Python27\libs.

After that:

Go to Linker -> Input and set the "Additional Dependencies"

In this field you add python27.lib.

Also you should add C:\Python27\include to your include directories and just do:

#include <Python.h>
Sign up to request clarification or add additional context in comments.

1 Comment

I did the above and also changed to 64 bit and solved my problem. Many thanks.
0

I think you try to link a 64 Bit python library to a 32-Bit Application

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.