Thread: Embedding Python - Link error

  1. #1
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709

    Embedding Python - Link error

    I'm following The Code Project's tutorial on embedding Python and it's all going well until I start to make function visible to the interpreter. Like:

    Code:
    #include <iostream>
    #include <py/python.h>
    
    static int g_iNumArgs = 0;
    
    static PyObject* emb_NumArgs(PyObject* poSelf, PyObject* poArgs)
    {
        if (! PyArg_ParseTuple(poArgs, ":g_iNumArgs"))
            return 0;
    
        return Py_BuildValue("i", g_iNumArgs);
    }
    
    static PyMethodDef EmbMethods[] = {
        {"NumArgs", emb_NumArgs, METH_VARARGS,
            "Return the number of arguments received by the process."},
        {0, 0, 0, 0}
    };
    
    int main(int argc, char* argv[])
    {
        Py_Initialize();
    
        g_iNumArgs = argc;
        Py_InitModule("emb", EmbMethods);
    
        Py_Finalize();
        return 0;
    }
    I get the link error:

    Code:
    PyEmbed.obj : error LNK2019: unresolved external symbol __imp__Py_InitModule4TraceRefs referenced in function _main
    I'm linking python24.lib and I've tried all the others that come with the installation but nothing is working. Can anyone help?

    EDIT: Oh... yeah I didn't have python24_d.lib (apparently it doesn't come with the installation) so I just made a copy of python24.lib and renamed it... like an idiot. I just ran a Release and it works fine.

    Off hunting for the _d version.

    EDIT2: Well that's not happening (getting hold of it) so I'll just #undef _DEBUG. I don't like it though...
    Last edited by cboard_member; 06-09-2006 at 10:45 AM.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  3. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 12:17 AM
  4. DX - CreateDevice - D3DERR_INVALIDCALL
    By Tonto in forum Game Programming
    Replies: 3
    Last Post: 12-01-2006, 07:17 PM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM