Linking library without a header file?(没有头文件的链接库?)
问题描述
我正在尝试使用 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.
这篇关于没有头文件的链接库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:没有头文件的链接库?
基础教程推荐
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- CString 到 char* 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
