microsoft / vcpkg

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

MSVS cannot find source files even after VCPKG installation with no errors #31915

Open mm-lmitechnologies opened 1 year ago

mm-lmitechnologies commented 1 year ago

Describe the bug Using VCPKG to install libraries, I then create a new MSVS project but cannot include the installed library header files (ex. sqlite3.h)

Environment Windows 10 Microsoft Visual Studio 2022

To Reproduce Steps to reproduce the behavior:

  1. ./vcpkg install sqlite3
  2. ./vcpkg integrate install (no errors)
  3. Create new MSVS 2022 project
  4. include [error: cannot open source file sqlite3.h]

Expected behavior expected MSVS to find the intalled libraries from vcpkg

Failure logs none

Additional context installed vcpkg by cloning git repo ran boostrap ran .\vcpkg integrate install, no warnings or errors. "All MSBuild C++ projects can now #include any installed libraries. Linking will be handled automatically. Installing new libraries will make them instantly available." ran .\vcpkg install sqlite3, no warnings or errors - installed succesfully occurs with all other libraries tried please help

Adela0814 commented 1 year ago

Have you set the toolchain file? https://github.com/microsoft/vcpkg#quick-start-windows:~:text=In%20order%20to%20use%20vcpkg%20with%20CMake%20outside%20of%20an%20IDE%2C%20you%20can%20use%20the%20toolchain%20file%3A

Baklap4 commented 1 year ago

Hmmm with the latest Visual Studio 17.6.2 the toolchain file from Microsoft gets loaded. I have specified VCPKG_ROOT to a custom directory and use that within my CMakePreset.json but somehow VS2022 ignores this and sets their own path as VCPKG_ROOT

{
  "version": 2,
  "configurePresets": [
    {
      "name": "windows-base",
      "description": "Target Windows with the Visual Studio development environment.",
      "hidden": true,
      "generator": "Ninja",
      "binaryDir": "${sourceDir}/build/${presetName}",
      "cacheVariables": {
        "CMAKE_C_COMPILER": "cl.exe",
        "CMAKE_CXX_COMPILER": "cl.exe",
        "BUILD_SHARED_LIBS": "ON",
        "ENABLE_WEBSERVER": "OFF",
        "SELF_BUILT_AUBIO": "ALWAYS",
        "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/${presetName}-install",
        "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", //<< this doesnt even though VCPKG_ROOT is set in env vars. It gets overriden by MS VS2022
        //"CMAKE_TOOLCHAIN_FILE": "C:/repos/performous/vcpkg/scripts/buildsystems/vcpkg.cmake", << this works
        "PERFORMOUS_VERSION": "$env{PERFORMOUS_VERSION}"
      }
    },

The command which is executed:

1> Command line: "C:\WINDOWS\system32\cmd.exe" /c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\PROFESSIONAL\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe"  -G "Ninja"  -DCMAKE_C_COMPILER:STRING="cl.exe" -DCMAKE_CXX_COMPILER:STRING="cl.exe" -DBUILD_SHARED_LIBS:STRING="ON" -DENABLE_WEBSERVER:STRING="OFF" -DSELF_BUILT_AUBIO:STRING="ALWAYS" -DCMAKE_INSTALL_PREFIX:STRING="C:/repos/performous/performous/build/x64-debinfo-install" -DCMAKE_TOOLCHAIN_FILE:STRING="C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\vcpkg/scripts/buildsystems/vcpkg.cmake" -DPERFORMOUS_VERSION:STRING="" -DCMAKE_BUILD_TYPE:STRING="RelWithDebInfo"  -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\PROFESSIONAL\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "C:\repos\performous\performous" 2>&1"

See that `CMAKE_TOOLCHAIN_FILE is set to the program files of VS2022 instead of the custom git cloned place:

-DCMAKE_TOOLCHAIN_FILE:STRING="C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\vcpkg/scripts/buildsystems/vcpkg.cmake"

VS2022 gives you the option to specify a custom vcpkg, but then it still uses their own TOOLCHAIN_FILE

Microsoft docs regarding VCPKG_ROOT env var: https://learn.microsoft.com/en-us/vcpkg/users/config-environment#vcpkg_root

Environment variable settings image

Commands ran in order:

  1. cd C:/repos/performous/
  2. git clone git@github.com:microsoft/vcpkg
  3. cd vcpkg
  4. git checkout master
  5. git pull
  6. .\bootstrap-vcpkg.bat
  7. .\vcpkg.exe integrate install
  8. .\vcpkg.exe install <your-dependencies>
  9. Use dependency in a project

Result: Build fails cause dependency cannot be found as Visual Studio uses their own TOOLCHAIN_FILE

github-actions[bot] commented 1 year ago

This is an automated message. Per our repo policy, stale issues get closed if there has been no activity in the past 28 days. The issue will be automatically closed in 14 days. If you wish to keep this issue open, please add a new comment.

ree4pwn commented 1 year ago

Same problem

github-actions[bot] commented 1 year ago

This is an automated message. Per our repo policy, stale issues get closed if there has been no activity in the past 28 days. The issue will be automatically closed in 14 days. If you wish to keep this issue open, please add a new comment.

Baklap4 commented 1 year ago

Up till today this is still a problem. The environment variable doesn't get used within Visual Studio 2022

Baklap4 commented 1 year ago

Any update on this @Adela0814 or do we need to go to VS2022 team?

Baklap4 commented 1 year ago

Hmm update from my side. If you install VS2022 with the built-in vcpkgmanager (which is the default for 17.6+) it'll always overrule the VCPKG_ROOT variable. I removed the vcpkg manager from VS2022 as i use the cloned Git variant, and all seemed to work again

github-actions[bot] commented 1 year ago

This is an automated message. Per our repo policy, stale issues get closed if there has been no activity in the past 28 days. The issue will be automatically closed in 14 days. If you wish to keep this issue open, please add a new comment.

Baklap4 commented 1 year ago

I guess this can be almost closed as it's not an issue with vcpkg but rather pebcak. If you install VS2022 and also have the built-in vcpkgmanager installed (which is the default since 17.6+) you'll have to uninstall this component to make a standalone install of vcpkg work again.

Might be nice if this gets mentioned within the docs of vcpkg? /first-good-issue

github-actions[bot] commented 11 months ago

This is an automated message. Per our repo policy, stale issues get closed if there has been no activity in the past 28 days. The issue will be automatically closed in 14 days. If you wish to keep this issue open, please add a new comment.

Baklap4 commented 9 months ago

@Adela0814 is there any documentation as of 9 hours ago that states this? Else please reopen it

If you install VS2022 and also have the built-in vcpkgmanager installed (which is the default since 17.6+) you'll have to uninstall this component to make a standalone install of vcpkg work again.