12

A third party library in my program is trying to call __scrt_common_main_seh by way of the Microsoft library msvcrt.lib, but is defined by some unknown library and therefore gives a linker error. I don't know what this function is supposed to do or where it is defined.

I looked online for this function, but did not find any clues except for general descriptions of what linker errors are.

I believe it might be doing some setup for win32 GUI applications. The library which defines it might be configured as project dependency by Visual Studio but my project is using Bazel.

Mark
  • 5,286
  • 5
  • 42
  • 73
  • This seems relevant https://stackoverflow.com/questions/22934206/what-is-the-difference-between-main-and-maincrtstartup – Mark Nov 24 '20 at 20:10
  • Also relevant https://learn.microsoft.com/en-us/cpp/build/reference/entry-entry-point-symbol?view=msvc-160 – Mark Nov 24 '20 at 20:12
  • 1
    `__scrt_common_main_seh` is the C and C++' language runtime startup code, that ultimately runs your code under a global SEH exception filter. When your code fails in catastrophic ways you'll at least get some error diagnostics out of it. It's totally unclear from the question, what situation you are in, but it is clear that your [proposed answer](https://stackoverflow.com/a/64994218/1889329) is guess-work, at best. There's an old saying among native developers that goes something like this: If you don't know why your code works, it doesn't. – IInspectable Nov 24 '20 at 21:32
  • Thanks @IInspectable. I think you are in a good position to improve on my answer. You might be able to explain what the SEH exception filter is, how exactly it comes to be instantiated, and under which circumstances the linker would not be able to locate it. – Mark Nov 24 '20 at 21:41

3 Answers3

15

Summary

For non-console applications having error error LNK2019: unresolved external symbol main referenced in function "int __cdecl __scrt_common_main_seh(void)" try adding linker flag /ENTRY:wWinMainCRTStartup or /ENTRY:WinMainCRTStartup

For console applications having that error, make sure to implement a main() function.

Details

This answer shows that __scrt_common_main_seh is normally called during mainCRTStartup which is the default entry point for windows console applications. __scrt_common_main_seh is then (indirectly) responsible for calling main().

My program did not have a main() function, which might have prevented the compiler from generating __scrt_common_main_seh (Just speculating. I am totally clueless about who defines __scrt_common_main_seh)

I did find, however, that the library I was linking against defined a wWinMain() function. So I tried adding the linker flag /ENTRY:wWinMainCRTStartup and the linker error went away.

Mark
  • 5,286
  • 5
  • 42
  • 73
2

What worked for me was to add: /ENTRY:mainCRTStartup to the linker flags (wWinMainCRTStartup or WinMainCRTStartup did not work).

See https://stackoverflow.com/a/39704287/7683041.

PJ127
  • 986
  • 13
  • 23
2

A bug in the Qwt qmake files. The author ( = me ) does not use Windows at all and missed, that "win32:CONFIG += entrypoint" seems to be necessary since Qt6.

See https://sourceforge.net/p/qwt/git/ci/qwt-6.2/ In case it doesn't work for you: https://sourceforge.net/p/qwt/bugs/365/

Uwe
  • 21
  • 1