没有头文件的链接库?

我正在尝试使用 Visual Studio 2010 链接 C++ 中的静态库.麻烦的是,库(和随附的标头)中有很多 MFC 对象.我想在不重新编译我的项目以包含 MFC 或重新编译库以不使用 MFC 的情况下调用库的函数之一.这篇 codeproject文章似乎暗示如果我这样做是可能的在我的项目中将函数定义为外部的(使用extern"关键字).

I'm attempting to link a static library in C++ using Visual Studio 2010. Trouble is, the library (and accompanying header ) have a lot of MFC objects in them. I would like to call one of the library's functions without recompiling my project to include MFC, or recompiling the library to not use MFC. This codeproject article seems to imply that this is possible if I define the function to be external in my project (using the "extern" keyword).

但是,我没有运气.无论我尝试什么,我都会收到未解决的外部符号错误.

However, I've had no luck. No matter what I try, I get an unresolved external symbol error.

文章是否正确?如果没有,这种联系是否可能以任何其他方式进行?

Is the article correct? And if not, is such linkage possible any other way?

推荐答案

你完全可以做到,你只需要找到完全正确的函数原型.

You can absolutely do this, you just have to find the exact right function prototype.

使用dumpbin"转储符号表,并查找您的函数.

Use "dumpbin" to dump the symbol table, and look for your function.

如果函数名看起来正常 - 然后定义它,并使用extern C"链接到它.如果符号是 c++ 损坏的,那么您将需要对它进行 demangle 以找到原型.

If the function name looks normal - then define it, and link to it using "extern C". If the symbol is c++ mangled, then you will need to demangle it to find the prototype.

如果函数不在符号表中 - 则它已在 lib 中静态定义,并且不可访问.那你就完蛋了.没办法.

If the function is not in the symbol table - then it has been defined statically in the lib, and is not accessible. Then you're hosed. There is no way.

相关文章