PixarAnimationStudios / OpenSubdiv

An Open-Source subdivision surface library.
graphics.pixar.com/opensubdiv
Other
2.9k stars 561 forks source link

OpenSubdiv "Unresolved External Symbol" trying to compile on Windows 10 #1245

Closed rjmigliori closed 2 years ago

rjmigliori commented 2 years ago

Dealing with the following error:

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2001 unresolved external symbol "public: __cdecl OpenSubdiv::v3_4_4::Far::TopologyDescriptor::TopologyDescriptor(void)" (??0TopologyDescriptor@Far@v3_4_4@OpenSubdiv@@QEAA@XZ)   pyOpenSubdiv    C:\Users\username>\source\repos\pyOpenSubdiv\pyOpenSubdiv\Source.obj    1   

Context below.

Prerequisites:

-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19044. -- The C compiler identification is MSVC 19.32.31332.0 -- The CXX compiler identification is MSVC 19.32.31332.0 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done CMake Deprecation Warning at CMakeLists.txt:27 (cmake_minimum_required): Compatibility with CMake < 2.8.12 will be removed from a future version of CMake.

Update the VERSION argument value or use a ... suffix to tell CMake that the project does not need compatibility with older versions.

-- Compiling OpenSubdiv version v3_4_4 -- Using cmake version 3.24.0-rc2 -- Found OpenGL: opengl32 -- Found GLFW: C:/Users//Desktop/cpp/glfw-3.3.7.bin.WIN64/glfw-3.3.7.bin.WIN64/include (found suitable version "3.3.7", minimum required is "3.0.0") -- Found DXSDK: C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/um -- Configuring done -- Generating done -- Build files have been written to: C:/Users//Desktop/cpp/OpenSubdiv/build

- Run build install command: 

cmake --build . --config Release --target install

Which seems to work fine except for this part: 

... Generating Code... osd_gpu_obj.vcxproj -> C:\Users\\Desktop\cpp\OpenSubdiv\build\opensubdiv\osd\osd_gpu_obj.dir\Release\osd_gpu _obj.lib version.cpp osd_static_gpu.vcxproj -> C:\Users\\Desktop\cpp\OpenSubdiv\build\lib\Release\osdGPU.lib Generating shader.gen.h dxviewer.cpp dxviewer.obj : error LNK2019: unresolved external symbol D3D11CreateDeviceAndSwapChain referenced in function "bool c decl initD3D11(struct HWND )" (?initD3D11@@YA_NPEAUHWND__@@@Z) [C:\Users\\Desktop\cpp\OpenSubdiv\build\exam ples\dxViewer\dxViewer.vcxproj] d3d11Utils.obj : error LNK2019: unresolved external symbol D3DCompile referenced in function "struct ID3D10Blob cde cl D3D11Utils::CompileShader(char const ,char const ,char const *)" (?CompileShader@D3D11Utils@@YAPEAUID3D10Blob@@PEB D00@Z) [C:\Users\\Desktop\cpp\OpenSubdiv\build\examples\dxViewer\dxViewer.vcxproj] d3d11ShaderCache.obj : error LNK2001: unresolved external symbol D3DCompile [C:\Users\\Desktop\cpp\OpenSubdiv\ build\examples\dxViewer\dxViewer.vcxproj] osdGPU.lib(d3d11ComputeEvaluator.obj) : error LNK2001: unresolved external symbol D3DCompile [C:\Users\\Deskto p\cpp\OpenSubdiv\build\examples\dxViewer\dxViewer.vcxproj] osdGPU.lib(d3d11ComputeEvaluator.obj) : error LNK2019: unresolved external symbol D3DReflect referenced in function "pu blic: bool cdecl OpenSubdiv::v3_4_4::Osd::D3D11ComputeEvaluator::Compile(struct OpenSubdiv::v3_4_4::Osd::BufferDescri ptor const &,struct OpenSubdiv::v3_4_4::Osd::BufferDescriptor const &,struct ID3D11DeviceContext *)" (?Compile@D3D11Com puteEvaluator@Osd@v3_4_4@OpenSubdiv@@QEAA_NAEBUBufferDescriptor@234@0PEAUID3D11DeviceContext@@@Z) [C:\Users\\D esktop\cpp\OpenSubdiv\build\examples\dxViewer\dxViewer.vcxproj] C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\um\x86\d3d11.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64' [C:\Users\\Desktop\cpp\OpenSubdiv\build\examples\dxViewer\dxViewer.vc xproj] C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\um\x86\d3dcompiler.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64' [C:\Users\\Desktop\cpp\OpenSubdiv\build\examples\dxViewer\dxVie wer.vcxproj] C:\Users\\Desktop\cpp\OpenSubdiv\build\bin\Release\dxViewer.exe : fatal error LNK1120: 3 unresolved externals [C:\Users\\Desktop\cpp\OpenSubdiv\build\examples\dxViewer\dxViewer.vcxproj] ...


Then, I have a basic Visual Studio C++ project with the C/C++ addition include directories: 

C:\Users\\Desktop\cpp\OpenSubdiv C:\Users\\Desktop\cpp\boost_1_79_0 C:\Users\\Desktop\cpp\glfw-3.3.7.bin.WIN64\glfw-3.3.7.bin.WIN64\include C:\Users\\AppData\Local\Programs\Python\Python310\include %(AdditionalIncludeDirectories)


And for the Linker, the following additional include libraries: 

C:\Users\\Desktop\cpp\OpenSubdiv\build\lib\ C:\Users\\Desktop\cpp\boost_1_79_0\bin\x64\lib C:\Users\\AppData\Local\Programs\Python\Python310\DLLs C:\Users\\AppData\Local\Programs\Python\Python310\Lib C:\Users\\AppData\Local\Programs\Python\Python310\libs C:\Users\\AppData\Local\Programs\Python\Python310\tcl %(AdditionalLibraryDirectories)


Finally, when I try to compile this code (build the project in visual studio)

define BOOST_PYTHON_STATIC_LIB

include

include <boost/python.hpp>

define _USE_MATH_DEFINES

include

// #include <GLFW/glfw3.h>

include <opensubdiv/far/topologyDescriptor.h>

include <opensubdiv/far/primvarRefiner.h>

using namespace OpenSubdiv; char const* test_function() { return "Hello from C++"; typedef Far::TopologyDescriptor Descriptor; Descriptor desc; }

BOOST_PYTHON_MODULE(Project1) { boost::python::def("test_function", test_function); }

int main(void) { return 0; }


**I get the following error:** 

Severity Code Description Project File Line Suppression State Error LNK2001 unresolved external symbol "public: __cdecl OpenSubdiv::v3_4_4::Far::TopologyDescriptor::TopologyDescriptor(void)" (??0TopologyDescriptor@Far@v3_4_4@OpenSubdiv@@QEAA@XZ) pyOpenSubdiv C:\Users\username>\source\repos\pyOpenSubdiv\pyOpenSubdiv\Source.obj 1



Along with a huge number of warnings, which I'm also not sure what to do about. 

I don't know how to resolve this. Can anyone help? Please let me know if there is any additional information I can provide. Note that the code compiles fine with the libraries only included, it only fails when I try to use them, e.g. instance a `TopologyDescriptor`.
meshula commented 2 years ago

It looks like you are building for x64, but trying to link against a 32 bit windows sdk, instead of the 64 bit one.

C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\um\x86\d3dcompiler.lib : warning LNK4272: library machine type
'x86' conflicts with target machine type 'x64' [C:\Users\<username>\Desktop\cpp\OpenSubdiv\build\examples\dxViewer\dxVie
wer.vcxproj]

On my machine, the x64 libraries are adjacent to the x86 libraries ~ your path is

C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\um\x86

mine is

C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\um\x64

rjmigliori commented 2 years ago

I see. can you suggest a fix? I have that path on my computer ( C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\um\x64). Is there a way to tell OpenSubdiv to build using the 64 bit libraries? Is this an environment variable issue, or maybe not the right commands being passed into cmake?

meshula commented 2 years ago

The usual reason cmake makes x86 choices, is if you weren't running the x64 Native Tools Command Prompt shell (or running the vcvars batch file associated with that shell) when you configured the build, although it is trying to build x64 OpenSubdiv, so that might not be the problem. Could you double check that you are in an x64 native prompt, and if you are, could you attach your CMakeCache.txt file?

rjmigliori commented 2 years ago

CMakeCache.txt

I'm building in powershell, and I checked that I'm running a 64-bit instance of it. I could try CMD prompt?

I've attached my cmake cache file. Let me know if you have trouble reading it.

meshula commented 2 years ago

If you search within it, it confirms that cmake has picked the incorrect windows sdk. As a quick test, changing all the \um\x86 to \um\x64 and then running cmake . in the CMakeCache.txt's directory will likely get you building, but in a very inconvenient way since you'd have to correct the error manually any time you need to regenerate the build.

I have locally verified the same issue under powershell and under an x64 native command prompt.

meshula commented 2 years ago

If you search within it, it confirms that cmake has picked the incorrect windows sdk.

Delete your build directory and run this way ~

cmake /path/to/OpenSubdiv -DCMAKE_GENERATOR_PLATFORM=x64

and you'll get the correct result.

rjmigliori commented 2 years ago

Alright that got the install to work properly, which is great! But I'm still getting the same compile error LNK2001 unresolved external symbol "public: __cdecl OpenSubdiv::v3_4_4::Far::TopologyDescriptor::TopologyDescriptor(void)" (??0TopologyDescriptor@Far@v3_4_4@OpenSubdiv@@QEAA@XZ) pyOpenSubdiv C:\Users\username>\source\repos\pyOpenSubdiv\pyOpenSubdiv\Source.obj

These are the exact commands I ran, in an administrator powershell

cmake ^ -DCMAKE_GENERATOR_PLATFORM=x64 -G "Visual Studio 17 2022" ^ -D NO_PTEX=1 -D NO_DOC=1 ^ -D NO_OMP=1 -D NO_TBB=1 -D NO_CUDA=1 -D NO_OPENCL=1 -D NO_CLEW=1 ^ -D "GLFW_LOCATION=C:/Users/rmigliori/Desktop/cpp/glfw-3.3.7.bin.WIN64/glfw-3.3.7.bin.WIN64" ^ ..

cmake --build . --config Release --target install

Maybe the second cmake --build needs a -DCMAKE_GENERATOR_PLATFORM, but I'm not sure where to put it?

rjmigliori commented 2 years ago

I solved the problem, I was missing osdCPU.lib and osdGPU.lib in the Visual Studio Linker "Input Additional Dependencies." See e.g. this SE answer.

What a relief. Thank you so much for the help.