2

Language : C++

OS : Windows 7/10

I use a third party library that calls the system method exit() which quits the application. How can I override that behavior so that instead of the system exit(), some other method is called, for example I can provide a different implementation that throws an exception.

I have seen some solutions asking to directly provide my own implementation of exit, but that results in the following error:

MSVCRTD.lib(MSVCR120D.dll) : error LNK2005: exit already defined in main.obj debug\Sample.exe : fatal error LNK1169: one or more multiply defined symbols found

  • 3
    *I use a third party library that calls the system method exit()* -- What is the name of this library, so that others can avoid using it. – PaulMcKenzie Nov 23 '18 at 06:10
  • 1
    How about contacting the author(s) of this library, and say to them what they're doing is [wrong-headed](https://stackoverflow.com/questions/22843189/exit-call-inside-a-function-which-should-return-a-reference/22843464#22843464) – PaulMcKenzie Nov 23 '18 at 06:12
  • @pau: Any library written in C++ terminates the program in case of an unhandled exception. This is required for a confirming implementation. Calling this off as *"wrong-headed"* without even knowing the circumstances under which this library terminates the program isn't entirely useful. – IInspectable Nov 23 '18 at 08:21
  • @IInspectable unhandled exception don't call [exit](https://en.cppreference.com/w/cpp/utility/program/exit), but call [std::terminate](https://en.cppreference.com/w/cpp/error/terminate) which by default calls [std::abort](https://en.cppreference.com/w/cpp/utility/program/abort) if no [std::terminate_handler](https://en.cppreference.com/w/cpp/error/terminate_handler) is installed. IMHO, if the third party library **really** calls exit it is "wrong-headed". – user1810087 Nov 23 '18 at 08:30
  • @use: `std::abort` is just the prescribed name of the function to be called in C++. That function needs an implementation, too, and that implementation will eventually call into `exit`. My point is that making a call based on incomplete information is inconsiderate. Maybe the library in question is indeed using an inappropriate implementation. But maybe it isn't, and the OP has failed to disclose *vital* details. If the latter is true, they may just be asking to solve the wrong problem altogether. – IInspectable Nov 23 '18 at 11:01

0 Answers0