0

I am getting a linking error in my Visual Studio C project. Those are related to external functions of C-Python API not being resolved in the linking stage. One of them being: unresolved external symbol __ipm_Py_Finalize referenced in function _main I Have Added the library folder of Python in the Linker Additional Library Directory and added include folder in C/C++ Additional Include Directory. Here is my C code:

#include <stdio.h>
#include <stdbool.h>

#include <Python.h>

int main() {
    Py_Initialze();
    printf("Initialized python interpreter!");
    PyObject* module = PyImport_ImportModule("CPBridger");
    if (module == NULL) {
        printf("Can't find module!");
        return -1;
    }

    PyObject* func = PyObject_GetAttrString(module, "helloWorld");
    PyObject* args = PyTuple_Pack(0);
    PyObject_CallObject(func, args);

    Py_XDECREF(func);
    Py_XDECREF(args);

    func = PyObject_GetAttrString(module, "sayHelloTo");
    args = PyTuple_Pack(1, PyString_FromString("LakshyaK2011"));
    PyObject_CallObject(func, args);

    Py_XDECREF(func);
    Py_XDECREF(args);
    Py_XDECREF(module);

    Py_Finalize();
    printf("Finalized python interpreter!");
}

What shall I configure in VS to make it resolve the external references?

5
  • Are you sure you have python.h in your C++ path as with #include <Python.h>? Perhaps you can provide its address like #include "address/of/Python.h" Commented Jan 14, 2024 at 5:37
  • I have included python include, compiling is fine, but when Linking, error comes up! Note: Its C actually, not C++ Commented Jan 14, 2024 at 5:51
  • If there is the DLL file available, make its address available to the linker as well. Commented Jan 14, 2024 at 5:59
  • It is not enough to add a library folder, you need to specify which libraries to use. Commented Jan 14, 2024 at 6:27
  • 1
    [SO]: How to create a Minimal, Reproducible Example (reprex (mcve)). Please add link command and its (full) output. You also need to add python3*.lib in the dependencies section. [SO]: How to include OpenSSL in Visual Studio (@CristiFati's answer) contains an example for OpenSSL. Commented Feb 7, 2024 at 21:52

1 Answer 1

0

Okay so in this secnario, I haven't included python3.lib, Simple fix to this is to iinclude python3.lib in the Linker.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.