NVlabs / instant-ngp

Instant neural graphics primitives: lightning fast NeRF and more
https://nvlabs.github.io/instant-ngp
Other
15.8k stars 1.9k forks source link

Error linking GLEW #986

Open roastduck opened 1 year ago

roastduck commented 1 year ago

Hi, I am building instant-ngp but it reports linking error against GLEW. In my case, CMake has already found GLEW (GLEW 2.2.0 installed via Spack):

-- Found GLEW: /home/spack/spack/opt/spack/linux-debian11-zen2/gcc-10.2.1/glew-2.2.0-ag6zl4i4osht5c72l27jxewoa5it3oqf/lib/cmake/glew/glew-config.cmake

But it is not linked successfully:

[56/57] Linking CXX executable testbed
FAILED: testbed
: && /usr/bin/g++ -fPIC -fopenmp -O3 -DNDEBUG  CMakeFiles/testbed.dir/src/main.cu.o -o testbed -L/home/spack/spack/opt/spack/linux-debian11-zen2/gcc-10.2.1/cuda-11.5.0-7ndmq24ccjlwllzf5l2hzgl7akc37pod/targets/x86_64-linux/lib/stubs libngp.a  -lGL  dependencies/glfw/src/CMakeFiles/glfw_objects.dir/./context.c.o  dependencies/glfw/src/CMakeFiles/glfw_objects.dir/./init.c.o  dependencies/glfw/src/CMakeFiles/glfw_objects.dir/./input.c.o  dependencies/glfw/src/CMakeFiles/glfw_objects.dir/./monitor.c.o  dependencies/glfw/src/CMakeFiles/glfw_objects.dir/./vulkan.c.o  dependencies/glfw/src/CMakeFiles/glfw_objects.dir/./window.c.o  dependencies/glfw/src/CMakeFiles/glfw_objects.dir/./x11_init.c.o  dependencies/glfw/src/CMakeFiles/glfw_objects.dir/./x11_monitor.c.o  dependencies/glfw/src/CMakeFiles/glfw_objects.dir/./x11_window.c.o  dependencies/glfw/src/CMakeFiles/glfw_objects.dir/./xkb_unicode.c.o  dependencies/glfw/src/CMakeFiles/glfw_objects.dir/./posix_time.c.o  dependencies/glfw/src/CMakeFiles/glfw_objects.dir/./posix_thread.c.o  dependencies/glfw/src/CMakeFiles/glfw_objects.dir/./glx_context.c.o  dependencies/glfw/src/CMakeFiles/glfw_objects.dir/./egl_context.c.o  dependencies/glfw/src/CMakeFiles/glfw_objects.dir/./osmesa_context.c.o  dependencies/glfw/src/CMakeFiles/glfw_objects.dir/./linux_joystick.c.o  -ldl  dependencies/tiny-cuda-nn/libtiny-cuda-nn.a  -lcuda  -lcublas  dependencies/tiny-cuda-nn/dependencies/fmt/libfmt.a  -lcudadevrt  -lcudart && :
/home/spack/spack/opt/spack/linux-debian11-zen2/clang-13.0.1/binutils-2.37-2o45cu3ly7nqvd37as4zwkufsaecopba/bin/ld: libngp.a(testbed.cu.o): in function `ngp::Testbed::draw_gui()::{lambda(ImDrawList const*, ImDrawCmd const*)#1}::_FUN(ImDrawList const*, ImDrawCmd const*)':
tmpxft_003ee13f_00000000-6_testbed.compute_86.cudafe1.cpp:(.text+0x7): undefined reference to `__glewBlendEquationSeparate'
/home/spack/spack/opt/spack/linux-debian11-zen2/clang-13.0.1/binutils-2.37-2o45cu3ly7nqvd37as4zwkufsaecopba/bin/ld: tmpxft_003ee13f_00000000-6_testbed.compute_86.cudafe1.cpp:(.text+0x1a): undefined reference to `__glewBlendFuncSeparate'
/home/spack/spack/opt/spack/linux-debian11-zen2/clang-13.0.1/binutils-2.37-2o45cu3ly7nqvd37as4zwkufsaecopba/bin/ld: libngp.a(testbed.cu.o): in function `ngp::Testbed::SecondWindow::draw(unsigned int)':

(more missing references omitted)

I notice the linking command here does not include -LGLEW at all. Is it by design or a bug?

The full CMake log is:

-- The C compiler identification is GNU 10.2.1
-- The CXX compiler identification is GNU 10.2.1
-- The CUDA compiler identification is NVIDIA 11.5.50
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/gcc - 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: /usr/bin/g++ - 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: /home/spack/spack/opt/spack/linux-debian11-zen2/gcc-10.2.1/cuda-11.5.0-7ndmq24ccjlwllzf5l2hzgl7akc37pod/bin/nvcc - skipped
-- Detecting CUDA compile features
-- Detecting CUDA compile features - done
-- No release type specified. Setting to 'Release'.
-- Automatic GPU detection failed. Building for common architectures.
-- Targeting GPU architectures: 35;50;52;60;61;70;75;80;86
CMake Warning at dependencies/tiny-cuda-nn/CMakeLists.txt:122 (message):
  Fully fused MLPs do not support GPU architectures of 70 or less.  Falling
  back to CUTLASS MLPs.  Remove GPU architectures 70 and lower to allow
  maximum performance

-- Module support is disabled.
-- Version: 9.0.0
-- Build type: Release
-- CXX_STANDARD: 14
-- Performing Test has_std_14_flag
-- Performing Test has_std_14_flag - Success
-- Performing Test has_std_1y_flag
-- Performing Test has_std_1y_flag - Success
-- Required features: cxx_variadic_templates
-- Could NOT find Vulkan (missing: Vulkan_LIBRARY Vulkan_INCLUDE_DIR)
CMake Warning at CMakeLists.txt:118 (message):
  Vulkan was not found.  Neural graphics primitives will still compile and
  run correctly, but DLSS will not be supported.

-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Using X11 for window creation
-- Found X11: /home/spack/spack/opt/spack/linux-debian11-zen2/gcc-10.2.1/xproto-7.0.31-ll4be6fqdxmjfhisuzms4oys222gap4i/include
-- Looking for XOpenDisplay in /home/spack/spack/opt/spack/linux-debian11-zen2/gcc-10.2.1/libx11-1.7.0-glmgafuwvufnbvva6rw7leqekeur24hc/lib/libX11.so;/home/spack/spack/opt/spack/linux-debian11-zen2/gcc-10.2.1/libxext-1.3.3-yefjovfn4iu4kva7ibv4t2evpxgfer3y/lib/libXext.so
-- Looking for XOpenDisplay in /home/spack/spack/opt/spack/linux-debian11-zen2/gcc-10.2.1/libx11-1.7.0-glmgafuwvufnbvva6rw7leqekeur24hc/lib/libX11.so;/home/spack/spack/opt/spack/linux-debian11-zen2/gcc-10.2.1/libxext-1.3.3-yefjovfn4iu4kva7ibv4t2evpxgfer3y/lib/libXext.so - found
-- Looking for gethostbyname
-- Looking for gethostbyname - found
-- Looking for connect
-- Looking for connect - found
-- Looking for remove
-- Looking for remove - found
-- Looking for shmat
-- Looking for shmat - found
-- Looking for IceConnectionNumber in ICE
-- Looking for IceConnectionNumber in ICE - found
-- Found GLEW: /home/spack/spack/opt/spack/linux-debian11-zen2/gcc-10.2.1/glew-2.2.0-ag6zl4i4osht5c72l27jxewoa5it3oqf/lib/cmake/glew/glew-config.cmake
-- Found OpenMP_C: -fopenmp (found version "4.5")
-- Found OpenMP_CXX: -fopenmp (found version "4.5")
-- Found OpenMP: TRUE (found version "4.5")
-- !!! Warning OptiX_INSTALL_DIR not set in environment. using default
-- OptiX_INSTALL_DIR value: /usr/local/NVIDIA-OptiX-SDK-7.5.0-linux64-x86_64
-- OptiX headers (optix.h and friends) not found.
CMake Warning at CMakeLists.txt:194 (message):
  OptiX was not found.  Neural graphics primitives will still compile and run
  correctly.  However, SDF training in 'raystab' and 'pathescape' modes will
  be significantly slower.

-- Found Python: /usr/bin/python3.9 (found suitable version "3.9.2", minimum required is "3.7") found components: Interpreter Development Development.Module Development.Embed
-- pybind11 v2.7.1
-- Performing Test HAS_FLTO
-- Performing Test HAS_FLTO - Success
-- Configuring done
-- Generating done
-- Build files have been written to: /home/rd/src/instant-ngp/build

Thanks in advance.

vincentcartillier commented 1 year ago

I had a similar issue where the compiler could not properly link to GLEW although it was installed.

I'm working on a cluster without sudo privilege and had to compile glew by hand. However, even after adding it to my envvars it wouldn't be found when compiling.

So I just manually set it in the CMakeLists.txt:

You can set the GLEW_INCLUDE_DIRS and BLEW_LIBRARIES manually before adding these into NGP. For instance you can add these two lines:

set(GLEW_INCLUDE_DIRS "/path-to-your-glew/glew-2.1.0/build/cmake/install/include")
set(GLEW_LIBRARIES "/path-to-your-glew/glew-2.1.0/build/cmake/install/lib/libGLEW.so")

right before L153/154

list(APPEND NGP_INCLUDE_DIRECTORIES ${GLEW_INCLUDE_DIRS})
list(APPEND` NGP_LIBRARIES GL ${GLEW_LIBRARIES} $<TARGET_OBJECTS:glfw_objects>)

This is pretty hacky but worked in my case.

gaoalexander commented 1 year ago

Chiming in that I also encountered the exact same issue, and had to follow the same steps that @vincentcartillier suggested above. This resolved the issue for me.

It's unclear what caused this issue, but uninstalling and reinstalling using apt was not effective. One thing I do notice is that whenever I install GLEW using sudo apt-get install libglew-dev, the libGLEW.so library file appears to be a broken symlink.

System Details: Ubuntu 20.04 cmake 3.21.7 gcc/g++ 9.4.0 NVIDIA RTX A5000 CUDA 11.6