1

When I follow the instructions from Creating a C++ extension for Python I don't get any errors until I reach the section Convert the C++ project to an extension for Python.

After I go through the steps from this section and attempt to build the solution I stumble on this:

1>------ Build started: Project: CppMain, Configuration: Debug Win32 ------
1>module.cpp
1>   Creating library C:\Users\$andu\Desktop\Cpp4Py\Debug\Cpp4Py.lib and object C:\Users\$andu\Desktop\Cpp4Py\Debug\Cpp4Py.exp
1>module.obj : error LNK2019: unresolved external symbol __imp__PyFloat_FromDouble referenced in function "struct _object * __cdecl tanh(struct _object *,struct _object *)" (?tanh@@YAPAU_object@@PAU1@0@Z)
1>module.obj : error LNK2019: unresolved external symbol __imp__PyFloat_AsDouble referenced in function "struct _object * __cdecl tanh(struct _object *,struct _object *)" (?tanh@@YAPAU_object@@PAU1@0@Z)
1>module.obj : error LNK2019: unresolved external symbol __imp__PyModule_Create2 referenced in function _PyInit_Cpp4Py
1>C:\Python\Anaconda3\libs\python3.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'x86'
1>C:\Users\$andu\Desktop\Cpp4Py\Debug\Cpp4Py.pyd : fatal error LNK1120: 3 unresolved externals
1>Done building project "CppMain.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

From the message above, I suspect that the problem comes from step 2 in that set of instructions. But I don't really know how to deal with that. Any suggestions?


I work with x64 Windows 10.

1 Answer 1

6

I'm not sure. But you can change your project's target machine type to x64 and try again. See this warning:

C:\Python\Anaconda3\libs\python3.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'x86'

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

3 Comments

I should have mentioned I have done that. Unsuccessfully. Have you tried the instructions? Do they work for you?
Actually, how do you do that? The way a I've done it is by choosing x64 Platform from the Solution Properties.
OK, I have also changed the Solution Platform to x64 in the Menu Bar and it worked. My problem is now that pip install . doesn't work. I am not sure I have created the setup.py as I was supposed to do it. There was no Python as prescribes "searching for "Python" and selecting Python file", so I just created a file in that directory and added it to the project.

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.