.crt section? What does this warning mean?

北城以北 提交于 2019-12-04 19:23:21

问题


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?


回答1:


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.




回答2:


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.




回答3:


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!




回答4:


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.



来源:https://stackoverflow.com/questions/6529003/crt-section-what-does-this-warning-mean

工具导航Map

JSON相关