2

I was working on a none Visual C++ Runtime Library project for a few days from now, however, I had a smooth ingoing until my linker start complaining about the unresolved external symbol of the __CxxFrameHandler3 CRT function, so after searching for the reason which produces this error I found that calling a method of any custom class from the main entry point is calling this CRT function, simple example :

// /No Common Language RunTime Support
// /Ignore All Default Libraries 

class A
{
public:
    A();
    ~A();

    int do_something();
private:

};

int A::do_something()
{
    return 0;
}

int EntryPoint()
{
    A a;
    a.do_something(); // Calls the __CxxFrameHandler3 CRT function.

    return 0;
}

Error :

 LNK2019    unresolved external symbol ___CxxFrameHandler3 referenced in function __unwindfunclet$?UmbraServerMain@@YGHPAUHINSTANCE__@@0PA_WH@Z$0   

Is there a way to prevent the call to this CRT function?

2 Answers2

4

Reposting my comment as an answer:

This functions has to do with SEH (Structured Exceptions Handling), so to stop calling it, one needs to disable exceptions (SEH and C++ exceptions) in the project.

SergeyA
  • 61,605
  • 5
  • 78
  • 137
  • Not sure if it's specifically SEH...it might just be regular C++ exceptions. (Exceptions aren't directly implemented by the compiler; it just inserts calls to CRT functions that do the heavy lifting.) – cHao Aug 01 '18 at 19:29
  • @cHao according MSDN, it deals with SEH: https://msdn.microsoft.com/en-us/library/ff770594.aspx AFAIK, in MSVC C++ exceptions are implemented on top of SEH, so I would imagine you need to disable both. – SergeyA Aug 01 '18 at 19:29
  • @cHao you are right, it is used for C++ exceptions and not for SEH (which uses _C_specific_handler). c.f. https://sanseolab.tistory.com/category/?page=6 – Lewis Kelsey Apr 24 '20 at 19:44
1

That function is part of VS's exception handling infrastructure. In order to safely avoid using the CRT, you'll need to either provide your own (compatible!) implementations of the exception-handling functions, or compile with exceptions disabled and religiously avoid anything that can throw an exception. (An exception you've explicitly unprepared yourself for, is a memory leak waiting to happen.)

cHao
  • 84,970
  • 20
  • 145
  • 172