简体   繁体   English

将公共语言运行时 (/clr) .dll 链接到静态链接到 C/C++ 运行时库的静态库

[英]Linking a Common Language Runtime (/clr) .dll to static libraries statically linked to the C/C++ Runtime Library

I have a WPF app I'm compiling in Visual Studio 2010 that uses a CLR .dll to interact with some unmanaged C/C++ code.我有一个正在 Visual Studio 2010 中编译的 WPF 应用程序,它使用 CLR .dll 与一些非托管 C/C++ 代码进行交互。 The idea is that WPF references the CLR .dll which in turn references the unmanaged code.这个想法是 WPF 引用 CLR .dll,后者又引用非托管代码。 Unfortunately, I'm running into terrible linking issues because the unmanaged C/C++ code and related libraries all link statically to the C/C++ runtime, but if I try to use that code generation method on the CLR .dll, it throws an error because the /clr option and statically linking to the CRT are incompatible.不幸的是,我遇到了可怕的链接问题,因为非托管 C/C++ 代码和相关库都静态链接到 C/C++ 运行时,但是如果我尝试在 CLR .dll 上使用该代码生成方法,则会引发错误因为 /clr 选项和静态链接到 CRT 是不兼容的。 I need to somehow glue these things together.我需要以某种方式将这些东西粘在一起。

My thought was to try to create an additional .dll that just contained all of the unmanaged code in a single package (also linked statically to the CRT), then link that to the CLR .dll, which in turn links into the app (blech!).我的想法是尝试创建一个额外的.dll,它只包含一个包中的所有非托管代码(也静态链接到 CRT),然后将链接到 CLR .dll,后者又链接到应用程序(blech !)。 I tried to make such a .dll, but the problem is that (maybe obviously?) it didn't pull in any of the symbols from the static .lib files because it didn't need any of them.我试图制作这样的 .dll,但问题是(也许很明显?)它没有从静态 .lib 文件中提取任何符号,因为它不需要任何符号。 I tried forcing symbol references (/OPT:NOREF), but that didn't seem to do anything.我尝试强制符号引用 (/OPT:NOREF),但这似乎没有任何作用。 It's just an empty .dll that "links" to the libs but isn't actually doing anything.它只是一个空的 .dll,它“链接”到库,但实际上并没有做任何事情。 So a big fail on that idea.所以这个想法大错特错。

Am I approaching this whole thing all wrong?我把整件事都搞错了吗?

I don't have source code for some of the unmanaged libraries, so I can't recompile them to link dynamically to the CRT.我没有某些非托管库的源代码,因此我无法重新编译它们以动态链接到 CRT。 These linking problems are getting really frustrating!这些链接问题变得非常令人沮丧!

Thanks for any suggestions!感谢您的任何建议!

UPDATE: I guess this is tantamount to trying to mix /MT and /MD modules together, which, according to this , is not possible.更新:我想这相当于尝试将/MT/MD模块混合在一起, 根据this是不可能的。 How is it that you're supposed to link projects in which you don't have control over third party libraries?您应该如何链接您无法控制第三方库的项目? You just hope that they've all chosen to use the same runtime library linking method?!您只是希望他们都选择使用相同的运行时库链接方法?! Seems like a horrible idea...似乎是一个可怕的想法......

The solution appears to be that you should not attempt to link /MT and /MD -compiled libraries together.解决方案似乎是您不应尝试将/MT/MD编译的库链接在一起。 I'm a bit surprised by it, because there are instances where you may not have control over the libraries you have to link to.我对此感到有些惊讶,因为在某些情况下,您可能无法控制必须链接到的库。 And if you're trying to link into a CLR project, you'd better hope those libraries were compiled with /MD , or you're in trouble!如果您尝试链接到 CLR 项目,您最好希望这些库是使用/MD编译的,否则您就有麻烦了! In my case, I was able to solve it by recompiling some external libraries using /MD.就我而言,我能够通过使用 /MD 重新编译一些外部库来解决它。 There was one in particular I didn't have access to code for, and its DEFAULTLIB was a statically linked C-runtime ( libcmt.lib ), but somehow I was able to link to it without issue.特别是有一个我无法访问代码,它的DEFAULTLIB是一个静态链接的 C 运行时( libcmt.lib ),但不知何故我能够毫无问题地链接到它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么在 Visual C++ 2008 中链接 static 运行时库在运行时仍需要 MSVCR71.dll? - Why does linking against static runtime libraries in Visual C++ 2008 still requires MSVCR71.dll at runtime? Visual C ++ Express 2008的静态运行时库链接 - Static Runtime Library Linking for Visual C++ Express 2008 如何创建与 c/c++ 标准库静态链接的 static 库? - How to create a static library that is statically linked against c/c++ standard libraries? C++ 项目编译强制选项 /clr 尽管在没有公共语言运行时支持的情况下执行它 - C++ project compilation forcing the option /clr though executing it with no Common Language Runtime support 静态链接到 VC++ 运行时,同时包含动态链接到它的静态库 - Linking to the VC++ runtime statically while including static libraries that linked to it dynamically C ++公共语言运行时支持[.Net?] - C++ Common Language Runtime Support [.Net?] 静态链接的非托管库和C ++ CLR - Statically linked unmanaged libs and C++ CLR 如何在Android上将C ++运行时静态编译为NDK / JNI库? - How to statically compile C++ runtime into NDK/JNI library on Android? Microsoft Visual Studio〜C / C ++运行时库〜静态/动态链接 - Microsoft Visual Studio ~ C/C++ Runtime Library ~ Static/dynamic linking 从与静态运行时链接的DLL函数(/ MT或/ MTd)返回非原始C ++类型 - Returning non-primitive C++ type from a DLL function linked with a static runtime (/MT or /MTd)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM