简体   繁体   English

Visual Studio在一个解决方案中“同步”多个项目

[英]Visual Studio “synchronize” multiple projects within one solution


I am writing my own C++ project library in visual studio (couple of projects that consist of *cpp, *.h files, NOT an actual .lib file). 我正在Visual Studio中编写自己的C ++项目库(几个项目由* cpp,*。h文件组成,而不是实际的.lib文件)。 Each of these projects is located in single Visual Studio "solution". 这些项目中的每一个都位于单个Visual Studio“解决方案”中。

When I needed to use a code from one project in another, I just copied it. 当我需要使用另一个项目中的代码时,只需复制它即可。 But that was short term solution. 但这是短期解决方案。 Now my library has grown both in size and functionality, and because of code duplication I ended up with dozens of different versions of the same file. 现在,我的库的大小和功能都在增长,由于代码重复,我最终得到了同一文件的数十种不同版本。

That single solution serve me as a playground // test ground for new ideas. 单一的解决方案可作为我//作为新想法的试验场。 I am developing projects not libs. 我正在开发项目而不是库。 Currently it holds about 50 projects. 目前,它拥有约50个项目。

I am working on visual studio 2015. 我正在Visual Studio 2015中工作。


Lets say I have setup like this: 可以说我有这样的设置:

  1. DataIO project located in */Solution/#DataInputAndOutput/DataIO/DataIO.h DataIO项目位于*/Solution/#DataInputAndOutput/DataIO/DataIO.h
    consist both of DataIO.h and DataIO.cpp 由DataIO.h和DataIO.cpp组成
  2. Foo project located in */Solution/#Foo/Foo/Foo.h Foo项目位于*/Solution/#Foo/Foo/Foo.h
    consist both of Foo.h and Foo.cpp 由Foo.h和Foo.cpp组成

DataIO.h: DataIO.h:

#pragma once
#ifndef __DATA_IO_H__
#define __DATA_IO_H__
// ...

extern FILE * const logFile;

// Bunch of function declarations
#endif // !__DATA_IO_H__

I know that this is not a "Minimal, Complete, and Verifiable example" but my problem lies in logistic of things, not things themselves. 我知道这不是“最小,完整和可验证的示例”,但我的问题在于事物的后勤保障,而不是事物本身。 And I believe that my description is sufficient. 而且我相信我的描述就足够了。


Problem #1: In Foo.cpp I #include "DataIO.h" (with is possible because i added additional include directories in Foo project setup) But whenever I try to compile Foo I am given following error: unresolved external symbol for every function declaration inside DataIO.h and that one external variable. 问题1:Foo.cpp#include "DataIO.h" (之所以可能,是因为我在Foo项目设置中添加了其他include目录),但是每当我尝试编译Foo时,都会出现以下错误:每个函数都无法unresolved external symbolDataIO.h内部DataIO.h和一个外部变量。 How Can I Fix this problem? 如何解决此问题? Do I need to create a DataIO.lib to keep things straight? 我是否需要创建一个DataIO.lib来使事情变得简单?

I tried to add DataIO.h and DataIO.cpp into Foo project directly (NOT copy it, just add it into project) but that seems like a bad idea... 我试图将DataIO.hDataIO.cpp直接添加到Foo项目中(不要复制它,只需将其添加到项目中),但这似乎是一个坏主意...

The best way to do this is to factor out common code into a library so the common code resides in one place. 最好的方法是将公共代码分解到一个库中,以便公共代码驻留在一个地方。 And then have your projects use the library - via an include file and linking with said library. 然后让您的项目使用库-通过包含文件并与所述库链接。

I recommend trying out the new "Shared Items Project" in VS2015+. 我建议在VS2015 +中尝试新的“共享项目项目”。 A Shared Items Project is literally just a set of files. 一个共享项目项目是从字面上只是一组文件。 The project itself doesn't build anything. 该项目本身不构建任何东西。 In fact, there are no (or almost no) compilation or linkage settings in a Shared Items Project -- those settings come the the project that references the Shared Items Project. 事实上,有一个共享项目项目没有(或几乎没有),编译或链接设置 - 这些设置都将引用共享项目项目项目。 When you reference a Shared Items Project from some other project FOO, the build of FOO happens as if the files of the Shared Items Project are items of the referencing project. 当您从其他一些项目FOO引用共享项目工程,FOO的积累发生,因为如果共享项目工程的文件是引用项目的项目。

Short of that, you can set up your shared projects to build .libs and then use Project References within Visual Studio to automatically set up the linkage. 简而言之,您可以设置共享项目以构建.libs,然后在Visual Studio中使用“项目引用”来自动设置链接。 I think you have to manually set up the include paths when doing this, though. 我认为您在执行此操作时必须手动设置包含路径。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM