.crt 部分?这个警告是什么意思?

发布于 2024-11-18 04:43:25 字数 182 浏览 9 评论 0原文

我最近收到此警告(VC++ 2010)

警告 LNK4210:.CRT 部分存在;可能有未处理的静态初始化程序或终止符

我假设这是关键部分。我的操作系统课程已经有一段时间了,所以我无法真正弄清楚这意味着什么。如果我没记错的话,关键部分使用共享资源。那么这个警告有什么关系,它到底意味着什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

一场春暖 2024-11-25 04:43:25

不,CRT = C 运行时间。它是任何程序完成工作所需的支持库。像 strcpy() 这样的东西就在那里。当您的代码包含需要在程序开始运行之前初始化的全局变量时,您的 .obj 文件中会出现“.CRT 部分”。 CRT 负责处理这个问题。

这没什么不寻常的。问题是链接器没有看到 CRT 链接到您的程序中。除了初始化要求之外,您以某种方式编写了不依赖于 CRT 代码的代码。很奇怪,从来没有听说过有人遇到这个问题。请按照文档中的清单查看其中是否有符合你的情况。

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.

红焚 2024-11-25 04:43:25

MSDN 文档很好地介绍了这一点:

一些代码引入了静态
初始化器或终止器,但是
CRT 或同等产品(需要
运行静态初始化程序或
终止符)不运行时
应用程序启动。代码示例
这会导致这个:

  • 具有构造函数、析构函数或虚函数表的全局类变量。
  • 使用非编译时常量初始化的全局变量。

要解决此问题:

  • 将 msvcrtxx.lib、libc.lib、libcd.lib、libcmt.lib 或 libcmtd.lib 添加到链接器命令行,或者
  • 删除所有带有静态初始值设定项的代码。
  • 请勿使用 /NOENTRY。

因此,我会检查您的代码是否最近添加了在静态或全局范围内创建的对象。如果您没有找到任何内容,它们可能隐藏在您正在链接的第三方库中。无论哪种方式,最可能的解决方案是使用上面“解决此问题”部分中的第一个建议与 CRT 链接。

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.

贱贱哒 2024-11-25 04:43:25

警告 LNK4210:.CRT 部分存在;可能存在未处理的静态初始值设定项或终止符

此错误是由于项目属性中入口点的规范引起的。

按照以下步骤操作,看看您的错误是否得到解决:

1. 在解决方案资源管理器中右键单击您的项目 (VS 2013)

2. 转到属性 - 所有配置

3. 链接器 - 入口点。如果指定了入口点,请删除该入口点。

无需指定入口点,因为 BOOST_TEST 会自动检测入口点。

希望这也有助于解决其他初始化程序错误。干杯!

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!

橘寄 2024-11-25 04:43:25

我通过手动指定 DLL 的“自定义”条目也遇到了同样的问题。我删除了那个自定义 DLL 条目,只使用默认名称 DLLMain,它又可以工作了……奇怪。

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.

暮倦 2024-11-25 04:43:25

LIBCMT.LIB 初始化 CRT 相关的东西....
使用mainCRTStartup作为入口函数,然后显式调用_CRT_INIT。

link hello_world.obj Kernel32.lib UCRT.LIB legacy_stdio_definitions.lib LIBCMT.LIB /subsystem:console  /out:hello_world_basic.exe 

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 
北城孤痞 2024-11-25 04:43:25
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

如果您不调用_CRT_INIT,链接器将显示有关“警告 LNK4210:.CRT 部分存在;可能存在未处理的静态初始化程序或终止符”的警告。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文