KhronosGroup / glslang

Khronos-reference front end for GLSL/ESSL, partial front end for HLSL, and a SPIR-V generator.
Other
2.98k stars 823 forks source link

GCC: libglslang.so: undefined references to SPIRV symbols #2196

Closed SpaceIm closed 1 week ago

SpaceIm commented 4 years ago

I'm trying to package glslang 8.13.3743 for conan. In this toy example, glslang built as a shared lib has undefined references to SPIRV symbols:

#include <glslang/Public/ShaderLang.h>

int main() {
  glslang::InitializeProcess();
  glslang::FinalizeProcess();

  return 0;
}
/usr/bin/g++  -D_GLIBCXX_USE_CXX11_ABI=0 -I/home/conan/.conan/data/glslang/8.13.3743/bincrafters/testing/package/0ca46b311c6e6214ad3d5b94605bf07700736de1/include  -m64 -O3 -DNDEBUG    -DENABLE_HLSL -std=gnu++11 -o CMakeFiles/test_package.dir/test_package.cpp.o -c /home/conan/project/test_package/test_package.cpp
[100%] Linking CXX executable bin/test_package
/usr/bin/cmake -E cmake_link_script CMakeFiles/test_package.dir/link.txt --verbose=1
/usr/bin/g++    -m64 -O3 -DNDEBUG        -rdynamic CMakeFiles/test_package.dir/test_package.cpp.o  -o bin/test_package   -L/home/conan/.conan/data/glslang/8.13.3743/bincrafters/testing/package/0ca46b311c6e6214ad3d5b94605bf07700736de1/lib  -Wl,-rpath,/home/conan/.conan/data/glslang/8.13.3743/bincrafters/testing/package/0ca46b311c6e6214ad3d5b94605bf07700736de1/lib -lSPIRV -lglslang -lOGLCompiler -lOSDependent -lSPVRemapper -lHLSL -lpthread 
/usr/bin/ld: /home/conan/.conan/data/glslang/8.13.3743/bincrafters/testing/package/0ca46b311c6e6214ad3d5b94605bf07700736de1/lib/libglslang.so: undefined reference to `spv::SpvBuildLogger::getAllMessages() const'
/usr/bin/ld: /home/conan/.conan/data/glslang/8.13.3743/bincrafters/testing/package/0ca46b311c6e6214ad3d5b94605bf07700736de1/lib/libglslang.so: undefined reference to `glslang::GlslangToSpv(glslang::TIntermediate const&, std::vector<unsigned int, std::allocator<unsigned int> >&, spv::SpvBuildLogger*, glslang::SpvOptions*)'
collect2: error: ld returned 1 exit status

As you can see I assume that SPIRV depends on glslang, based on CMakeLists.txt in SPIRV folder: https://github.com/KhronosGroup/glslang/blob/bcf6a2430e99e8fc24f9f266e99316905e6d5134/SPIRV/CMakeLists.txt#L67

So now I'm confused, does glslang depend on SPIRV (and SPIRV on glslang)?

I didn't have these undefined symbols with 8.13.3559 with the same linking order.

EDIT: Seems like this dependency of glslang to SPIRV comes from this new compilation unit in glslang target: glslang_c_interface.cpp. If internal implementation of C interface depends on glslang and SPIRV, while SPIRV depends on glslang, it would be probably a better idea to have a new specific lib for C interface in order to break circular dependencies, something like this:

add_library(glslang-c CInterface/glslang_c_interface.cpp)
target_link_libraries(glslang-c PRIVATE SPIRV glslang)
...
zeno-endemann-kdab commented 1 year ago

More generally I'd like to see the different cmake targets of glslang be documented. Some are kind of self-explanatory, but for some it is not clear which one's you are supposed to use for a given task. Alternatively (or additionally) it would be good to have the headers belonging to a specific target be in a subdir indicating what target it belongs to. Then one can deduce what target to link against by what headers one used.

arcady-lunarg commented 1 week ago

libglslang.so and libSPIRV.so have been combined into one library, so this shouldn't be an issue anymore.