Makefile运行编译时#if说不应该的代码

时间:2013-11-14 12:18:03

标签: c++ makefile

我正在尝试在Linux上编译我的代码并创建一个简单的make文件。 在我的一个标题中,有一个模拟Unix的dirent.h的文件的编译时条件#include。

我把这个包含在#if defined(_WIN32) || defined(_WIN64)中,然而g ++很乐意包含该文件,这会导致无休止的错误。

整个区块看起来像这样:

#if defined(_WIN32) || defined(_WIN64) 
#include "dirent.h"
#define strncasecmp _strnicmp 
#else
#include <unistd.h>
#include <dirent.h>
#include <fcntl.h>
#include <sys/types.h>
#include <utime.h>
#endif

有没有明显的理由发生这种情况?

1 个答案:

答案 0 :(得分:3)

因此,请注意以下内容:请勿调用“兼容性标题”"dirent.h",而应使用"dirent_compat.h""dirent_win.h"

或者,不要将当前目录添加到系统包含的包含路径中(无论如何你真的不应该在当前目录中包含<...>