Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在一个解决方案中有两个 C++ 项目,它们都需要共享两个公共类。我想要避免的是拥有两个源文件副本,但我不愿意只在一个项目中包含源代码并在另一个项目中引用它。
这种情况一般是怎么处理的?
创建第三个项目,它可以是动态库或静态库(为了便于使用,首选后者)并将共享代码放入其中。其他两个项目#include 来自库项目的标头并与库项目二进制文件链接。