I am creating a DLL that I'd like to use in other projects, but has a Python dependency (there is no getting around this; the CPP DLL must call a Python module).
Platform: Windows
IDE: Visual Studio
Use Vcpkg Manifest: Yes
Target triplet : "x64-windows-static-md"
Added python3 using:
vcpkg add port python3
Then ran
vcpkg install
It seems installed fine because output is:
warning: In the September 2023 release, the default triplet for vcpkg libraries changed from x86-windows to the detected host triplet (x64-windows). For the old behavior, add --triplet x86-windows . To suppress this message, add --triplet x64-windows .
Detecting compiler hash for triplet x64-windows...
All requested packages are currently installed.
Total install time: 1.2 us
zeromq provides CMake targets:
# this is heuristically generated, and may not be correct
find_package(ZeroMQ CONFIG REQUIRED)
target_link_libraries(main PRIVATE libzmq libzmq-static)
zeromq provides pkg-config modules:
# 0MQ c++ library
libzmq
cppzmq provides CMake targets:
# this is heuristically generated, and may not be correct
find_package(cppzmq CONFIG REQUIRED)
target_link_libraries(main PRIVATE cppzmq cppzmq-static)
cppzmq provides pkg-config modules:
# C++ binding for libzmq
cppzmq
The package python3 is compatible with built-in CMake targets:
find_package(Python3 COMPONENTS Development REQUIRED)
target_link_libraries(main PRIVATE Python3::Python)
The package python3 provides a python interpreter that supports virtual environments:
>tools\python3\python.exe -m venv c:\path\to\venv
>set VIRTUAL_ENV=c:\path\to\venv
>set PATH=c:\path\to\venv\bin;%PATH%
>set PYTHONHOME=
See https://docs.python.org/3/library/venv.html for more details.
My problem occurs when I build:
Rebuild started at 12:27 AM...
1>------ Rebuild All started: Project: DLLTester, Configuration: Release x64 ------
2>------ Rebuild All started: Project: AsyncDLLMQL, Configuration: Release x64 ------
1>DLLTester.cpp
2>pch.cpp
1>LINK : fatal error LNK1181: cannot open input file 'AsyncDLLMQL.lib'
2>dllmain.cpp
2>mt5.cpp
2>utils.cpp
2>ZMQL.cpp
1>Done building project "DLLTester.vcxproj" -- FAILED.
2>D:\Redacted\Dev\AsyncDLLMQL\AsyncDLLMQL\mt5.cpp(3,10): error C1083: Cannot open include file: 'Python.h': No such file or directory
2>(compiling source file '/mt5.cpp')
2>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility(4537,18): warning C4244: '=': conversion from 'wchar_t' to 'char', possible loss of data
2>(compiling source file '/ZMQL.cpp')
2>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility(4537,18):
2>the template instantiation context (the oldest one first) is
2>D:\Redacted\Dev\AsyncDLLMQL\AsyncDLLMQL\ZMQL.cpp(47,16):
2>see reference to function template instantiation 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string<std::_String_iterator<std::_String_val<std::_Simple_types<_Elem>>>,0>(_Iter,_Iter,const _Alloc &)' being compiled
2> with
2> [
2> _Elem=wchar_t,
2> _Iter=std::_String_iterator<std::_String_val<std::_Simple_types<wchar_t>>>,
2> _Alloc=std::allocator<char>
2> ]
2>D:\Redacted\Dev\AsyncDLLMQL\AsyncDLLMQL\ZMQL.cpp(47,16):
2>see the first reference to 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string' in 'init_zmq'
2>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xstring(2600,17):
2>see reference to function template instantiation 'void std::basic_string<char,std::char_traits<char>,std::allocator<char>>::_Construct_from_iter<wchar_t*,wchar_t*,_Size_type>(_Iter,const _Sent,_Size)' being compiled
2> with
2> [
2> _Size_type=unsigned __int64,
2> _Iter=wchar_t *,
2> _Sent=wchar_t *,
2> _Size=unsigned __int64
2> ]
2>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xstring(2756,18):
2>see reference to function template instantiation '_OutIt *std::_Copy_n_unchecked4<wchar_t*,_Size,char*>(_InIt,_SizeTy,_OutIt)' being compiled
2> with
2> [
2> _OutIt=char *,
2> _Size=unsigned __int64,
2> _InIt=wchar_t *,
2> _SizeTy=unsigned __int64
2> ]
2>zmq_wrap.cpp
2>Done building project "AsyncDLLMQL.vcxproj" -- FAILED.
========== Rebuild All: 0 succeeded, 2 failed, 0 skipped ==========
========== Rebuild completed at 12:27 AM and took 01.698 seconds =========
How can I resolve this?
this is a problem specific to the vcpkg integration with visual studio, vcpkg currently adds python headers under a subdirectory with the python version, like Python3.12
, but it is only adding its parent to the include paths .... so it is included as
#include <Python3.12/Python.h>
you can find this directory relative to your solution file at \vcpkg_installed\x64-windows-static-md\x64-windows-static-md\include
this is very problematic when they upgrade the python version as you need to update your source code, to say 3.13
so it will be Python3.13/Python.h
you can add this to your Additional Include Directories
so you only have to change one place when vcpkg updates it on their side.
$(SolutionDir)vcpkg_installed\x64-windows-static-md\x64-windows-static-md\include\python3.12
then you can include it as
#include <Python.h>
and whenever you update the vcpkg dependencies version (baseline) you can update this path in this single location.
this problem is specific to using vcpkg with visual studio integration link to problematic line, and doesn't exist with CMake, as their CMake files correctly add the subdirectory to your include paths .... so you could probably switch to using CMake