Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VC6 C++ Python
Hi,
 
I was trying to use Python/C API in VC++. However, I got a error link message when linking the project:
python.obj : error LNK2019: unresolved external symbol __imp__Py_Initialize referenced in function _main
 
I have included the 'python27/include' and 'python27/libs' in C/C++ ->General ->Additional include directories and Linker->general->additional libraries directories.
 
Also, I was using "Debug" mode. Is there any further steps I need to follow?
 
Below is the code. I'd appreciate if anyone could help.
 
==================================================
#include "stdafx.h"
#undef _DEBUG /* Link with python24.lib and not python24_d.lib */
#include "Python.h"
 

int main(int argc, char *argv[])
{
    int i;
    PyObject *pName, *pModule, *pDict, *pFunc, *pArgs, *pValue;
 
    if (argc < 3)
    {
        printf("Usage: exe_name python_source function_name\n");
        return 1;
    }
 
    // Initialize the Python Interpreter
    Py_Initialize();
 

    return 0;
}
Posted 13-Nov-12 8:36am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The linker is definitely not finding the library that contains the definition of __imp__Py_Initialize. Did you add the library name in Linker->Input?
  Permalink  
Comments
Qianfei Li at 14-Nov-12 12:58pm
   
The question is that which library I should add. There are 18 .lib files there~
Richard MacCutchan at 14-Nov-12 13:07pm
   
The ones that are required by your program! I have no idea which that might be, I suggest checking the documentation.
Qianfei Li at 14-Nov-12 16:42pm
   
The documentation only says "To include the headers, place the directories (if different) on your compiler’s search path for includes." Any idea on that?
Richard MacCutchan at 14-Nov-12 17:34pm
   
This has nothing to do with headers, it is a linker issue. You need to check which libraries contain the various functions or classes that you are trying to use, and add their names into the list in the linker properties of your project, as I mentioned above.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Have you added your "Python.h" to your include path ?
If it still doesn't work, you may show your *.dsp
  Permalink  
v2
Comments
Qianfei Li at 14-Nov-12 12:59pm
   
Yes, I did. "Python.h" is in Python27/include. Any other suggestions?
Richard MacCutchan at 14-Nov-12 13:06pm
   
This is a linker issue, header files are used by the compiler.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Gihan Liyanage 332
1 Sergey Alexandrovich Kryukov 330
2 ClimerChinna 222
3 vikinghunter 168
4 OriginalGriff 166
0 Sergey Alexandrovich Kryukov 8,363
1 OriginalGriff 7,112
2 CPallini 2,598
3 Richard MacCutchan 2,025
4 Abhinav S 1,788


Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 13 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100