optix library build project problem - error LNK2001: __declspec(dllimport)

Hello,

I am new to Optix,
I want to build SDK’s example project( for example "optixSphere").
The equipment list is below.

  • Windows 7 Prof 64 bit,
  • Microsoft Visual Studio Professional 2012
    Version 11.0.50727.1 RTMREL
    Microsoft .NET Framework
    Version 4.5.50709
    Installed Version: Professional
  • NVIDIA CUDA 6.0 Wizards 6.0
  • GPU: TeslaK20
  • Optix SDK version : v4.0.2

I build this project file("optixSphere") in Visual Studio without Cmake. I also changed these parameters;

  • Property->Configuration Properties-> Cuda C/C++ -> Common -> NVCC Compilation Type : changed to Generate .ptx file(-ptx)
  • Property->Configuration Properties-> Cuda C/C++ -> Device -> Code Generation: changed compute_35,sm_35
    I add to include files in this link :"Property->Configuration Properties -> VC++ Directories -> Include Directories" and I add to library files in this link: "Property->Configuration Properties -> VC++ Directories -> Library Directories"

In conclusion, with these project specs I couldn’t build any optix SDK example. For example, with "optixSphere" project I took these errors;

error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl sutil::displayBufferPPM(char const *,struct RTbuffer_api *)" (_imp?displayBufferPPM@sutil@@YAXPEBDPEAURTbuffer_api@@@Z)

error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl sutil::calculateCameraVariables(struct optix::float3,struct optix::float3,struct optix::float3,float,float,struct optix::float3 &,struct optix::float3 &,struct optix::float3 &,bool)" (_imp?calculateCameraVariables@sutil@@YAXUfloat3@optix@@00MMAEAU23@11_N@Z)

error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl sutil::reportErrorMessage(char const *)" (_imp?reportErrorMessage@sutil@@YAXPEBD@Z)

error LNK2001: unresolved external symbol "__declspec(dllimport) char const * __cdecl sutil::samplesPTXDir(void)" (_imp?samplesPTXDir@sutil@@YAPEBDXZ)

error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl sutil::displayBufferGlut(char const *,struct RTbuffer_api *)"

error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl sutil::parseDimensions(char const *,int &,int &)" (_imp?parseDimensions@sutil@@YAXPEBDAEAH1@Z)

error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl sutil::handleError(struct RTcontext_api *,enum RTresult,char const *,int)" (_imp?handleError@sutil@@YAXPEAURTcontext_api@@W4RTresult@@PEBDH@Z)

error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl sutil::initGlut(int *,char * *)" (_imp?initGlut@sutil@@YAXPEAHPEAPEAD@Z)

Why could these problems occur? I couldn’t fix these problems. Can we use optix tool without cmake? If yes How can I make project in Visual Studio? Could you tell me this solution step by step? Thanks for your help.

First, when building your own OptiX projects without using CMake, make sure you also disable any debug options (-g, -G) and enable the use_fast_math option in your CUDA code generation settings.

Make sure all build targets are 64-bit.

To your main issue: “Unresolved external function” errors normally indicate that you did not link against all necessary libraries.
You just seem to miss OptiX’ sutil library in your MSVS project’s linker settings.

I would still recommend to start using CMake to build all OptiX SDK examples first. I’m using CMake 3.7.1 for example.
Once you got that working, you can still build your own project manually and even peek into some working project settings to see what compiler and linker use.
The CUDA to PTX compilation is a custom build step though and you won’t see the code generation options for those inside the MSVS project, only inside the CMake files. Still you can use your own settings

Use the top-most CMakeLists.txt file you’ll find inside the OptiX SDK “<your_installation_path>\OptiX SDK 4.0.2\SDK” as root in CMake. It does some global configurations. That also contains the necessary documentation how to add own samples.
Using the CMakeLists.txt files inside the individual example folder would miss these global project settings.

For use with OptiX 4.0.2 I would highly recommend to use CUDA 7.5 (or 8.0 which also works but is not officially supported). CUDA 6.0 is pretty old already.

Hi Detlef,
Thanks for your advices.
Firstly, I updated to CUDA 7.5 and setup CMake 3.8.0.
I didn’t resolve working without Cmake because I didn’t see “sutil.lib” file in “Installation path\OptiX_SDK_4.0.2” directory. So I couldn’t add the library to MSVS project’s properties. Are you sure “sutil.lib” file is exist? Or can we add “.dll” files to our project properties link? If yes, I don’t know how can we do this.

Secondly, I setup the CMake 3.8.0. But I couldn’t success again. I read all step inside the OptiX SDK “<installation_path>\OptiX SDK 4.0.2\SDK” but It doesn’t work. CMake project configuration as belows;
“Source code” : "installation path\OptiX SDK 4.0.2\SDK "
“build the binaries”: “C:/Users/atilla/Desktop/optSdk/”
Configure: “Visual Studio 12 2013 Win64”
After these configuration I took this errors;

The C compiler identification is unknown
The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:82 (project):
No CMAKE_C_COMPILER could be found.
CMake Error at CMakeLists.txt:82 (project):
No CMAKE_CXX_COMPILER could be found.
Configuring incomplete, errors occurred!
See also “C:/Users/atilla/Desktop/optSdk/OptiX SDK 4.0.2/SDK/CMakeFiles/CMakeOutput.log”.
See also “C:/Users/atilla/Desktop/optSdk/OptiX SDK 4.0.2/SDK/CMakeFiles/CMakeError.log”.

CmakeOutput.log: The system is: Windows - 6.1.7601 - AMD64
CMakeError.log : Compiling the C compiler identification source file “CMakeCCompilerId.c” failed.
Compiler:
Build flags:
Id flags:
The output was:
The system cannot find the file specified
Compiling the CXX compiler identification source file “CMakeCXXCompilerId.cpp” failed.
Compiler:
Build flags:
Id flags:
The output was:
The system cannot find the file specified

Thanks,

I don’t know about the CMake 3.8.0 failure to find your host compiler. I’ve tried CMake 3.8.0 RC1 once and it failed to find some third party libraries, that’s why I stayed at 3.7.1 for now. Maybe give the previous release CMake 3.6.3 a try. That really needs to work first.

sutil comes as sources with the OptiX SDK. It’s a project inside the solution you generate with the top-most CMakeLists.txt file. There should be an sutil_sdk DLL project generated and its import library is linked by all other OptiX examples in the same solution.

For own projects there isn’t really a requirement to use the sutil code. My own OptiX applications for example use a completely different framework and only link against the core OptiX library.

There are some more examples to be found via this sticky post [url]https://devtalk.nvidia.com/default/topic/998546/optix/optix-advanced-samples-on-github/[/url]
Those are also using a different framework (GLFW and IMGUI). Read the INSTALL-WIN.txt text there for how to build them. (Don’t merge that code into the OptiX SDK folder. Keep it in a separate location.)

Thanks for your help Detlef,

I guess my problem is related to Cmake Configure. I selected Visual 11 2012 Win64 instead of Visual 12 2013 Win64, and it worked for SDK’s examples. After build and generate steps, I opened .sln projects with visual studio and I run those for make .exe files. Is this a right way to make a .run file? Can we build .exe file with Cmake?

Secondly I saw some problems when I build your example project. ( https://devtalk.nvidia.com/default/topic/998546/optix/optix-advanced-samples-on-github/)
I added to CmakeList.txt file this include path:
# Add the path to the OptiX headers to our include paths.
include_directories(
“${c:/Program Files/NVIDIA Corporation/OptiX SDK 4.0.2/}”

But When I push the Configure button I saw these lines;

[i]The C compiler identification is MSVC 17.0.50727.1
The CXX compiler identification is MSVC 17.0.50727.1
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 11.0/VC/bin/x86_amd64/cl.exe
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 11.0/VC/bin/x86_amd64/cl.exe – works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 11.0/VC/bin/x86_amd64/cl.exe
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 11.0/VC/bin/x86_amd64/cl.exe – works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
Found CUDA: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v7.5 (found suitable version “7.5”, minimum required is “7.0”)
Found OpenGL: opengl32
CMake Error at CMake/FindOptiX.cmake:99 (message):
optix library not found. Please locate before proceeding.
Call Stack (most recent call first):
CMake/FindOptiX.cmake:108 (OptiX_report_error)
CMakeLists.txt:200 (find_package)

Configuring incomplete, errors occurred!
See also “C:/Users/atilla/Desktop/Tez/ex2/CMakeFiles/CMakeOutput.log”.[/i]

I guess I couldnt add the optix path to Cmakelist.txt. How can I fix this problem?

For the latest question only:

Since the advanced samples are downloaded separately from OptiX itself, you need to tell CMake where you installed OptiX, via the “OptiX_INSTALL_DIR” variable. Notice this error in your log above:

I should probably change that message to also mention OptiX_INSTALL_DIR.

On Windows we look for OptiX libraries in a default location in “C:/ProgramData”, but maybe you installed OptiX somewhere else.

That’s actually not the path to the OptiX headers.
It should have been this in your case:
“${c:/Program Files/NVIDIA Corporation/OptiX SDK 4.0.2/include}”

The original CMakeLists.txt file should work without manual changes when following the INSTALL-WIN.txt descriptions of the advanced OptiX samples, where one step is to set the OptiX_INSTALL_DIR CMake variable.

Check how it’s used inside the FindOptiX.cmake file inside the examples’ CMake folder.
https://github.com/nvpro-samples/optix_advanced_samples/blob/master/src/CMake/FindOptiX.cmake