# How to add linker directories to cmake gtest\_discover\_tests

**URL:** <https://discourse.cmake.org/t/how-to-add-linker-directories-to-cmake-gtest-discover-tests/1704>\
**Category:** Code\
**Tags:** os:linux\
**Created:** [August 14, 2020, 12:21am UTC](https://discourse.cmake.org/t/how-to-add-linker-directories-to-cmake-gtest-discover-tests/1704 "2020-08-14T00:21:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gil.kalish](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/g/48db29/32.png) [@gil.kalish](https://discourse.cmake.org/u/gil.kalish)\
**Post date:** [August 14, 2020, 12:21am UTC](https://discourse.cmake.org/t/how-to-add-linker-directories-to-cmake-gtest-discover-tests/1704/1 "2020-08-14T00:21:29Z")

</div>

0

I’m using cmake and gtest for my project. My gtest executable is using the same name as the program executable. I know this is not ideal but I cannot change it.

The compiler I’m using is installed in a different directory than the system GCC (which is older). I’ve set the compiler path using:

```auto
set(CMAKE_C_COMPILER /opt/gcc-5.4.0/bin/gcc-5.4.0)
set(CMAKE_CXX_COMPILER /opt/gcc-5.4.0/bin/g++-5.4.0)

```

When linking my executable I’m using target\_link\_directories:

```auto
target_link_directories(target PUBLIC /opt/gcc-5.4.0/lib /opt/gcc-5.4.0/lib64)

```

Without gtest, the target compiles, links and runs properly, however when adding gtest:

```auto
  gtest_discover_tests(target WORKING_DIRECTORY <gtests_soruce_dir>)

```

The gtest target fails to link:

```auto
target: /lib64/libstdc++.so.6: version `CXXABI_1.3.8' not found (required by executable_name)
target: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by executable_name)
target: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by executable_name)
target: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by executable_name)

CMake Error at /home/gilkalish/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/202.6397.106/bin/cmake/linux/share/cmake-3.17/Modules/GoogleTestAddTests.cmake:40 (message):
  Error running test executable.

    Path: 'executable_path'
    Result: 1
    Output:

```

This is the very last step while linking gtest, after the executable was linked.

```auto
/home/gilkalish/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/202.6397.106/bin/cmake/linux/bin/cmake -D TEST_TARGET=target -D TEST_EXECUTABLE=/target_path/target -D TEST_EXECUTOR= -D TEST_WORKING_DIR=<gtest_source_dir> -D TEST_EXTRA_ARGS= -D TEST_PROPERTIES= -D TEST_PREFIX= -D TEST_SUFFIX= -D NO_PRETTY_TYPES=FALSE -D NO_PRETTY_VALUES=FALSE -D TEST_LIST=target_TESTS -D CTEST_FILE=/target_path/target[1]_tests.cmake -D TEST_DISCOVERY_TIMEOUT=5 -P /home/gilkalish/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/202.6397.106/bin/cmake/linux/share/cmake-3.17/Modules/GoogleTestAddTests.cmake

```

I can add the path to my custom GCC libraries using LD\_LIBRARY\_PATH, then linking works, but I would like to find a solution that will allow me to specify in cmake where to look for that libraries when linking the tests.

Also tried updating to cmake 3.18 that gave the same results. Any tips will be appreciated, Thanks!

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [January 4, 2021, 3:15pm UTC](https://discourse.cmake.org/t/how-to-add-linker-directories-to-cmake-gtest-discover-tests/1704/2 "2021-01-04T15:15:27Z")

</div>

CMake doesn’t “look for” standard libraries such as `libstdc++` generally. It’s up to the compiler to figure that out on its own. You shouldn’t need to add the link directories for them as the compiler should use the appropriate library for the compiler automatically. It seems that some other system library is adding the system path to the linker’s search paths and it finds that copy before the toolchain-provided one?
