所以我通过将编译参数更改为:
g++ -static bar.cpp -o bar -L./ -lfoo
您必须声明使用其他C函数的函数 extern "C" 或者C ++名称修改会“扭曲”你的名字。更多信息: http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/index.jsp?topic=%2Fcom.ibm.vacpp6m.doc%2Flanguage%2Fref%2Fclrc01name_mangling.htm
extern "C"