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.

Can
  • 8,502
  • 48
  • 57
gbh
  • 173
  • 1
  • 1
  • 5
  • Uh... did you try linking? – Ignacio Vazquez-Abrams Sep 13 '13 at 05:46
  • It is a linking issue you can read the already asked question http://stackoverflow.com/questions/658879/linking-to-python-import-library-in-visual-studio-2005 – AurA Sep 13 '13 at 05:47
  • also add Python to your include path instead of using absolute path – Loïc Faure-Lacroix Sep 13 '13 at 05: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. – gbh Sep 13 '13 at 05:50

2 Answers2

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>
Pierre Fourgeaud
  • 14,290
  • 1
  • 38
  • 62
0

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

Hennaldo
  • 155
  • 6