0

I have library that consist of many directories each of them contains libX.cpp and libX.h files where X is directory name. One libX might be used in different projects. Problem is that while compiling each project asks include stdafx.h in libX.cpp. I suppose I must include stdafx.h file that was generated for current project (correct me if I'm wrong). Ok, I'm writing #include "some_absolute_path1\stdafx.h" in for example libA.cpp file. But I'm using the same libA.cpp in another project and then I must change line

#include "some_absolute_path1\stdafx.h"

to

#include "some_absolute_path2\stdafx.h"

It is not very comfortable to change stdafx.h path while switching between projects.

What is best way to deal in that situation?

4

2 回答 2

0

当您的 lib 使用该文件中定义的某些要包含的资源时,任何包含都是必需的。如果你需要包含 stdafx.h 是因为你有一些强制它的依赖。您应该查看是什么原因导致您需要将此项目相关文件包含在您的库中(不是特定于项目)

我发现这篇文章:http ://en.wikipedia.org/wiki/Precompiled_header

然后我会尝试将 stdafx.h 移动为 main.cpp 中的第一个包含,您还可以在其中包含您的 libx.h 文件。

于 2012-08-08T18:49:11.060 回答
0

您可以根本不使用 stdafx.h。它仅用于预编译头文件。

你可以做#include "some_absolute_path2\libX.h"

如果您仍想使用预编译头文件,您只需#include "some_absolute_path2\libX.h"在需要该库的项目的 stdafx.h 中即可。

于 2012-08-08T18:36:51.000 回答