cmake works from cmd, fails in Visual Studio and Qt Creator

489 views Asked by At

I have a cmake project that I've been editing through Visual Studio 17 2022 with Ninja as the generator. This project uses boost and some other libraries as well. Boost was installed in the default location of C:\Boost. All other libraries were installed in my user folder so they have been added to my %PATH% environment variable. This setup worked. I installed Qt Creator to begin adding UI components. Once I installed Qt 6.5.0 MSVC2019 64bit, I could not compile the project anymore. I initially tried to build with Qt Creator and that failed. I went back to visual studio to build the project and that failed. However, compiling with cmake from the command line still works.

When I compiled from the command line, I noticed that Visual Studio 17 2022 was used as the generator. Because of this, I changed the CMakeUserPresets.json generator to Visual Studio 17 2022 and I changed the Qt build kit's generator to Visual Studio 17 2022, but Qt and Visual Studio still could not compile the project. The error I get from building the project Qt is: LINK : fatal error LNK1104: cannot open file 'libboost_log_setup-vc143-mt-gd-x64-1_78.lib' [C:\Users\calvin.bunge\git\build-ande-Desktop_Qt_6_5_0_MSVC2019_64bit-Debug\MotionLogicTest\MotionLogicTests.vcxproj]. The error I get from building the project from Visual Studio is: C:\Users\calvin.bunge\git\ande\out\build\x64-debug\LINK : fatal error LNK1104: cannot open file 'libboost_log_setup-vc143-mt-gd-x64-1_78.lib'. These link errors do not happen when I compile with cmake.

When I configure CMake with Visual Studio, I get this output:

-- Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.22621.
-- Found Boost: C:/Boost/lib/cmake/Boost-1.78.0/BoostConfig.cmake (found suitable version "1.78.0", minimum required is "1.71.0")  
CMake Deprecation Warning at C:/Users/calvin.bunge/Open3D/CMake/Open3DConfig.cmake:18 (cmake_policy):
  The OLD behavior for policy CMP0072 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
  Infrastructure/CMakeLists.txt:5 (find_package)


-- Boost_INCLUDE_DIR="C:/Boost/include/boost-1_78"
-- Boost_LIBRARY_DIR_RELEASE=""
-- Boost_LIBRARY_DIR_DEBUG=""
-- Boost_LIBRARY_DIRS=""
-- BOOST_ROOT=""
CMake Warning (dev) at C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FetchContent.cmake:1264 (message):
  The DOWNLOAD_EXTRACT_TIMESTAMP option was not given and policy CMP0135 is
  not set.  The policy's OLD behavior will be used.  When using a URL
  download, the timestamps of extracted files should preferably be that of
  the time of extraction, otherwise code that depends on the extracted
  contents might not be rebuilt if the URL changes.  The OLD behavior
  preserves the timestamps from the archive instead, but this is usually not
  what you want.  Update your project to the NEW behavior or specify the
  DOWNLOAD_EXTRACT_TIMESTAMP option with a value of true to avoid this
  robustness issue.
Call Stack (most recent call first):
  InfrastructureTest/CMakeLists.txt:2 (FetchContent_Declare)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Deprecation Warning at C:/Users/calvin.bunge/Open3D/CMake/Open3DConfig.cmake:18 (cmake_policy):
  The OLD behavior for policy CMP0072 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
  InfrastructureTest/CMakeLists.txt:22 (find_package)


CMake Deprecation Warning at C:/Users/calvin.bunge/Open3D/CMake/Open3DConfig.cmake:18 (cmake_policy):
  The OLD behavior for policy CMP0072 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
  MotionLogic/CMakeLists.txt:63 (find_package)


CMake Warning (dev) at C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FetchContent.cmake:1264 (message):
  The DOWNLOAD_EXTRACT_TIMESTAMP option was not given and policy CMP0135 is
  not set.  The policy's OLD behavior will be used.  When using a URL
  download, the timestamps of extracted files should preferably be that of
  the time of extraction, otherwise code that depends on the extracted
  contents might not be rebuilt if the URL changes.  The OLD behavior
  preserves the timestamps from the archive instead, but this is usually not
  what you want.  Update your project to the NEW behavior or specify the
  DOWNLOAD_EXTRACT_TIMESTAMP option with a value of true to avoid this
  robustness issue.
Call Stack (most recent call first):
  MotionLogicTest/CMakeLists.txt:2 (FetchContent_Declare)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Deprecation Warning at C:/Users/calvin.bunge/Open3D/CMake/Open3DConfig.cmake:18 (cmake_policy):
  The OLD behavior for policy CMP0072 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
  MotionLogicTest/CMakeLists.txt:22 (find_package)


CMake Deprecation Warning at C:/Users/calvin.bunge/Open3D/CMake/Open3DConfig.cmake:18 (cmake_policy):
  The OLD behavior for policy CMP0072 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
  Domain/CMakeLists.txt:50 (find_package)


-- Boost toolset is unknown (compiler MSVC 19.34.31937.0)
-- Boost toolset is unknown (compiler MSVC 19.34.31937.0)
-- Boost toolset is unknown (compiler MSVC 19.34.31937.0)
-- Boost toolset is unknown (compiler MSVC 19.34.31937.0)
-- Boost toolset is unknown (compiler MSVC 19.34.31937.0)
-- Boost toolset is unknown (compiler MSVC 19.34.31937.0)
-- Found Boost: C:/Boost/lib/cmake/Boost-1.78.0/BoostConfig.cmake (found suitable version "1.78.0", minimum required is "1.71.0") found components: log 
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/calvin.bunge/git/ande/out/build/x64-debug

When I configure CMake with Qt:

-- Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.22621.
-- CMAKE_CXX_COMPILER_ID="MSVC"
-- CMAKE_CXX_COMPILER_VERSION="19.34.31937.0"
-- CMAKE_VERSION="3.24.0-rc2"
-- CMAKE_GENERATOR="Visual Studio 17 2022"
MSVC
-- Found Boost: C:/Boost/lib/cmake/Boost-1.78.0/BoostConfig.cmake (found suitable version "1.78.0", minimum required is "1.71.0")  
CMake Deprecation Warning at C:/Users/calvin.bunge/Open3D/CMake/Open3DConfig.cmake:18 (cmake_policy):
  The OLD behavior for policy CMP0072 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
  Infrastructure/CMakeLists.txt:5 (find_package)


-- Boost_INCLUDE_DIR="C:/Boost/include/boost-1_78"
-- Boost_LIBRARY_DIR_RELEASE=""
-- Boost_LIBRARY_DIR_DEBUG="C:/Boost/lib"
-- Boost_LIBRARY_DIRS="C:/Boost/lib"
-- BOOST_ROOT=""
CMake Warning (dev) at C:/Program Files/CMake/share/cmake-3.24/Modules/FetchContent.cmake:1237 (message):
  The DOWNLOAD_EXTRACT_TIMESTAMP option was not given and policy CMP0135 is
  not set.  The policy's OLD behavior will be used.  When using a URL
  download, the timestamps of extracted files should preferably be that of
  the time of extraction, otherwise code that depends on the extracted
  contents might not be rebuilt if the URL changes.  The OLD behavior
  preserves the timestamps from the archive instead, but this is usually not
  what you want.  Update your project to the NEW behavior or specify the
  DOWNLOAD_EXTRACT_TIMESTAMP option with a value of true to avoid this
  robustness issue.
Call Stack (most recent call first):
  InfrastructureTest/CMakeLists.txt:2 (FetchContent_Declare)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Deprecation Warning at C:/Users/calvin.bunge/Open3D/CMake/Open3DConfig.cmake:18 (cmake_policy):
  The OLD behavior for policy CMP0072 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
  InfrastructureTest/CMakeLists.txt:22 (find_package)


CMake Deprecation Warning at C:/Users/calvin.bunge/Open3D/CMake/Open3DConfig.cmake:18 (cmake_policy):
  The OLD behavior for policy CMP0072 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
  MotionLogic/CMakeLists.txt:63 (find_package)


CMake Warning (dev) at C:/Program Files/CMake/share/cmake-3.24/Modules/FetchContent.cmake:1237 (message):
  The DOWNLOAD_EXTRACT_TIMESTAMP option was not given and policy CMP0135 is
  not set.  The policy's OLD behavior will be used.  When using a URL
  download, the timestamps of extracted files should preferably be that of
  the time of extraction, otherwise code that depends on the extracted
  contents might not be rebuilt if the URL changes.  The OLD behavior
  preserves the timestamps from the archive instead, but this is usually not
  what you want.  Update your project to the NEW behavior or specify the
  DOWNLOAD_EXTRACT_TIMESTAMP option with a value of true to avoid this
  robustness issue.
Call Stack (most recent call first):
  MotionLogicTest/CMakeLists.txt:2 (FetchContent_Declare)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Deprecation Warning at C:/Users/calvin.bunge/Open3D/CMake/Open3DConfig.cmake:18 (cmake_policy):
  The OLD behavior for policy CMP0072 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
  MotionLogicTest/CMakeLists.txt:22 (find_package)


CMake Deprecation Warning at C:/Users/calvin.bunge/Open3D/CMake/Open3DConfig.cmake:18 (cmake_policy):
  The OLD behavior for policy CMP0072 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
  Domain/CMakeLists.txt:50 (find_package)


-- Boost toolset is unknown (compiler MSVC 19.34.31937.0)
-- Boost toolset is unknown (compiler MSVC 19.34.31937.0)
-- Boost toolset is unknown (compiler MSVC 19.34.31937.0)
-- Boost toolset is unknown (compiler MSVC 19.34.31937.0)
-- Boost toolset is unknown (compiler MSVC 19.34.31937.0)
-- Boost toolset is unknown (compiler MSVC 19.34.31937.0)
-- Found Boost: C:/Boost/lib/cmake/Boost-1.78.0/BoostConfig.cmake (found suitable version "1.78.0", minimum required is "1.71.0") found components: log 
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/calvin.bunge/git/build-ande-Desktop_Qt_6_5_0_MSVC2019_64bit-Debug

When I configure from the command line:

-- Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.22621.
-- CMAKE_CXX_COMPILER_ID="MSVC"
-- CMAKE_CXX_COMPILER_VERSION="19.34.31937.0"
-- CMAKE_VERSION="3.24.0-rc2"
-- CMAKE_GENERATOR="Visual Studio 17 2022"
MSVC
-- Found Boost: C:/Boost/include/boost-1_78 (found suitable version "1.78.0", minimum required is "1.71.0")
CMake Deprecation Warning at C:/Users/calvin.bunge/Open3D/CMake/Open3DConfig.cmake:18 (cmake_policy):
  The OLD behavior for policy CMP0072 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
  Infrastructure/CMakeLists.txt:5 (find_package)


-- Boost_INCLUDE_DIR="C:/Boost/include/boost-1_78"
-- Boost_LIBRARY_DIR_RELEASE=""
-- Boost_LIBRARY_DIR_DEBUG="C:/Boost/lib"
-- Boost_LIBRARY_DIRS="C:/Boost/lib"
-- BOOST_ROOT=""
CMake Warning (dev) at C:/Program Files/CMake/share/cmake-3.24/Modules/FetchContent.cmake:1237 (message):
  The DOWNLOAD_EXTRACT_TIMESTAMP option was not given and policy CMP0135 is
  not set.  The policy's OLD behavior will be used.  When using a URL
  download, the timestamps of extracted files should preferably be that of
  the time of extraction, otherwise code that depends on the extracted
  contents might not be rebuilt if the URL changes.  The OLD behavior
  preserves the timestamps from the archive instead, but this is usually not
  what you want.  Update your project to the NEW behavior or specify the
  DOWNLOAD_EXTRACT_TIMESTAMP option with a value of true to avoid this
  robustness issue.
Call Stack (most recent call first):
  InfrastructureTest/CMakeLists.txt:2 (FetchContent_Declare)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Deprecation Warning at C:/Users/calvin.bunge/Open3D/CMake/Open3DConfig.cmake:18 (cmake_policy):
  The OLD behavior for policy CMP0072 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
  InfrastructureTest/CMakeLists.txt:22 (find_package)


CMake Deprecation Warning at C:/Users/calvin.bunge/Open3D/CMake/Open3DConfig.cmake:18 (cmake_policy):
  The OLD behavior for policy CMP0072 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
  MotionLogic/CMakeLists.txt:63 (find_package)


CMake Warning (dev) at C:/Program Files/CMake/share/cmake-3.24/Modules/FetchContent.cmake:1237 (message):
  The DOWNLOAD_EXTRACT_TIMESTAMP option was not given and policy CMP0135 is
  not set.  The policy's OLD behavior will be used.  When using a URL
  download, the timestamps of extracted files should preferably be that of
  the time of extraction, otherwise code that depends on the extracted
  contents might not be rebuilt if the URL changes.  The OLD behavior
  preserves the timestamps from the archive instead, but this is usually not
  what you want.  Update your project to the NEW behavior or specify the
  DOWNLOAD_EXTRACT_TIMESTAMP option with a value of true to avoid this
  robustness issue.
Call Stack (most recent call first):
  MotionLogicTest/CMakeLists.txt:2 (FetchContent_Declare)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Deprecation Warning at C:/Users/calvin.bunge/Open3D/CMake/Open3DConfig.cmake:18 (cmake_policy):
  The OLD behavior for policy CMP0072 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
  MotionLogicTest/CMakeLists.txt:22 (find_package)


CMake Deprecation Warning at C:/Users/calvin.bunge/Open3D/CMake/Open3DConfig.cmake:18 (cmake_policy):
  The OLD behavior for policy CMP0072 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
  Domain/CMakeLists.txt:50 (find_package)


-- Found Boost: C:/Boost/include/boost-1_78 (found suitable version "1.78.0", minimum required is "1.71.0") found components: log log_setup filesystem thread regex chrono atomic
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/calvin.bunge/git/ande/build

The compiler versions are the same, the cmake versions are the same, but the message for found boost is different. The IDEs find boost at C:/Boost/lib/cmake/Boost-1.78.0/BoostConfig.cmake but the command line finds boost at C:/Boost/include/boost-1_78. Another difference is that the command line sets Boost_LIBRARY_DIRS, Boost_LIBRARY_DIR_RELEASE, Boost_LIBRARY_DIR_DEBUG whereas the IDEs do not. Also the -- Boost toolset is unknown (compiler MSVC 19.34.31937.0) appears when the IDEs configure cmake but not when cmake is configured from the IDE.

I'm mainly puzzled by the fact that this problem emerged after I installed Qt for MSVC. I compiled the program with visual studio half an hour before I installed Qt, didn't change any cmake scripts, and cannot compile from visual studio since I installed Qt.

UPDATE: Here is the CMakeLists.txt for the module using boost log:

add_library(Common
    Logger.cpp
    Logger.h
    MathUtility.cpp
    MathUtility.h
    StringUtility.cpp
    StringUtility.h
)

target_include_directories(Common PUBLIC
  $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
  $<INSTALL_INTERFACE:>
)
# Eigen
target_link_libraries (Common Eigen3::Eigen)
find_package (Eigen3 3.4 REQUIRED)
# Boost
# Use static lib. Must specify or else log will look for shared lib
SET(Boost_USE_STATIC_LIBS ON)
find_package (Boost 1.71.0 REQUIRED COMPONENTS log)
target_link_libraries (Common Boost::boost)
target_link_libraries (Common Boost::log)

Here is the CMakeLists.txt for the project:

# CMakeList.txt : Top-level CMake project file, do global configuration
# and include sub-projects here.
#
cmake_minimum_required (VERSION 3.14)
set(CMAKE_CXX_STANDARD 14)

project ("ANDE")

# Include sub-projects.
add_subdirectory("Infrastructure")
enable_testing()
add_subdirectory("InfrastructureTest")
add_subdirectory("MotionLogic")
add_subdirectory("MotionLogicTest")
add_subdirectory("Domain")
add_subdirectory("Common")

Some modules like Infrastucture depend on Common. Boost Log can only be link to one spot in an application if the static lib is used, which we are doing. However, I don't think this is an issue since the code worked fine like this before. I was able to execute unit tests without problem.

Here are the commands that Qt and Visual Studio use to configure and build the project, and here are the commands I use from cmd that works:

Visual Studio:

Configure:

"C:\WINDOWS\system32\cmd.exe" /c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe"  -G "Visual Studio 17 2022"  -DCMAKE_C_COMPILER:STRING="cl.exe" -DCMAKE_CXX_COMPILER:STRING="cl.exe" -DCMAKE_PREFIX_PATH:STRING="" -DCMAKE_BUILD_TYPE:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="C:/Users/calvin.bunge/git/ande/out/install/x64-debug"  "C:\Users\calvin.bunge\git\ande" 2>&1"

Build: Not available

Qt:

Configure:

C:\Program Files\CMake\bin\cmake.exe -S C:/Users/calvin.bunge/git/ande -B C:/Users/calvin.bunge/git/build-ande-Desktop_Qt_6_5_0_MSVC2019_64bit-Debug in C:\Users\calvin.bunge\git\build-ande-Desktop_Qt_6_5_0_MSVC2019_64bit-Debug

Build:

"C:\Program Files\CMake\bin\cmake.exe" --build C:/Users/calvin.bunge/git/build-ande-Desktop_Qt_6_5_0_MSVC2019_64bit-Debug --target ALL_BUILD --config Debug

Command Line:

Configure: (from directory build in project root) cmake ..

Build: cmake --build .

1

There are 1 answers

0
calbungendts On

I've removed boost logging and replaced it with a simple write to text file function. Not the best solution but this has been a major stop in development that cannot continue.