Click here to Skip to main content
15,867,939 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

==================================================
C#
#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
Updated 30-Mar-18 15:51pm

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?
 
Share this answer
 
Comments
Qianfei Li 14-Nov-12 12:58pm    
The question is that which library I should add. There are 18 .lib files there~
Richard MacCutchan 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 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 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.
Have you added your "Python.h" to your include path ?
If it still doesn't work, you may show your *.dsp
 
Share this answer
 
v2
Comments
Qianfei Li 14-Nov-12 12:59pm    
Yes, I did. "Python.h" is in Python27/include. Any other suggestions?
Richard MacCutchan 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900