Unable to build tests against system-wide gtest, spirv-headers, spirv-tools, glslang libraries
Hello.
There are several issues when trying to build tests with shaderc @ a2c044c against system-wide gtest-1.8.0, spirv-headers @ 87a720a, spirv-tools @ ea7239f, glslang @ 2c8265b.
- Missing
-lgtestlink flag. First encountered error is:
[ 17%] Building CXX object libshaderc_util/CMakeFiles/shaderc_util_format_test.dir/src/format_test.cc.o
cd /var/tmp/portage/media-libs/shaderc-9999/work/shaderc-9999-abi_x86_64.amd64/libshaderc_util && /usr/bin/x86_64-pc-linux-gnu-g++ -I/include -I/var/tmp/portage/media-libs/shaderc-9999/work/shaderc-9999/libshaderc_util/include -DNDEBUG -O2 -march=native -mfpmath=sse -fomit-frame-pointer -pipe -frecord-gcc-switches -Wall -Werror -fvisibility=hidden -fPIC -std=c++11 -Wno-noexcept-type -o CMakeFiles/shaderc_util_format_test.dir/src/format_test.cc.o -c /var/tmp/portage/media-libs/shaderc-9999/work/shaderc-9999/libshaderc_util/src/format_test.cc
[ 19%] Linking CXX executable shaderc_util_format_test
cd /var/tmp/portage/media-libs/shaderc-9999/work/shaderc-9999-abi_x86_64.amd64/libshaderc_util && /usr/bin/cmake -E cmake_link_script CMakeFiles/shaderc_util_format_test.dir/link.txt --verbose=1
/usr/bin/x86_64-pc-linux-gnu-g++ -O2 -march=native -mfpmath=sse -fomit-frame-pointer -pipe -frecord-gcc-switches -Wl,--hash-style=gnu -Wl,-O1 -Wl,--as-needed -rdynamic CMakeFiles/shaderc_util_format_test.dir/src/format_test.cc.o -o shaderc_util_format_test libshaderc_util.a -lgmock -lgtest_main -lglslang -lOSDependent -lOGLCompiler -lglslang -lOSDependent -lOGLCompiler -lHLSL -lSPIRV -lSPIRV-Tools-opt -lSPIRV-Tools -lpthread
/usr/lib/gcc/x86_64-pc-linux-gnu/6.4.0/../../../../x86_64-pc-linux-gnu/bin/ld: CMakeFiles/shaderc_util_format_test.dir/src/format_test.cc.o: undefined reference to symbol '_ZN7testing8internal6IsTrueEb'
/usr/lib64/libgtest.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [libshaderc_util/CMakeFiles/shaderc_util_format_test.dir/build.make:96: libshaderc_util/shaderc_util_format_test] Error 1
Full build.log: https://paste.pound-python.org/show/pZ3uhOKrPGHhLjoFyYlF/
Problem: missing -lgtest link flag in test compile options.
Solution:
diff --git a/cmake/utils.cmake b/cmake/utils.cmake
index ed3c733..d461f41 100644
--- a/cmake/utils.cmake
+++ b/cmake/utils.cmake
@@ -4,7 +4,7 @@ function (shaderc_use_gmock TARGET)
target_include_directories(${TARGET} PRIVATE
${gmock_SOURCE_DIR}/include
${gtest_SOURCE_DIR}/include)
- target_link_libraries(${TARGET} PRIVATE gmock gtest_main)
+ target_link_libraries(${TARGET} PRIVATE gmock gtest gtest_main)
endfunction(shaderc_use_gmock)
function(shaderc_default_c_compile_options TARGET)
Continued in comments.
- Borked linking to glslang/SPIRV-Tools/pthread in tests
Adding
-lgtestas shown above allows the build to continue further only to throw another error:
[ 67%] Linking CXX executable shaderc_combined_shaderc_cpp_test
cd /var/tmp/portage/media-libs/shaderc-9999/work/shaderc-9999-abi_x86_64.amd64/libshaderc && /usr/bin/cmake -E cmake_link_script CMakeFiles/shaderc_combined_shaderc_cpp_test.dir/link.txt --verbose=1
/usr/bin/x86_64-pc-linux-gnu-g++ -O2 -march=native -mfpmath=sse -fomit-frame-pointer -pipe -frecord-gcc-switches -Wl,--hash-style=gnu -Wl,-O1 -Wl,--as-needed -rdynamic CMakeFiles/shaderc_combined_shaderc_cpp_test.dir/src/shaderc_cpp_test.cc.o -o shaderc_combined_shaderc_cpp_test libshaderc_combined.a -lpthread -lgmock -lgtest -lgtest_main
CMakeFiles/shaderc_combined_shaderc_cpp_test.dir/src/shaderc_cpp_test.cc.o: In function `(anonymous namespace)::EntryPointTest_SourceLangHlslMinimalHlslVertexShaderAsConstCharPtrSucceedsWithEntryPointName_Test::TestBody()':
shaderc_cpp_test.cc:(.text+0x1aa6a): undefined reference to `spvtools::SpirvTools::SpirvTools(spv_target_env)'
shaderc_cpp_test.cc:(.text+0x1aa85): undefined reference to `spvtools::SpirvTools::Disassemble(std::vector<unsigned int, std::allocator<unsigned int> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, unsigned int) const'
shaderc_cpp_test.cc:(.text+0x1aa94): undefined reference to `spvtools::SpirvTools::~SpirvTools()'
shaderc_cpp_test.cc:(.text+0x1ad2c): undefined reference to `spvtools::SpirvTools::~SpirvTools()'
CMakeFiles/shaderc_combined_shaderc_cpp_test.dir/src/shaderc_cpp_test.cc.o: In function `(anonymous namespace)::EntryPointTest_SourceLangHlslMinimalHlslVertexShaderAsStdStringSucceedsWithEntryPointName_Test::TestBody()':
shaderc_cpp_test.cc:(.text+0x1aefc): undefined reference to `spvtools::SpirvTools::SpirvTools(spv_target_env)'
shaderc_cpp_test.cc:(.text+0x1af17): undefined reference to `spvtools::SpirvTools::Disassemble(std::vector<unsigned int, std::allocator<unsigned int> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, unsigned int) const'
shaderc_cpp_test.cc:(.text+0x1af26): undefined reference to `spvtools::SpirvTools::~SpirvTools()'
shaderc_cpp_test.cc:(.text+0x1b24a): undefined reference to `spvtools::SpirvTools::~SpirvTools()'
libshaderc_combined.a(shaderc.cc.o): In function `shaderc_compiler_initialize':
shaderc.cc:(.text+0x7a0): undefined reference to `glslang::InitializeProcess()'
libshaderc_combined.a(shaderc.cc.o): In function `shaderc_compilation_result_spv_binary::~shaderc_compilation_result_spv_binary()':
shaderc.cc:(.text._ZN37shaderc_compilation_result_spv_binaryD2Ev[_ZN37shaderc_compilation_result_spv_binaryD5Ev]+0x17): undefined reference to `spvBinaryDestroy'
libshaderc_combined.a(shaderc.cc.o): In function `shaderc_compilation_result_spv_binary::~shaderc_compilation_result_spv_binary()':
shaderc.cc:(.text._ZN37shaderc_compilation_result_spv_binaryD0Ev[_ZN37shaderc_compilation_result_spv_binaryD5Ev]+0x13): undefined reference to `spvBinaryDestroy'
libshaderc_combined.a(spirv_tools_wrapper.cc.o): In function `shaderc_util::SpirvToolsOptimize(shaderc_util::Compiler::TargetEnv, std::vector<shaderc_util::PassId, std::allocator<shaderc_util::PassId> > const&, std::vector<unsigned int, std::allocator<unsigned int> >*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*)':
spirv_tools_wrapper.cc:(.text+0x322): undefined reference to `spvtools::Optimizer::Optimizer(spv_target_env)'
spirv_tools_wrapper.cc:(.text+0x4f6): undefined reference to `spvtools::Optimizer::SetMessageConsumer(std::function<void (spv_message_level_t, char const*, spv_position_t const&, char const*)>)'
spirv_tools_wrapper.cc:(.text+0x554): undefined reference to `spvtools::CreateStripDebugInfoPass()'
spirv_tools_wrapper.cc:(.text+0x55f): undefined reference to `spvtools::Optimizer::RegisterPass(spvtools::Optimizer::PassToken&&)'
spirv_tools_wrapper.cc:(.text+0x567): undefined reference to `spvtools::Optimizer::PassToken::~PassToken()'
spirv_tools_wrapper.cc:(.text+0x59b): undefined reference to `spvtools::Optimizer::Run(unsigned int const*, unsigned long, std::vector<unsigned int, std::allocator<unsigned int> >*) const'
spirv_tools_wrapper.cc:(.text+0x65a): undefined reference to `spvtools::Optimizer::~Optimizer()'
spirv_tools_wrapper.cc:(.text+0x694): undefined reference to `spvtools::CreateCompactIdsPass()'
spirv_tools_wrapper.cc:(.text+0x69f): undefined reference to `spvtools::Optimizer::RegisterPass(spvtools::Optimizer::PassToken&&)'
spirv_tools_wrapper.cc:(.text+0x6a7): undefined reference to `spvtools::Optimizer::PassToken::~PassToken()'
spirv_tools_wrapper.cc:(.text+0x6b4): undefined reference to `spvtools::Optimizer::RegisterLegalizationPasses()'
spirv_tools_wrapper.cc:(.text+0x6c4): undefined reference to `spvtools::Optimizer::RegisterSizePasses()'
spirv_tools_wrapper.cc:(.text+0x6d4): undefined reference to `spvtools::Optimizer::RegisterPerformancePasses()'
spirv_tools_wrapper.cc:(.text+0xa98): undefined reference to `spvtools::Optimizer::~Optimizer()'
spirv_tools_wrapper.cc:(.text+0xab0): undefined reference to `spvtools::Optimizer::PassToken::~PassToken()'
spirv_tools_wrapper.cc:(.text+0xabd): undefined reference to `spvtools::Optimizer::PassToken::~PassToken()'
libshaderc_combined.a(spirv_tools_wrapper.cc.o): In function `shaderc_util::SpirvToolsDisassemble(shaderc_util::Compiler::TargetEnv, std::vector<unsigned int, std::allocator<unsigned int> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*)':
spirv_tools_wrapper.cc:(.text+0xb90): undefined reference to `spvtools::SpirvTools::SpirvTools(spv_target_env)'
spirv_tools_wrapper.cc:(.text+0xd27): undefined reference to `spvtools::SpirvTools::SetMessageConsumer(std::function<void (spv_message_level_t, char const*, spv_position_t const&, char const*)>)'
spirv_tools_wrapper.cc:(.text+0xd51): undefined reference to `spvtools::SpirvTools::Disassemble(std::vector<unsigned int, std::allocator<unsigned int> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, unsigned int) const'
spirv_tools_wrapper.cc:(.text+0xf5b): undefined reference to `spvtools::SpirvTools::~SpirvTools()'
spirv_tools_wrapper.cc:(.text+0x1121): undefined reference to `spvtools::SpirvTools::~SpirvTools()'
libshaderc_combined.a(spirv_tools_wrapper.cc.o): In function `shaderc_util::SpirvToolsAssemble(shaderc_util::Compiler::TargetEnv, shaderc_util::string_piece, spv_binary_t**, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*)':
spirv_tools_wrapper.cc:(.text+0x11fc): undefined reference to `spvContextCreate'
spirv_tools_wrapper.cc:(.text+0x123d): undefined reference to `spvTextToBinary'
spirv_tools_wrapper.cc:(.text+0x1631): undefined reference to `spvDiagnosticDestroy'
spirv_tools_wrapper.cc:(.text+0x1639): undefined reference to `spvContextDestroy'
libshaderc_combined.a(compiler.cc.o): In function `shaderc_util::Compiler::PreprocessShader(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, shaderc_util::string_piece const&, shaderc_util::string_piece const&, shaderc_util::CountingIncluder&) const':
compiler.cc:(.text+0x409a): undefined reference to `glslang::TShader::TShader(EShLanguage)'
compiler.cc:(.text+0x40e5): undefined reference to `glslang::TShader::setStringsWithLengthsAndNames(char const* const*, int const*, char const* const*, int)'
compiler.cc:(.text+0x41d8): undefined reference to `glslang::TShader::preprocess(TBuiltInResource const*, int, EProfile, bool, bool, EShMessages, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, glslang::TShader::Includer&)'
compiler.cc:(.text+0x41ec): undefined reference to `glslang::TShader::getInfoLog()'
compiler.cc:(.text+0x42c5): undefined reference to `glslang::TShader::~TShader()'
compiler.cc:(.text+0x46d1): undefined reference to `glslang::TShader::getInfoLog()'
compiler.cc:(.text+0x4fe4): undefined reference to `glslang::TShader::~TShader()'
libshaderc_combined.a(compiler.cc.o): In function `shaderc_util::Compiler::Compile(shaderc_util::string_piece const&, EShLanguage, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const*, std::function<EShLanguage (std::ostream*, shaderc_util::string_piece const&)> const&, shaderc_util::CountingIncluder&, shaderc_util::Compiler::OutputType, std::ostream*, unsigned long*, unsigned long*, shaderc_util::GlslangInitializer*) const':
compiler.cc:(.text+0x58b1): undefined reference to `glslang::TShader::TShader(EShLanguage)'
compiler.cc:(.text+0x5903): undefined reference to `glslang::TShader::setStringsWithLengthsAndNames(char const* const*, int const*, char const* const*, int)'
compiler.cc:(.text+0x5920): undefined reference to `glslang::TShader::setEntryPoint(char const*)'
compiler.cc:(.text+0x5931): undefined reference to `glslang::TShader::setAutoMapBindings(bool)'
compiler.cc:(.text+0x5942): undefined reference to `glslang::TShader::setAutoMapLocations(bool)'
compiler.cc:(.text+0x5963): undefined reference to `glslang::TShader::setShiftImageBinding(unsigned int)'
compiler.cc:(.text+0x5978): undefined reference to `glslang::TShader::setShiftSamplerBinding(unsigned int)'
compiler.cc:(.text+0x598d): undefined reference to `glslang::TShader::setShiftTextureBinding(unsigned int)'
compiler.cc:(.text+0x59a2): undefined reference to `glslang::TShader::setShiftUboBinding(unsigned int)'
compiler.cc:(.text+0x59b7): undefined reference to `glslang::TShader::setShiftSsboBinding(unsigned int)'
compiler.cc:(.text+0x59cc): undefined reference to `glslang::TShader::setShiftUavBinding(unsigned int)'
compiler.cc:(.text+0x59dd): undefined reference to `glslang::TShader::setHlslIoMapping(bool)'
compiler.cc:(.text+0x59f2): undefined reference to `glslang::TShader::setResourceSetBinding(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&)'
compiler.cc:(.text+0x5a98): undefined reference to `glslang::TShader::parse(TBuiltInResource const*, int, EProfile, bool, bool, EShMessages, glslang::TShader::Includer&)'
compiler.cc:(.text+0x5aa7): undefined reference to `glslang::TShader::getInfoLog()'
compiler.cc:(.text+0x5b42): undefined reference to `glslang::TProgram::TProgram()'
compiler.cc:(.text+0x5b8c): undefined reference to `glslang::TProgram::link(EShMessages)'
compiler.cc:(.text+0x5ba0): undefined reference to `glslang::TProgram::mapIO(glslang::TIoMapResolver*)'
compiler.cc:(.text+0x5bae): undefined reference to `glslang::TProgram::getInfoLog()'
compiler.cc:(.text+0x5c70): undefined reference to `glslang::GlslangToSpv(glslang::TIntermediate const&, std::vector<unsigned int, std::allocator<unsigned int> >&, glslang::SpvOptions*)'
compiler.cc:(.text+0x5d97): undefined reference to `glslang::TProgram::~TProgram()'
compiler.cc:(.text+0x5d9f): undefined reference to `glslang::TShader::~TShader()'
compiler.cc:(.text+0x6a19): undefined reference to `glslang::TProgram::~TProgram()'
compiler.cc:(.text+0x6a24): undefined reference to `glslang::TShader::~TShader()'
collect2: error: ld returned 1 exit status
make[2]: *** [libshaderc/CMakeFiles/shaderc_combined_shaderc_cpp_test.dir/build.make:96: libshaderc/shaderc_combined_shaderc_cpp_test] Error 1
make[2]: Leaving directory '/var/tmp/portage/media-libs/shaderc-9999/work/shaderc-9999-abi_x86_64.amd64'
make[1]: *** [CMakeFiles/Makefile2:882: libshaderc/CMakeFiles/shaderc_combined_shaderc_cpp_test.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 68%] Linking CXX executable shaderc_shared_shaderc_test
cd /var/tmp/portage/media-libs/shaderc-9999/work/shaderc-9999-abi_x86_64.amd64/libshaderc && /usr/bin/cmake -E cmake_link_script CMakeFiles/shaderc_shared_shaderc_test.dir/link.txt --verbose=1
/usr/bin/x86_64-pc-linux-gnu-g++ -O2 -march=native -mfpmath=sse -fomit-frame-pointer -pipe -frecord-gcc-switches -Wl,--hash-style=gnu -Wl,-O1 -Wl,--as-needed -rdynamic CMakeFiles/shaderc_shared_shaderc_test.dir/src/shaderc_test.cc.o -o shaderc_shared_shaderc_test -Wl,-rpath,/var/tmp/portage/media-libs/shaderc-9999/work/shaderc-9999-abi_x86_64.amd64/libshaderc libshaderc_shared.so -lSPIRV-Tools -lgmock -lgtest -lgtest_main
/usr/lib/gcc/x86_64-pc-linux-gnu/6.4.0/../../../../x86_64-pc-linux-gnu/bin/ld: CMakeFiles/shaderc_shared_shaderc_test.dir/src/shaderc_test.cc.o: undefined reference to symbol 'pthread_create@@GLIBC_2.2.5'
/lib64/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [libshaderc/CMakeFiles/shaderc_shared_shaderc_test.dir/build.make:96: libshaderc/shaderc_shared_shaderc_test] Error 1
Full build.log: https://paste.pound-python.org/show/VjiFl3GvruE4RVhcqClu/ It seems there are two problems:
- shaderc_shared_shaderc_test fails to find pthreads during linking
- shaderc_combined_shaderc_cpp_test fails to find glslang and SPIRV-Tools during linking
The shaderc_shared_shaderc_test problem is easily fixed by:
diff --git a/libshaderc/CMakeLists.txt b/libshaderc/CMakeLists.txt
index 14da8ce..a4c1f76 100644
--- a/libshaderc/CMakeLists.txt
+++ b/libshaderc/CMakeLists.txt
@@ -59,7 +59,7 @@ shaderc_add_tests(
shaderc_add_tests(
TEST_PREFIX shaderc_shared
- LINK_LIBS shaderc_shared SPIRV-Tools
+ LINK_LIBS shaderc_shared ${CMAKE_THREAD_LIBS_INIT} SPIRV-Tools
INCLUDE_DIRS include ${shaderc_SOURCE_DIR}/libshaderc_util/include ${glslang_SOURCE_DIR}
${spirv-tools_SOURCE_DIR}/include
TEST_NAMES
However, simply adding glslang and SPIRV-Tools to linkflags for shaderc_combined_shaderc_cpp_test doesn't solve the above problem and I'm not sure why.
At first look seems like transitive library dependencies are not being picked up.
What version of CMake are you using?
3.9.6