Skip to content

Commit 7ada935

Browse files
committed
[Build] Fix GCC C++ linkage
The OpenAssetIO C library depends on the C++ library, which in turn depends on the C++ standard library. If the C++ standard library cannot be found in the linker's search paths, then linking will fail. In particular, on Linux this means that libstdc++ must be discoverable. On many system layouts, including CI, this hasn't been a problem, presumably because libstdc++ happens to be in the default search paths added by `gcc`. However, `gcc` (as opposed to `g++`) does not explicitly add the location of libstdc++ to the search paths. So on some system layouts (in particular, on my local setup using a Conda sandbox environment) linking via `gcc` will fail. The correct thing to do seems to be to inform CMake that C++-style linking is required, so that linking is performed via `g++`, rather than `gcc`. Compilation of the C code still happens using `gcc`, but linking is performed via `g++`. Signed-off-by: David Feltell <[email protected]>
1 parent 2e3495d commit 7ada935

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ if (OPENASSETIOTEST_ENABLE_C)
142142
add_executable(test.c.core src/test.core.c)
143143
add_test(c.core test.c.core)
144144
target_link_libraries(test.c.core PRIVATE OpenAssetIO::openassetio-core-c)
145+
# Must use C++ linker settings or the C++ standard library might not
146+
# be linked. This is required since openassetio-core-c depends on
147+
# openassetio-core, which is a C++ library.
148+
set_target_properties(test.c.core PROPERTIES LINKER_LANGUAGE CXX)
145149
target_compile_features(test.c.core PRIVATE c_std_99)
146150
if (WIN32 AND DEFINED OpenAssetIO_BINARY_DIR)
147151
set_tests_properties(c.core PROPERTIES ENVIRONMENT "PATH=${OpenAssetIO_BINARY_DIR_NATIVE}")

RELEASE_NOTES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ v1.0.0-alpha.x
1717
* CI testing added to exercise convergent dependency acquisition modes.
1818
[#7](https://github.com/OpenAssetIO/OpenAssetIO-Test-CMake/pull/7)
1919

20+
### Bug Fixes
21+
22+
* Updated build configuration such that C API tests use the C++ linker,
23+
fixing issues where the C++ standard library is not found on the
24+
default C linker search paths.
25+
[#14](https://github.com/OpenAssetIO/OpenAssetIO-Test-CMake/pull/14)
2026

2127
v1.0.0-alpha.1
2228
--------------

0 commit comments

Comments
 (0)