开发者

.crt section? What does this warning mean?

开发者 https://www.devze.com 2023-03-16 14:31 出处:网络
I\'ve got this warning recently (VC++ 2010) warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators

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 mea开发者_开发百科n exactly?


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.


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.


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!


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.


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 


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".

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号