如何避免“错误 LNK2005:” (已定义的 stdlib 函数)使用 Microsoft Visual Studio '08 编译 libpng 时?

发布于 2024-08-15 17:09:59 字数 1864 浏览 11 评论 0原文

(为什么我尝试这样做:我没有运气在 Windows 上使用 libpng 的预构建二进制文件(尽管经过了很多小时的尝试和错误),因此我现在尝试自己编译它。我发现 这篇有用的博客文章与此相关,完成Microsoft Visual Studio 2008 项目文件,但不幸的是仍然无法使用它。)

当链接到找到的 zlib 二进制文件时,它成功编译 此处,但在尝试将其链接到测试文件时我收到以下信息:

    C:\Documents and Settings\Administrator\My Documents>cl "C:\Documents and Settin
    gs\Administrator\My Documents\test.c" "C:\Documents and Settings\Administrator\M
    y Documents\libpng.lib" -I "C:\Documents and Settings\Administrator\My Documents\include"

    Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
    Copyright (C) Microsoft Corporation.  All rights reserved.

    test.c
    Microsoft (R) Incremental Linker Version 9.00.30729.01
    Copyright (C) Microsoft Corporation.  All rights reserved.

    /out:test.exe
    test.obj
    "C:\Documents and Settings\Administrator\My Documents\libpng.lib"
    MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _abort already defined in LIBCMT.lib(
    abort.obj)
    MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _fread already defined in LIBCMT.lib(
    fread.obj)
    MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _malloc already defined in LIBCMT.lib
    (malloc.obj)
    MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _free already defined in LIBCMT.lib(f
    ree.obj)
    MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: ___iob_func already defined in LIBCMT
    .lib(_file.obj)
    LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; u
    se /NODEFAULTLIB:library
    test.exe : fatal error LNK1169: one or more multiply defined symbols found

有人愿意阐明如何修复这些错误吗?

(Why I am trying to do this: I have had no luck in using the pre-built binaries for libpng on Windows (despite many hours of trial and error), and therefore am now trying to compile it myself. I found this helpful blog post concerning this, complete with a Microsoft Visual Studio 2008 project file, but unfortunately have still not been able to use it.)

It successfully compiles when linking to the zlib binary found here, but when attempting to link it to a test file I receive the following:

    C:\Documents and Settings\Administrator\My Documents>cl "C:\Documents and Settin
    gs\Administrator\My Documents\test.c" "C:\Documents and Settings\Administrator\M
    y Documents\libpng.lib" -I "C:\Documents and Settings\Administrator\My Documents\include"

    Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
    Copyright (C) Microsoft Corporation.  All rights reserved.

    test.c
    Microsoft (R) Incremental Linker Version 9.00.30729.01
    Copyright (C) Microsoft Corporation.  All rights reserved.

    /out:test.exe
    test.obj
    "C:\Documents and Settings\Administrator\My Documents\libpng.lib"
    MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _abort already defined in LIBCMT.lib(
    abort.obj)
    MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _fread already defined in LIBCMT.lib(
    fread.obj)
    MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _malloc already defined in LIBCMT.lib
    (malloc.obj)
    MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _free already defined in LIBCMT.lib(f
    ree.obj)
    MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: ___iob_func already defined in LIBCMT
    .lib(_file.obj)
    LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; u
    se /NODEFAULTLIB:library
    test.exe : fatal error LNK1169: one or more multiply defined symbols found

Could anyone care to shed some light as to how to fix these errors?

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

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

发布评论

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

评论(1

尛丟丟 2024-08-22 17:09:59

问题在于,两个项目之一在“项目属性”->“项目属性”中使用多线程 DLL,而另一个项目则使用多线程(其中不含 DLL)。配置属性-> C/C++->代码生成。

我身上发生过好几次。

确保“同步”该设置,甚至对于发布版本以及每种可能的组合(调试、非调试等)

The problem is that one of the two projects is using Multi-threaded DLL while the other is using Multi-threaded (without DLL in it) in Project Properties -> Configuration Properties -> C/C++ -> Code generation.

Happened to me several times.

Make sure to "synchronize" that setting even for release builds, and for each possible combination (debug, non debug, etc)

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