4

I was trying to integrate Python interpreter in C++ application in Visual Studio 2013, despite of adding INCLUDES and ENV VARIABLES such as LIB & LIBPATH, compilation is throwing an Error as

LINK : fatal error LNK1104: cannot open file 'python37_d.lib'.

I tried all possible google suggestions, but still I am not able get rid of this Error. Any help on this would be highly appreciated.

  • 1
    What are your settings for library path and include path as well as the libraries to link? – The Floating Brain May 25 '20 at 04:20
  • Hi,Settings are as below: Include Path: (Proporties->Configuration Properties->VC++ Directories->Include Directories) C:\Users\Shridhar\AppData\Local\Programs\Python\Python37\include -----> This is where Python37 resides Library Path:(Proporties->Configuration Properties->VC++ Directories->Libraries Directories) C:\Users\Shridhar\AppData\Local\Programs\Python\Python37\libs -----> libraries folder – Shridhar Y Bhandiwad May 25 '20 at 04:43
  • Cool, and what does it say for "additional dependencies?" – The Floating Brain May 25 '20 at 04:47
  • 1
    Here's the obvious question, do you have a file called C:\Users\Shridhar\AppData\Local\Programs\Python\Python37\libs\python37_d.lib? Because your linker is telling you that you don't. – john May 25 '20 at 04:52
  • @john On my machine in the same folder for python 36 I just have python36.lib and python3.lib – The Floating Brain May 25 '20 at 17:11

2 Answers2

7

This library is intended for debugging, and you simply don't have it if the Python was installed with default options. To obtain it, you are to (re)install Python with "Download debug binaries" option enabled in the installer. Then the python37_d.lib will be located in %PythonPath%\Libs together with python3_d.lib.

Suthiro
  • 1,210
  • 1
  • 7
  • 18
  • 1
    I am wondering, how visual studio determined to require this library for compilation, given that I didn't explicit ask for it. – Ziqi Fan Jun 05 '21 at 14:51
  • 1
    The same way as many other libraries do: using the preprocessor. Search `include\pyconfig.h` for `pragma comment(lib,"python37_d.lib")` line (#274 in Python3.7). For MSVC consult the [documentation](https://learn.microsoft.com/ru-ru/cpp/preprocessor/comment-c-cpp?view=msvc-160). – Suthiro Jun 06 '21 at 08:31
  • I see. So libraries are only specified through command-line options, but can also be requested in header files. – Ziqi Fan Jun 07 '21 at 14:41
0

Following up the Suthiro's answer, you can also explicitly specify Debug or Release configurations for multi-configuration generators (Ninja Multi-Config, Visual Studio) by running

# Configure the build
cmake -S . -B build

# Actually build the binaries
cmake --build build --config Release

in your source directory. For single configuration generators and more details see this answer https://stackoverflow.com/a/64719718/15452880.

Python
  • 359
  • 2
  • 16