简体   繁体   中英

Resolving the Standard new/delete operators

Please see this question for some context: Linking unreferenced libraries breaks my program

I have the following program:

#include <iostream>

int main( int argc, char* argv[] )
{
    std::cout << "Hello world" << std::endl;

    int *p;
    p = new int(3);
    std::cout << *p << std::endl;
    delete p;

    return 0;
}

It works fine until I link to third-party libraries. When I link to the Abaqus libraries that I'll need in a much larger program, the above program crashes when trying to run delete p; . Using Dependency Walker, I found that the call to operator new is linked to an operator new definition provided by Abaqus. However, the call to operator delete is linked to the standard definition.

I have replaced new / delete with ::new / ::delete and get the same result.

Is there a way to resolve the standard new/delete operators? Alternatively, can I force Visual Studio to link to the correct (standard) definition of these operators?

指定链接器选项"/DEFAULTLIB:MSVCRT.LIB"会使程序成功执行。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM