github.com/0xKiwi/rules_go@v0.24.3/tests/legacy/examples/cgo/cc_dependency/cxx_version.cc (about) 1 #include <dlfcn.h> 2 #include <iostream> 3 4 #include "tests/legacy/examples/cgo/cc_dependency/version.h" 5 6 // TODO(yugui) Support Darwin too once Bazel allows it. 7 // 8 // Bazel passes two or more -Wl,-rpath to $(CC) when it links a binary with 9 // shared libraries prebuilt outside of Bazel (i.e. when "srcs" attribute of 10 // the dependency cc_library contains ".so" files). 11 // Unfortunately tools/cpp/osx_cc_wrapper.sh, which is $(CC) on Darwin, expects 12 // only one -Wl,-rpath. So the binary fails to resolve the shared libraries 13 // at runtime. 14 #ifndef __APPLE_CC__ 15 # include "tests/legacy/examples/cgo/cc_dependency/c_version.h" 16 #endif 17 18 extern "C" void PrintCXXVersion() { 19 #ifndef __APPLE_CC__ 20 PrintCVersion(); 21 #endif 22 void* ptr = dlsym(RTLD_DEFAULT, "PrintCXXVersion"); 23 if (ptr) { 24 std::cout 25 << "function ptr: " << std::hex << ptr << std::dec << std::endl; 26 } else { 27 std::cout << dlerror() << std::endl; 28 } 29 std::cout << "C++ version: " << __cplusplus << std::endl; 30 }