'LNK1181: cannot open input file 'usd.lib' from USD SDK despite linking it in CMake

I have downloaded prebuilt binaries for Pixar's USD SDK, and set up a rudimentary CMake project to use it:

# my-project/CMakeLists.txt
cmake_minimum_required(VERSION 3.8)

project("my-project")

add_subdirectory(thirdparty/usd) # This CMakeLists.txt just calls include(pxrConfig.cmake)

add_executable(my-project "my-project.cpp" "my-project.h")

target_link_libraries(my-project
    usd
)

The C++ files are default and don't actually use the USD target yet:

// my-project.h
#pragma once

#include <iostream>

// my-project.cpp
#include "my-project.h"

int main()
{
    std::cout << "Hello CMake." << std::endl;
    return 0;
}

However, when building, I get a link error that usd.lib cannot be found

[proc] Executing command: "C:\Programs\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" --build c:/Users/Drew/Documents/git/my-project/out/build/x64-release --target my-project
[build] [1/2](0.491s) Building CXX object CMakeFiles\my-project.dir\my-project.cpp.obj
[build] [2/2](0.534s) Linking CXX executable my-project.exe
[build] FAILED: my-project.exe 
[build] cmd.exe /C "cd . && "C:\Programs\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\my-project.dir --rc=C:\PROGRA~2\WINDOW~4\10\bin\100190~1.0\x86\rc.exe --mt=C:\PROGRA~2\WINDOW~4\10\bin\100190~1.0\x86\mt.exe --manifests  -- C:\Programs\MICROS~1\2022\COMMUN~1\VC\Tools\MSVC\1431~1.311\bin\Hostx86\x64\link.exe /nologo CMakeFiles\my-project.dir\my-project.cpp.obj  /out:my-project.exe /implib:my-project.lib /pdb:my-project.pdb /version:0.0 /machine:x64 /INCREMENTAL:NO /subsystem:console  usd.lib  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
[build] LINK: command "C:\Programs\MICROS~1\2022\COMMUN~1\VC\Tools\MSVC\1431~1.311\bin\Hostx86\x64\link.exe /nologo CMakeFiles\my-project.dir\my-project.cpp.obj /out:my-project.exe /implib:my-project.lib /pdb:my-project.pdb /version:0.0 /machine:x64 /INCREMENTAL:NO /subsystem:console usd.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:my-project.exe.manifest" failed (exit code 1181) with the following output:
[build] LINK : fatal error LNK1181: cannot open input file 'usd.lib'

If relevant, the configure command was

[proc] Executing command: "C:\Programs\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=cl.exe -DCMAKE_CXX_COMPILER=cl.exe -DCMAKE_INSTALL_PREFIX=c:/Users/Drew/Documents/git/my-project/out/install/x64-release -Sc:/Users/Drew/Documents/git/my-project -Bc:/Users/Drew/Documents/git/my-project/out/build/x64-release -G Ninja

Pixar's cmake code sets up the usd target like so

add_library(usd SHARED IMPORTED)

set_target_properties(usd PROPERTIES
  INTERFACE_COMPILE_DEFINITIONS "PXR_PYTHON_ENABLED=1"
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include;E:/w/ca6c508eae419cf8/_install/win64_py36_release/include;E:/w/ca6c508eae419cf8/_install/win64_py36_release/include"
  INTERFACE_LINK_LIBRARIES "arch;kind;pcp;sdf;ar;plug;tf;trace;vt;work;E:/w/ca6c508eae419cf8/_install/win64_py36_release/lib/boost_python36-vc141-mt-x64-1_70.lib;E:/w/ca6c508eae419cf8/_install/win64_py36_release/lib/tbb.lib"
  INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "E:/w/ca6c508eae419cf8/_install/win64_py36_release/include;E:/w/ca6c508eae419cf8/_install/win64_py36_release/include"
)

# Import target "usd" for configuration "Release"
set_property(TARGET usd APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(usd PROPERTIES
  IMPORTED_IMPLIB_RELEASE "${_IMPORT_PREFIX}/lib/usd.lib"
  IMPORTED_LOCATION_RELEASE "${_IMPORT_PREFIX}/lib/usd.dll"
  )

list(APPEND _IMPORT_CHECK_TARGETS usd )
list(APPEND _IMPORT_CHECK_FILES_FOR_usd "${_IMPORT_PREFIX}/lib/usd.lib" "${_IMPORT_PREFIX}/lib/usd.dll" )

so it should be set up properly.

What am I doing wrong with my project setup to cause this linker error?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source