Skip to content

Commit 484d07a

Browse files
authored
fix: Add runtime_library_search_directories for QNX dynamic linking (#14)
QNX toolchain requires -Wl,-rpath instead of -rpath for runtime library paths. This enables cc_shared_library and dynamic linking support.
1 parent 93f443c commit 484d07a

3 files changed

Lines changed: 39 additions & 1 deletion

File tree

examples/BUILD

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,21 @@ cc_test(
3535
name = "math_lib_test",
3636
srcs = ["math_lib_test.cpp"],
3737
deps = [":math_lib"],
38+
linkstatic = True,
39+
)
40+
41+
cc_shared_library(
42+
name = "math_lib_shared",
43+
shared_lib_name = "libmath_lib.so",
44+
deps = [":math_lib"],
45+
)
46+
47+
cc_test(
48+
name = "math_lib_dyn_test",
49+
srcs = ["math_lib_test.cpp"],
50+
deps = [":math_lib"],
51+
dynamic_deps = [":math_lib_shared"],
52+
linkstatic = False,
3853
)
3954

4055
cc_test(
@@ -45,4 +60,4 @@ cc_test(
4560
"@googletest//:gtest",
4661
"@googletest//:gtest_main",
4762
]
48-
)
63+
)

examples/math_lib_test.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
********************************************************************************/
1313

1414
#include "math_lib.h"
15+
#include <iostream>
1516
#include <cassert>
1617

1718
int main() {
1819
assert(add(2, 3) == 5);
1920
assert(sub(5, 3) == 2);
21+
std::cout << "add(2, 3) = " << add(2, 3) << std::endl;
2022

2123
// Note: sub(3, 5) is NOT tested → coverage will show a missed branch
2224
return 0;

templates/qnx/cc_toolchain_config.bzl.template

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,26 @@ def _impl(ctx):
399399
],
400400
)
401401

402+
# QNX uses -Wl,-rpath instead of -rpath
403+
runtime_library_search_directories_feature = feature(
404+
name = "runtime_library_search_directories",
405+
flag_sets = [
406+
flag_set(
407+
actions = all_link_actions,
408+
flag_groups = [
409+
flag_group(
410+
iterate_over = "runtime_library_search_directories",
411+
flag_groups = [
412+
flag_group(
413+
flags = ["-Wl,-rpath,$EXEC_ORIGIN/%{runtime_library_search_directories}"],
414+
),
415+
],
416+
),
417+
],
418+
),
419+
],
420+
)
421+
402422
# The order of the features is relevant, they are applied in this specific order.
403423
# A command line parameter from a feature at the end of the list will appear
404424
# after a command line parameter from a feature at the beginning of the list.
@@ -420,6 +440,7 @@ def _impl(ctx):
420440
use_license_env_info_feautre,
421441
sdp_env_feature,
422442
supports_pic_feature,
443+
runtime_library_search_directories_feature,
423444
]
424445

425446
cxx_builtin_include_directories = [

0 commit comments

Comments
 (0)