在Windows上CMake链接错误(CMake linking error on windows)

编程入门 行业动态 更新时间:2024-10-21 20:28:50
在Windows上CMake链接错误(CMake linking error on windows)

我有一个恼人的CMake问题。 我有一个包含多个目录的项目,例如(理论上):

编译器 - >生成compiler.exe和compiler.dll 这是纯C ++ 然而,由于使用了一些奇特的东西,compiler.dll需要链接到machine.dll(见下文)... 而compiler.dll是一个SHARED库 机器 - >生成machine.exe和machine.dll - 这是一半C和一半C ++。 C ++部分需要链接到compiler.dll

所以这里出现了循环依赖,在Linux上非常优雅地解决了,但是在MSVS2012上,链接器抱怨LNK2019 ......未解析的外部符号。 这是可以理解的,因为当我看到编译时,顺序如下:

它编译机器的C文件 它试图编译机器的C ++文件...这里它在链接失败,因为编译器的C ++文件还没有编译......

我该如何解决这个问题?

I have an annoying CMake issue. I have a project with more than one directories, such as (theoretically):

compiler -> generates compiler.exe and compiler.dll This is pure C++ However the compiler.dll needs to link to machine.dll (see below) due to use of some fancy things ... and the compiler.dll is a SHARED library machine -> generates machine.exe and machine.dll - this is half C and half C++. The C++ part needs to link to compiler.dll

So here a circular dependency arose, which is very elegantly solved on Linux, however on MSVS2012, the linker complains with LNK2019 ... unresolved external symbol. Which is understandable, since when I see the compilation, the order is the following:

it compiles the machine's C files it tries to compile the machine's C++ files ... and here it fails at the linking, since the compilers' C++ files were not compiled yet...

How can I resolve this issue?

最满意答案

通过将共享库转换为静态库并将必要部分提取到共享库中来解决问题,而不保持循环性。

Problem was solved by converting the shared libraries into static ones and extracting the necessary parts into a shared library, without keeping the circularity.

更多推荐

本文发布于:2023-08-02 19:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1379644.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   链接   CMake   Windows   error

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!