Click here to Skip to main content
12,547,321 members (58,913 online)
Rate this:
Please Sign up or sign in to vote.
See more: VC6 C++ Python

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

    return 0;
Posted 13-Nov-12 8:36am
Rate this: bad
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?
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.
Rate this: bad
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
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.161018.1 | Last Updated 13 Nov 2012
Copyright © CodeProject, 1999-2016
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