如果要使用 dlopen() 从 C 程序打开 C++ 共享库,应确保共享库依赖于适当的 C++ 运行时(对于 -compat=5,为 libCrun.so.1)。
为此,对于 -compat=5,在生成共享库时,应将 -lCrun 添加到命令行。例如:
example% CC -G -compat=5... -lCrun
如果使用 -compat=g、-std=c++03、-std=c++11 或 -std=c++14 选项,则需要改为链接 g++ 支持库:
example% CC -G -std=c++11 ... -lstdc++ -lgcc_s -lCrunG3
如果共享库使用了异常且不具有对 C++ 运行库的依赖性,则 C 程序可能会出现无规律的行为。