gpt4 book ai didi

c++ - Makefile 运行编译时#if 说它不应该运行的代码

转载 作者:太空狗 更新时间:2023-10-29 21:22:43 24 4
gpt4 key购买 nike

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

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

整个 block 看起来像这样:

#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

发生这种情况有什么明显的原因吗?

最佳答案

因此,考虑到评论:不要调用您的“兼容性 header ”"dirent.h"但像 "dirent_compat.h""dirent_win.h" .

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

关于c++ - Makefile 运行编译时#if 说它不应该运行的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19977446/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com