忽略全局覆盖的新/删除 [英] Ignore globally overridden new/delete
问题描述
我正在使用一个全局覆盖了new/delete的库.但是我对该库有问题,问题在于必须在主函数中手动对其进行初始化.
Hi I'm using a library that has globally overridden new/delete. But I have a problem with this library, the problem is that it has to be manually initialized in the main function.
现在,我正在尝试使用另一个在调用main之前初始化一些函数的库,不幸的是,该库在这些函数中使用了new.因此出现错误是因为使用覆盖的new/delete关键字的内存管理器尚未初始化.
Now I'm trying to use another library that initializes a few functions before main is called, unfortunately this library uses new within these functions. So I get errors because the memory manager that uses the overridden new/delete keywords are not initialized yet.
我真的很想使用默认的内存管理器,因为我想向该库添加单元测试.使用我要测试的库以及单元测试库使用的内存并没有多大意义.
I'd really like to use the default memory manager because I want to add unit testing to this library. It would not make much sense to use the memory used my the library I want to test also used by my Unit Testing library.
所以我的问题是,包括第二个库时是否可以忽略全局覆盖的new/delete,而仅使用默认的new/delete?
So my question is if it's possible to ignore global overridden new/delete when including the second library and just use the default new/delete?
我正在Windows 7和标准C ++编译器上使用Visual Studio 2010.
I'm using visual studio 2010 on Windows 7 with the standard C++ compiler.
推荐答案
如果不修改库本身,我认为这是不可能的.我猜这是关于静态库的(在dll中,被dll内部的函数指向的是覆盖的new/delete.)
I do not think this is possible without modifying the library itself. I guess it is about a static library (inside a dll, the overridden new/delete will be pointed by the functions inside the dll.)
您可以使用命令(Visual命令提示符)从静态库中删除obj文件:
You can remove an obj file from a static library by using the command (Visual command prompt):
LIB /REMOVE:obj_to_remove /OUT:removed.lib input.lib
要找出要删除的obj,请先运行:
To find out what obj to remove, first run:
DUMPBIN /ARCHIVEMEMBERS input.lib
您将看到诸如
Archive member name at 14286: /0 compilation.dir\objfile1.obj
14286
'标识'obj文件.要查看每个符号的位置,请运行:
14286
'identifies' the obj file. To see where each symbol is, run:
DUMPBIN /LINKERMEMBER:1 input.lib > members.txt
并查找新的/删除的. members.txt
将包含每个符号的错误名称和该符号所在的obj的标识符.例如
and look for the new/delete. members.txt
will contains the mangled names of each symbols and an identifier of the obj in which this symbol is. For instance
14286 ?_Rank@?$_Arithmetic_traits@C@std@@2HB
14286
告诉您符号所在的obj'identifier'.如果找不到新的/删除的,可以运行:
The 14286
is telling you the obj 'identifier' in which the symbol lies. If you have trouble finding new/delete, you can run:
DUMPBIN /SYMBOLS input.lib > sym.txt
,这将冲刷到sym.txt
每个符号的变形和未破坏的名称中.
which will flush into sym.txt
the mangled and unmangled names for each symbol.
最后,在我们的示例中,将obj_to_remove
替换为compilation.dir\objfile1.obj
,并使用上述LIB
命令删除obj文件,然后链接到removed.lib
.
At the end, remove the obj file with the LIB
command above by replacing obj_to_remove
by compilation.dir\objfile1.obj
in our example, and link against removed.lib
.
现在,如果您不走运,则所需的其他符号可能与新建/删除对象位于同一目标文件中.在这种情况下,您可以使用 this "a>(例如将new
重命名为dew
,将delete
重命名为nelete
.)
Now, if you are not lucky, other symbols you need may be in the same object file as the new/delete. In that case, you can "hack" the lib using something like this (say renaming new
to dew
and delete
to nelete
.)
这篇关于忽略全局覆盖的新/删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!