Hello,
I’am trying to build a hello world project with optix 9.0. However I am finding a difficulty to use.
(conan-env) aminated@aminated-HP-ZBook-Fury-17-3-inch-G8:~/Downloads/doc-optix/hello$ ./build.sh
======== Input profiles ========
Profile host:
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=gnu17
compiler.libcxx=libstdc++11
compiler.version=13
os=Linux
[options]
boost/:without_locale=True
boost/:without_stacktrace=True
Profile build:
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=gnu17
compiler.libcxx=libstdc++11
compiler.version=13
os=Linux
======== Computing dependency graph ========
Graph root
conanfile.txt: /home/aminated/Downloads/doc-optix/hello/conanfile.txt
======== Computing necessary packages ========
======== Installing packages ========
======== Finalizing install (deploy, generators) ========
conanfile.txt: Writing generators to /home/aminated/Downloads/doc-optix/hello/build/Release/generators
conanfile.txt: Generator ‘CMakeDeps’ calling ‘generate()’
conanfile.txt: Generator ‘CMakeToolchain’ calling ‘generate()’
conanfile.txt: CMakeToolchain generated: conan_toolchain.cmake
conanfile.txt: CMakeToolchain: Preset ‘conan-release’ added to CMakePresets.json.
(cmake>=3.23) cmake --preset conan-release
(cmake<3.23) cmake -G “Unix Makefiles” -DCMAKE_TOOLCHAIN_FILE=<output_folder>/generators/conan_toolchain.cmake -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_BUILD_TYPE=Release
conanfile.txt: CMakeToolchain generated: /home/aminated/Downloads/doc-optix/hello/build/Release/generators/CMakePresets.json
conanfile.txt: CMakeToolchain generated: /home/aminated/Downloads/doc-optix/hello/CMakeUserPresets.json
conanfile.txt: Generating aggregated env files
conanfile.txt: Generated aggregated env files: [‘conanbuild.sh’, ‘conanrun.sh’]
Install finished successfully
– Using Conan toolchain: /home/aminated/Downloads/doc-optix/hello/build/Release/generators/conan_toolchain.cmake
– Conan toolchain: Defining architecture flag: -m64
– Conan toolchain: C++ Standard 17 with extensions ON
– The CXX compiler identification is GNU 13.3.0
– The CUDA compiler identification is NVIDIA 12.9.86
– Detecting CXX compiler ABI info
– Detecting CXX compiler ABI info - done
– Check for working CXX compiler: /usr/bin/c++ - skipped
– Detecting CXX compile features
– Detecting CXX compile features - done
– Detecting CUDA compiler ABI info
– Detecting CUDA compiler ABI info - done
– Check for working CUDA compiler: /usr/local/cuda-12.9/bin/nvcc - skipped
– Detecting CUDA compile features
– Detecting CUDA compile features - done
– Using OptiX from: /home/aminated/Downloads/optix
CMake Error at CMakeLists.txt:25 (find_library):
Could not find OPTIX_LIB using the following names: optix
-- Configuring incomplete, errors occurred!
ninja: error: loading ‘build.ninja’: No such file or directory
(conan-env) aminated@aminated-HP-ZBook-Fury-17-3-inch-G8:~/Downloads/doc-optix/hello$ ./build.sh
======== Input profiles ========
Profile host:
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=gnu17
compiler.libcxx=libstdc++11
compiler.version=13
os=Linux
[options]
boost/:without_locale=True
boost/:without_stacktrace=True
Profile build:
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=gnu17
compiler.libcxx=libstdc++11
compiler.version=13
os=Linux
======== Computing dependency graph ========
Graph root
conanfile.txt: /home/aminated/Downloads/doc-optix/hello/conanfile.txt
======== Computing necessary packages ========
======== Installing packages ========
======== Finalizing install (deploy, generators) ========
conanfile.txt: Writing generators to /home/aminated/Downloads/doc-optix/hello/build/Release/generators
conanfile.txt: Generator ‘CMakeDeps’ calling ‘generate()’
conanfile.txt: Generator ‘CMakeToolchain’ calling ‘generate()’
conanfile.txt: CMakeToolchain generated: conan_toolchain.cmake
conanfile.txt: CMakeToolchain: Preset ‘conan-release’ added to CMakePresets.json.
(cmake>=3.23) cmake --preset conan-release
(cmake<3.23) cmake -G “Unix Makefiles” -DCMAKE_TOOLCHAIN_FILE=<output_folder>/generators/conan_toolchain.cmake -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_BUILD_TYPE=Release
conanfile.txt: CMakeToolchain generated: /home/aminated/Downloads/doc-optix/hello/build/Release/generators/CMakePresets.json
conanfile.txt: CMakeToolchain generated: /home/aminated/Downloads/doc-optix/hello/CMakeUserPresets.json
conanfile.txt: Generating aggregated env files
conanfile.txt: Generated aggregated env files: [‘conanbuild.sh’, ‘conanrun.sh’]
Install finished successfully
– Using Conan toolchain: /home/aminated/Downloads/doc-optix/hello/build/Release/generators/conan_toolchain.cmake
– Conan toolchain: Defining architecture flag: -m64
– Conan toolchain: C++ Standard 17 with extensions ON
– The CXX compiler identification is GNU 13.3.0
– The CUDA compiler identification is NVIDIA 12.9.86
– Detecting CXX compiler ABI info
– Detecting CXX compiler ABI info - done
– Check for working CXX compiler: /usr/bin/c++ - skipped
– Detecting CXX compile features
– Detecting CXX compile features - done
– Detecting CUDA compiler ABI info
– Detecting CUDA compiler ABI info - done
– Check for working CUDA compiler: /usr/local/cuda-12.9/bin/nvcc - skipped
– Detecting CUDA compile features
– Detecting CUDA compile features - done
– Using OptiX from: /home/aminated/Downloads/optix
– Found CUDAToolkit: /usr/local/cuda-12.9/targets/x86_64-linux/include (found version “12.9.86”)
– Performing Test CMAKE_HAVE_LIBC_PTHREAD
– Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
– Found Threads: TRUE
– Configuring done (2.0s)
– Generating done (0.0s)
– Build files have been written to: /home/aminated/Downloads/doc-optix/hello/build
[0/2] Re-checking globbed directories…
[2/2] Linking CXX executable hello
FAILED: hello
: && /usr/bin/c++ -m64 -O3 -DNDEBUG -m64 CMakeFiles/hello.dir/src/hello.cpp.o -o hello -Wl,-rpath,/usr/local/cuda-12.9/targets/x86_64-linux/lib /usr/local/cuda-12.9/targets/x86_64-linux/lib/libcudart.so && :
/usr/bin/ld: CMakeFiles/hello.dir/src/hello.cpp.o: warning: relocation against g_optixFunctionTable_105' in read-only section .text.startup’
/usr/bin/ld: CMakeFiles/hello.dir/src/hello.cpp.o: in function main': hello.cpp:(.text.startup+0x43): undefined reference to g_optixFunctionTable_105’
/usr/bin/ld: hello.cpp:(.text.startup+0x7c): undefined reference to g_optixFunctionTable_105' /usr/bin/ld: hello.cpp:(.text.startup+0xad): undefined reference to g_optixFunctionTable_105’
/usr/bin/ld: hello.cpp:(.text.startup+0xcc): undefined reference to `g_optixFunctionTable_105’
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
(conan-env) aminated@aminated-HP-ZBook-Fury-17-3-inch-G8:~/Downloads/doc-optix/hello$ echo $LD_LIBRARY_PATH
:/usr/local/cuda-12.9/lib64:/usr/local/cuda-12.9/lib64
(conan-env) aminated@aminated-HP-ZBook-Fury-17-3-inch-G8:~/Downloads/doc-optix/hello$ echo $OPTI
$OPTIND $OPTIX_ROOT
(conan-env) aminated@aminated-HP-ZBook-Fury-17-3-inch-G8:~/Downloads/doc-optix/hello$ echo $OPTIX_ROOT
/home/aminated/Downloads/optix
(conan-env) aminated@aminated-HP-ZBook-Fury-17-3-inch-G8:~/Downloads/doc-optix/hello$ ls $OPTIX_ROOT
build doc environment.yml env.sh include lib64 license_info.txt OptiX_EndUserLicense.pdf OptiX_ThirdParty_Licenses.txt README.md SDK
#include <optix.h>
#include <optix_stubs.h>
#include <iostream>
#define OPTIX_CHECK(call) \
do { \
OptixResult res = call; \
if (res != OPTIX_SUCCESS) { \
std::cerr << "OptiX error: " << res << "\n"; \
exit(1); \
} \
} while(0)
int main()
{
std::cout << "Starting OptiX test...\n";
// Init OptiX (THIS is where your error happens if linking is wrong)
OPTIX_CHECK(optixInit());
std::cout << "OptiX initialized successfully!\n";
// Create context
OptixDeviceContext context = nullptr;
OPTIX_CHECK(optixDeviceContextCreate(0, nullptr, &context));
std::cout << "Device context created!\n";
optixDeviceContextDestroy(context);
std::cout << "Done.\n";
return 0;
}
cmake_minimum_required(VERSION 3.20)
project(optix_shadow LANGUAGES CXX CUDA)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# -------------------------------------------------------
# OptiX
# -------------------------------------------------------
if(NOT DEFINED ENV{OPTIX_ROOT})
message(FATAL_ERROR "OPTIX_ROOT not set. Export it before running CMake.")
endif()
set(OPTIX_ROOT $ENV{OPTIX_ROOT})
message(STATUS "Using OptiX from: ${OPTIX_ROOT}")
find_path(OPTIX_INCLUDE_DIR
optix.h
HINTS ${OPTIX_ROOT}/include
REQUIRED
)
# -------------------------------------------------------
# OptiX Library
# -------------------------------------------------------
#find_library(OPTIX_LIB
# NAMES optix
# HINTS ${OPTIX_ROOT}/lib64
# REQUIRED
#)
# -------------------------------------------------------
# CUDA
# -------------------------------------------------------
find_package(CUDAToolkit REQUIRED)
# -------------------------------------------------------
# Sources
# -------------------------------------------------------
file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS
src/*.cpp
)
#--------------------------------------------------------
# hello binary
# -------------------------------------------------------
add_executable(hello ${SOURCES})
target_include_directories(hello PRIVATE
${TENSORRT_INCLUDE_DIR}
${OPTIX_INCLUDE_DIR}
)
target_link_libraries(hello PRIVATE
CUDA::cudart
# ${OPTIX_LIB}
)
rm -rf build
conan install . --output-folder=. --build=missing -o boost/*:without_locale=True -o boost/*:without_stacktrace=True
cmake -S . -B build \
-G Ninja \
-DCMAKE_TOOLCHAIN_FILE=build/Release/generators/conan_toolchain.cmake \
-DCMAKE_BUILD_TYPE=Release
cmake --build build
Regards