PixarAnimationStudios / OpenSubdiv

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

undefined reference to `glXGetCurrentContext' #1294

Closed RGBA-Research closed 1 year ago

RGBA-Research commented 1 year ago

Hello, We're aiming to compile OSD 3.5.0 on Ubuntu 20 against CUDA 11.7 for a Quadro RTX 4000 GPU. After changing compute_20 to compute_75 in CMakeLists.txt, we're hitting the following glX* related errors, whether GLEW and CUDA are on or off. Of course, we'd like CUDA on.

The error:

...
[ 37%] Built target examples_common_gl_obj
[ 38%] Generating mtlPtexCommon.gen.h
[ 39%] Generating glslPtexCommon.gen.h
[ 39%] Generating hlslPtexCommon.gen.h
[ 39%] Building CXX object examples/common/CMakeFiles/examples_common_ptex_obj.dir/ptexMipmapTextureLoader.cpp.o
[ 39%] Building CXX object examples/common/CMakeFiles/examples_common_ptex_obj.dir/glPtexMipmapTexture.cpp.o
[ 39%] Built target examples_common_ptex_obj
[ 39%] Generating shader_gl3.gen.h
[ 39%] Generating shader.gen.h
[ 40%] Building CXX object examples/glViewer/CMakeFiles/glViewer.dir/glViewer.cpp.o
[ 40%] Linking CXX executable ../../bin/glViewer
/usr/bin/ld: ../common/CMakeFiles/examples_common_gl_obj.dir/clDeviceContext.cpp.o: in function `CLDeviceContext::Initialize()':
clDeviceContext.cpp:(.text+0x4ed): undefined reference to `glXGetCurrentContext'
/usr/bin/ld: clDeviceContext.cpp:(.text+0x4f6): undefined reference to `glXGetCurrentDisplay'
/usr/bin/ld: ../common/CMakeFiles/examples_common_gl_obj.dir/cudaDeviceContext.cpp.o: in function `_GetCudaDeviceForCurrentGLContext()':
cudaDeviceContext.cpp:(.text+0x5b): undefined reference to `glXGetCurrentDisplay'
collect2: error: ld returned 1 exit status
make[2]: *** [examples/glViewer/CMakeFiles/glViewer.dir/build.make:156: bin/glViewer] Error 1
make[1]: *** [CMakeFiles/Makefile2:3767: examples/glViewer/CMakeFiles/glViewer.dir/all] Error 2
make: *** [Makefile:146: all] Error 2

Here's an example of the cmake command we've tried:

cmake \
-D CMAKE_CXX_STANDARD=14 \
-D CMAKE_INSTALL_PREFIX=/sw/builds/opensibdiv/3.5.0  \
-D CMAKE_BUILD_WITH_INSTALL_RPATH=True \
-D CMAKE_INSTALL_RPATH_USE_LINK_PATH=True \
-D PTEX_LOCATION=/sw/builds/ptex/2.4.2 \
-D CUDA_SDK_ROOT_DIR=/usr/local/cuda-11.7 \
-D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-11.7 \
-D GLFW_LOCATION=/sw/builds/glfw/3.3.8 \
-D TBB_INCLUDE_DIR=/sw/builds/tbb/2020.3/include \
-D TBB_tbb_LIBRARY=/sw/builds/tbb/2020.3/lib/libtbb.so \
-D NO_CLEW=ON \
-D NO_GLEW=ON \
-D CUDA_cupti_LIBRARY=/usr/local/cuda-11.7/lib64/libcupti.so \
-D CUDA_CUDA_LIBRARY=/usr/local/cuda-11.7/lib64/stubs/libcuda.so \
-D NO_MACOS_FRAMEWORK=ON \
-D NO_METAL=ON \
-D _OPENCL_CPP_INCLUDE_DIRS=/usr/local/cuda-11.7/include \
-D NO_REGRESSION=ON \
..

Thank you for having a look,

davidgyu commented 1 year ago

Filed as internal issue #OSD-406

davidgyu commented 1 year ago

I've been able to repro this on my Ubuntu 20.04 system and I was able to workaround the build error by adding the following line to the top-level CMakeLists.txt to have executables link with the glx library:

@@ -492,6 +492,7 @@ elseif(OPENGL_FOUND)
         ${PROJECT_SOURCE_DIR}/glLoader)
     set(OPENGL_LOADER_LIBRARIES
         ${OPENGL_gl_LIBRARY}
+        ${OPENGL_glx_LIBRARY}
         ${CMAKE_DL_LIBS})

We'll take a look at getting a proper fix merged. Recommend leaving GLEW support disabled. You're free to use GLEW in your own application, but it makes things cleaner to have OpenSubdiv itself not use GLEW. Thanks!

RGBA-Research commented 1 year ago

@davidgyu thank you for the quick reply and the workaround. It worked like a charm when building 3.4.4 and 3.5.0.

davidgyu commented 1 year ago

Great! Glad you have that working now!

davidgyu commented 1 year ago

Improved fix has been merged and verified in dev.