.crt section? What does this warning mean?
Asked Answered
Q

6

11

I've got this warning recently (VC++ 2010)

warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators

I'm assuming this is the Critical Section. It's been a while since my Operating Systems course, so I can't really figure out what this means. If I remember right, the Critical Section works with shared resources. So how is this warning related and what does it mean exactly?

Quinate answered 30/6, 2011 at 1:11 Comment(0)
L
11

No, CRT = C Run Time. It is support library that any program needs to get the job done. Stuff like strcpy() lives there. You get a '.CRT section' in your .obj file when your code contains global variables that need to be initialized before your program starts running. The CRT takes care of that.

That is nothing unusual. The problem is the linker didn't see the CRT getting linked into your program. You somehow wrote code that didn't have any dependency on the CRT code, other than the initialization requirement. Very strange, never heard of anybody having this issue. Follow the checklist in the documentation to see if one of them matches your case.

Lacuna answered 30/6, 2011 at 1:22 Comment(3)
Alright, cool, I'll take a look through that checklist. Not causing me any problems, but I'd like to have a warning-free compile :)Quinate
For the record, some people do it on purpose to write a really tiny program (by private bytes RAM usage) - at least given the "32-bit Windows process" requirement. The warning occurs when you accidentally make use of language features that rely on the CRT.Mangrove
You can run into this if you're building a kernel driver with C++ and try making a static instance of a class. Without the CRT, there's nothing to run the initialization and termination code for the static.Incandescent
V
8

The MSDN docs cover this pretty well:

Some code introduced static initializers or terminators, but the CRT or its equivalent (which needs to run the static initializers or terminators) isn't run when the application starts. Examples of code that would cause this:

  • Global class variable with a constructor, destructor, or virtual function table.
  • Global variable initialized with a non-compile-time constant.

To fix this problem:

  • Add msvcrtxx.lib, libc.lib, libcd.lib, libcmt.lib, or libcmtd.lib to your linker command line, or
  • Remove all code with static initializers.
  • Do not use /NOENTRY.

So I would check your code for the recent addition of objects created at static or global scope. If you don't find any, they may be hiding within a 3rd-party library which you're linking with. Either way, the most likely solution will be to link with CRT using the first suggestion in the "To fix this problem" section above.

Veasey answered 30/6, 2011 at 1:19 Comment(1)
It's not always possible to use the MSVCRT if you are writing a plugin for a product that was compiled with a different CRT (e.g. Citrix Receiver). Nasty things can start to happen if a process pulls multiple versions of the CRT into it's process. Careful coding will allow you to remove the CRT.Burthen
D
6

warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators

This error is caused due to the specification of the entry point in project properties.

Follow the steps below and see if your error gets resolved:

1.Right click on your Project in solution explorer(VS 2013)

2.Go to properties- All Configurations

3.Linker- Entry Point. Delete the entry point if you have specified any.

There is no need to specify the entry point as the BOOST_TEST detects the entry point automatically.

Hope this helps for other innitializer errors as well. Cheers!

Dragnet answered 3/7, 2017 at 16:17 Comment(0)
C
2

I have had the same problem by manually specifying a "custom" entry to my DLL. I removed that custom DLL entry and am simply using the default name DLLMain and it works again...odd.

Conversable answered 4/3, 2014 at 18:51 Comment(0)
A
-1

LIBCMT.LIB to initialize the CRT related stuffs.... Use mainCRTStartup for entry function, then call _CRT_INIT explicity.

link hello_world.obj Kernel32.lib UCRT.LIB legacy_stdio_definitions.lib LIBCMT.LIB /subsystem:console  /out:hello_world_basic.exe 
Avent answered 11/8, 2021 at 23:56 Comment(0)
A
-2
bits 64
default rel

segment .data
    msg db "Hello world!", 0xd, 0xa, 0

segment .text
global mainCRTStartup
extern ExitProcess
extern _CRT_INIT

extern printf

mainCRTStartup:
    push    rbp
    mov     rbp, rsp
    sub     rsp, 32

    call    _CRT_INIT

    lea     rcx, [msg]
    call    printf

    xor     rax, rax
    call    ExitProcess
    ret

If you don't call _CRT_INIT, the linker will show the warnings about "warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators".

Avent answered 12/8, 2021 at 0:0 Comment(1)
The question is about C++, not assembly language.Purapurblind

© 2022 - 2024 — McMap. All rights reserved.