force visual studio to link all symbols in a lib file(强制 Visual Studio 链接 lib 文件中的所有符号)
问题描述
有什么方法可以强制 Visual Studio 将 lib 文件中的所有符号链接到 dll 中,因为 atm 它正在优化程序在运行时使用 dll 所需的未使用"功能.
Is there any way to force visual studio to link all symbols from a lib file into the dll as atm it is optimizing "unused" functions which are needed by the program using the dll at run time.
我尝试使用/OPT:NOREF 和/OPT:NOICF 但它们似乎不起作用.
I tried using the /OPT:NOREF and /OPT:NOICF but they dont seem to work.
我需要它们的原因是因为它们是全局类,它们向控制器注册它们自己,并且它们没有在 dll 中链接.
The reason i need them is because they are global class which register them selves with a controller and they are not being linked in the dll.
推荐答案
我不知道Visual Studio中是否有更优雅的方式,但是我们使用它的跨平台解决方案有两个宏来强制问题对象要链接的文件.
I don't know if there's a more elegant way in Visual Studio, but the cross-platform solution we use it to have two macros that force the problamatic object file to be linked.
一个放在要排除的函数的源文件中,另一个放在链接器知道将被调用的函数中.
One is placed in the source file of functions that are being excluded, the other is placed in a function that the linker knows will be called.
类似的东西;
#define FORCE_LINK_THIS(x) int force_link_##x = 0;
#define FORCE_LINK_THAT(x) { extern int force_link_##x; force_link_##x = 1; }
这不是很优雅,但我们还没有找到一个更好的跨平台工作的解决方案.
It's not exactly elegant, but we haven't found a better solution that works across platforms.
这篇关于强制 Visual Studio 链接 lib 文件中的所有符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:强制 Visual Studio 链接 lib 文件中的所有符号
基础教程推荐
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- CString 到 char* 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
