microsoft / vcpkg

C++ Library Manager for Windows, Linux, and MacOS
MIT License
23.33k stars 6.45k forks source link

[poco] MTd link failure #38462

Open az-faro opened 6 months ago

az-faro commented 6 months ago

Describe the bug I use the poco library via vcpkg. The application uses /MTd runtime library, but vcpkg is set to not use static libraries. Poco builds correctly, but in the linking stage I get LINK : fatal error LNK1104: cannot open file 'PocoFoundationmtd.lib'.

Environment

To Reproduce Steps to reproduce the behavior:

  1. Add {"name":"poco", "platform": "x64|windows"} to vcpkg.json.
  2. Create Visual Studio C++ project with vcpkg activated that uses some Poco functionality (for example #include "Poco/URI.h").
  3. The vcpkg config in the project is the default apart from Use Vcpkg Manifest that is set to Yes. Particularly Use Static Libraries is set to No, but this should be the default.
  4. Build project in debug config with Runtime Library set to Multi-threaded Debug (/MTd)

Expected behavior I would expect the project to link correctly and give me access to Poco functionality.

Failure logs

1>------ Build started: Project: PocoTest, Configuration: Debug x64 ------
1>LINK : fatal error LNK1104: cannot open file 'PocoFoundationmtd.lib'
1>Done building project "PocoTest.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Additional context

FrankXie05 commented 6 months ago

@az-faro Thanks for posting this issue, I think we have included the debug path correctly, can you rerun the command ./vcpkg integrate install and try again?

https://github.com/microsoft/vcpkg/blob/7eb700c9688daed6d8bdcdc571ebe3eedea6a774/scripts/buildsystems/msbuild/vcpkg.targets#L113

az-faro commented 6 months ago

Hello @FrankXie05. This indeed now works correctly in debug.

The same issue persists in release though. I know I didn't mention that in the original bug report, but it's exactly the same issue in release as there is in debug.

az-faro commented 6 months ago

Actually, upon closer inspection this still doesn't work for me. Using the latest version of vcpkg and poco 1.13.3 still shows exactly the same issue:

Build started... 1>------ Build started: Project: PocoTest, Configuration: Debug x64 ------ 1>Installing vcpkg dependencies to C:\work\unversioned\PocoTest\vcpkg_installed\x64-windows\ 1>"C:\work\vcpkg\vcpkg\vcpkg.exe" install --x-wait-for-lock --triplet "x64-windows" --vcpkg-root "C:\work\vcpkg\vcpkg\" "--x-manifest-root=C:\work\unversioned\PocoTest\" "--x-install-root=C:\work\unversioned\PocoTest\vcpkg_installed\x64-windows\" 1>Detecting compiler hash for triplet x64-windows... 1>Compiler found: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe 1>The following packages will be built and installed: 1> expat:x64-windows@2.6.2 1> pcre2[core,jit,platform-default-features]:x64-windows@10.43 1> poco:x64-windows@1.13.3 1> vcpkg-cmake:x64-windows@2024-04-18 1> vcpkg-cmake-config:x64-windows@2022-02-06#1 1> zlib:x64-windows@1.3.1 1>Additional packages () will be modified to complete this operation. 1>Restored 6 package(s) from C:\Users\ZettersA\AppData\Local\vcpkg\archives in 5.1 s. Use --debug to see more details. 1>Installing 1/6 vcpkg-cmake:x64-windows@2024-04-18... 1>Elapsed time to handle vcpkg-cmake:x64-windows: 37 ms 1>vcpkg-cmake:x64-windows package ABI: 8b42a42ed1bdf897a526265f62c948a0025fbd3832eec15b9a644732e1bb56a2 1>Installing 2/6 zlib:x64-windows@1.3.1... 1>Elapsed time to handle zlib:x64-windows: 34.9 ms 1>zlib:x64-windows package ABI: 3ea500905e5b64da0a81e1616c29e8ecb067f2cfd89cceaedb122747f77d9a4d 1>Installing 3/6 vcpkg-cmake-config:x64-windows@2022-02-06#1... 1>Elapsed time to handle vcpkg-cmake-config:x64-windows: 16.7 ms 1>vcpkg-cmake-config:x64-windows package ABI: f2b3d24fa2b61fe3ca168cfb265f3c64a3cf82219fbeac798ca0317c7303e895 1>Installing 4/6 pcre2[core,jit,platform-default-features]:x64-windows@10.43... 1>Elapsed time to handle pcre2:x64-windows: 68.4 ms 1>pcre2:x64-windows package ABI: f029c303a48d9a6057ef886c81d05aec6e03b71e896d43090ba461a1d05dc104 1>Installing 5/6 expat:x64-windows@2.6.2... 1>Elapsed time to handle expat:x64-windows: 38.3 ms 1>expat:x64-windows package ABI: 92b9ffebe49c1fb841b90332f61195f5135143ff108dc6dc900e0bca216ee815 1>Installing 6/6 poco:x64-windows@1.13.3... 1>Elapsed time to handle poco:x64-windows: 886 ms 1>poco:x64-windows package ABI: a60bfe72fb139c264257e556727ee7396625f9a26a9e01bc5ffdfce931bb81e7 1>Total install time: 1.1 s 1>The package poco is compatible with built-in CMake targets: 1> 1> find_package(Poco REQUIRED [COMPONENTS ...]) 1> target_link_libraries(main PRIVATE Poco::) 1> 1>PocoTest.cpp 1>LINK : fatal error LNK1104: cannot open file 'PocoFoundationmtd.lib' 1>Done building project "PocoTest.vcxproj" -- FAILED. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

dg0yt commented 6 months ago
  1. Add {"name":"poco", "platform": "x64|windows"} to vcpkg.json.

Note that this request to install poco when you build "for x64 or for windows". It does not set what type of lib to build. You have to set the vcpkg target triplet for that choice.

The PocoFoundatinmtd.lib is correctly built, it's just the linking that is incorrect.

Are you sure? The log says

1>Installing 6/6 poco:x64-windows@1.13.3...

And that package builds (CI logs):

poco:x64-windows:/debug/lib/PocoFoundationd.lib poco:x64-windows:/lib/PocoFoundation.lib

az-faro commented 6 months ago
  1. Add {"name":"poco", "platform": "x64|windows"} to vcpkg.json.

Note that this request to install poco when you build "for x64 or for windows". It does not set what type of lib to build. You have to set the vcpkg target triplet for that choice.

As far as I understand Visual Studio will decide which triplet to use depending on which configuration I choose to build and if I configure that I want to use static libraries or not.

The PocoFoundatinmtd.lib is correctly built, it's just the linking that is incorrect.

Are you sure? The log says

1>Installing 6/6 poco:x64-windows@1.13.3...

And that package builds (CI logs):

poco:x64-windows:/debug/lib/PocoFoundationd.lib poco:x64-windows:/lib/PocoFoundation.lib

Well that's the issue then isn't it? if it builds those version and then tries to link the mtd version? I don't choose which version to link, vcpkg does.

dg0yt commented 6 months ago

I don't choose which version to link, vcpkg does.

Does it? I assume you use msbuild, not CMake. Vcpkg uses "autolinking" for msbuild. It would choose exactly (all!) the files which are there. However, if a source or header has a #pragma comment(lib PocoFoundatinmtd), the linker wants to have that lib, too. If such a header is installed by vcpkg, it is a bug. But quite often users find such lines in own code or non-vcpkg dependencies.

az-faro commented 6 months ago

Well this is exactly all the code in the test project I made to illustrate the issue. I think it's safe to say I'm not forcing PocoFoundationmtd to load.

#include <iostream>
#include "Poco/URI.h"

int main()
{
    std::cout << "Hello World!\n";
}
dg0yt commented 6 months ago

PocoFoundationmtd.lib belongs to the x64-windows-static triplet (static library linkage, static CRT linkage).

Use Static Libraries is set to No

I don't know if this is or should be passed to vcpkg. (Still not using Visual Something.) I still believe that "You have to set the vcpkg target triplet": https://learn.microsoft.com/en-us/vcpkg/users/buildsystems/msbuild-integration#vcpkgtriplet

dg0yt commented 6 months ago

And obviously "Use Static Libraries is set to No" poorly fits x64-windows-static.

az-faro commented 6 months ago

I think it chooses the correct triplet x64-windows as seen in the logs. It's just that then when selecting which library to import it seems to take that from the project settings (i.e. that the runtime library is set to MTd), rather than the vcpkg settings Use Static Libraries = No.

pierr3 commented 2 months ago

Facing exactly the same issue, with the same circumstances and same test code. Must be an issue with the port, it seems to always build as /MD

neilenns commented 2 months ago

Digging into the Poco cmake file I found when MSVC is used the POCO_MT flag determines whether mt or md is output.

The cmake file in this repo sets POCO_MT like this.

Is it possible that POCO_MT is simply never set? I tried manually forcing it like this at the top of the cmake file Pierre and I use:

set(POCO_MT TRUE)

but it didn't change anything.

Edit: It didn't change anything because the cmake file in this repo sets it explicitly like this:

string(COMPARE EQUAL "${VCPKG_CRT_LINKAGE}" "static" POCO_MT)

Looks like we don't have a triplet defined 😬 Trying with this now and will report back:

set(VCPKG_TARGET_TRIPLET x64-windows-static)