BullseyeCoverage Up Contents Search

Error LNK2019 unresolved external symbol atexit

Symptoms

error LNK2019: unresolved external symbol atexit referenced in function cov_probe_v12

Cause

Your link command uses option /INTEGRITYCHECK, but does not link with the C run-time library due to the compiler option /Zl or linker option /NODEFAULTLIB.

Resolution

There are three alternatives.

  1. Do not use /INTEGRITYCHECK when using BullseyeCoverage.

  2. Link with the C run-time library.

  3. Implement atexit.
    1. Add the code below to your application.
      void (__cdecl* AtexitFunction)(void);
      #if __cplusplus
      extern "C"
      #endif
      int __cdecl atexit(void (__cdecl* func)(void))
      {
      	AtexitFunction = func;
      	return 0;
      }
      
    2. Add the code below to the end of your entry point function (WinMainCRTStartup or mainCRTStartup) and before every call to ExitProcess.
      if (AtexitFunction)
          AtexitFunction();
      

More Information

BullseyeCoverage implements the atexit using a DLL, which cannot be code signed to the requirements of the /INTEGRITYCHECK option. When /INTEGRITYCHECK is in effect, BullseyeCoverage falls back to the C run-time atexit.

Updated: 2 Dec 2024