gpt4 book ai didi

c++ - 构建时的 Microsoft C++ 库符号链接(symbolic link)

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:31:11 25 4
gpt4 key购买 nike

使用 Visual Studio C++ 2008 Express:

我正尝试在如下编译的构建中执行最后的链接步骤:

  • foo.lib 是使用 /MD 开关静态编译的(构建不会生成 .dll) . foo.lib 的构建成功。 .lib 文件和 header 被传送到下面库的项目可以找到它们的目录。 foo.lib 源代码是用非托管 C++ 编写的。

  • bar.dll 被编译为带有 /MD/LD 开关的动态库。 bar.dll 依赖于 foo.lib 导出的符号。 bar.dllfoo.lib 都是使用相同的 cl.exelink.exe 从源代码构建的来自 VS2008 Express 工具链的二进制文件。 bar.dll 源代码是用非托管 C++ 编写的。

  • bar.dll 的所有 .obj 文件构建成功,但在 link.exe 的最终执行期间生成 bar.dll,我收到 数千 的关于未定义外部的 LNK2001 错误。所有未定义的外部都是我希望在标准 C++ 库中的东西:像 std::basic_string 构造函数、std::_Throw 类、ostream 重载运算符,等等。 link.exe 表示未定义的外部 foo.lib 中未定义!

  • bar.dll 的目标是在其中包含 foo.lib 的整个静态链接代码,以及它自己的对象,但动态取决于 MSVCR90.dllMSVCP90.dll 在运行时的存在/解析。

我是想用这个build设置一个不可能的情况,还是我只是做错了什么?如果这在理论上根本行不通,请告诉我。否则,请告诉我可以尝试哪些诊断来确定为什么 C++ 库符号在最后的链接步骤中对 foo.lib 不可用。

编辑:更具体的信息:foo.libLLVM 3.1 和 bar.dllMesalibgl-gdi (llvmpipe)来自 master 分支(目标是生成在 llvmpipe 上运行的 opengl32.dll)。我已经满足了所有构建依赖项,如下所示:

  • LLVM 构建取决于 CMake作为构建系统,以及 Python 2.7。
  • Mesa 构建取决于 SCons作为构建系统,LLVM 2.6 或更高版本、Python 2.7、pywin32、python-libxml2、bison 和 flex。在上面,只有 LLVM 在运行时被传送;其余的只是构建过程中使用的“工具”。

我还根据需要为每个项目定制了构建以设置环境变量并确保它们始终只使用 /MD 开关而不是 /MT 或一些用于选择错误的 C 运行时库的其他开关。

最佳答案

来自MSDN help :

Defines _MT and _DLL so that both multithread- and DLL-specific versions of the run-time routines are selected from the standard .h files. This option also causes the compiler to place the library name MSVCRT.lib into the .obj file. Applications compiled with this option are statically linked to MSVCRT.lib. This library provides a layer of code that allows the linker to resolve external references. The actual working code is contained in MSVCR71.DLL, which must be available at run time to applications linked with MSVCRT.lib.

When /MD is used with _STATIC_CPPLIB defined (/D_STATIC_CPPLIB) it will cause the application to link with the static multithread Standard C++ Library (libcpmt.lib) instead of the dynamic version (msvcprt.lib) while still dynamically linking to the main CRT via msvcrt.lib.

更具体地说 - 此摘录:“使用此选项编译的应用程序静态链接到 MSVCRT.lib

换句话说 - 您需要将您的 foo.lib 链接到 msvcrt.lib。

关于c++ - 构建时的 Microsoft C++ 库符号链接(symbolic link),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11801673/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com