Using core libstd++ library with cmake

See also VSCode glibc++6 Needs Update?

Info:
Ubuntu 20.04.2 LTS (focal)
core is currently using GLIBCXX_3.4.21 as shown above.
non-core libstdc++.so.6 contains GLIBCXX_3.4.28 as above.

I’m compiling a large project using node native code. The snap core library is at GLIBVXX_3.4.21 but other components in my project (e.g. jsoncpp and the c++ functions) are in GLIBCXX_3.4.28.

Note: I am not building a snap. I am trying to build a native module for node. When node runs it runs in an isolated environment and so it links to the core libstdc++.so which is out of date.
I’m using clion and cmake.

Note: my code works fine for Python and Ruby native modules since those are not in snap.

How do I configure cmake to use the snap core libraries instead of the ones in Ubuntu’s /usr/lib ?

I have tried:

  • target_link_options() with -rpath
  • target_link_options() -rpath-link
  • target_link_libraries() with the full path to the libstdc++.so.6
  • target_link_directories() with path /snap/core/current/usr/lib/x86_64-linux-gnu/
  • setting CMAKE_INSTALL_RPATH and CMAKE_INSTALL_RPATH_USE_LINK_PATH
  • setting CMAKE_PREFIX_PATH to /snap/core/current/usr/lib/x86_64-linux-gnu/