Skip to content

Unable to build tests against system-wide gtest, spirv-headers, spirv-tools, glslang libraries #470

@Coacher

Description

@Coacher

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.

  1. Missing -lgtest link 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions