diff options
Diffstat (limited to 'tests/legacy/examples/cgo/cc_dependency/cxx_version.cc')
-rw-r--r-- | tests/legacy/examples/cgo/cc_dependency/cxx_version.cc | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/legacy/examples/cgo/cc_dependency/cxx_version.cc b/tests/legacy/examples/cgo/cc_dependency/cxx_version.cc new file mode 100644 index 00000000..43fb427e --- /dev/null +++ b/tests/legacy/examples/cgo/cc_dependency/cxx_version.cc @@ -0,0 +1,30 @@ +#include <dlfcn.h> +#include <iostream> + +#include "tests/legacy/examples/cgo/cc_dependency/version.h" + +// TODO(yugui) Support Darwin too once Bazel allows it. +// +// Bazel passes two or more -Wl,-rpath to $(CC) when it links a binary with +// shared libraries prebuilt outside of Bazel (i.e. when "srcs" attribute of +// the dependency cc_library contains ".so" files). +// Unfortunately tools/cpp/osx_cc_wrapper.sh, which is $(CC) on Darwin, expects +// only one -Wl,-rpath. So the binary fails to resolve the shared libraries +// at runtime. +#ifndef __APPLE_CC__ +# include "tests/legacy/examples/cgo/cc_dependency/c_version.h" +#endif + +extern "C" void PrintCXXVersion() { +#ifndef __APPLE_CC__ + PrintCVersion(); +#endif + void* ptr = dlsym(RTLD_DEFAULT, "PrintCXXVersion"); + if (ptr) { + std::cout + << "function ptr: " << std::hex << ptr << std::dec << std::endl; + } else { + std::cout << dlerror() << std::endl; + } + std::cout << "C++ version: " << __cplusplus << std::endl; +} |