尽管有if语句,Visual Studio仍试图包括Linux标头

编程入门 行业动态 更新时间:2024-10-10 02:14:46
本文介绍了尽管有if语句,Visual Studio仍试图包括Linux标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试创建一个健壮的头文件,该文件可以在Windows和Linux上进行编译,而无需进行更改.为此,我的include中有一个if语句,看起来像

I am attempting to create a robust header file that will compile on both windows and linux without need for changes. To this end I have an if statement in my includes that looks like

#if (!defined(__WINDOWS__)) #include <sys/time.h> #include <unistd.h> #include <pthread.h> #endif

尽管if语句导致出现类似错误,但我在Visual Studio仍尝试包含这些标头的过程中遇到了问题

I am having problems with visual studio still attempting to include these headers despite the if statement resulting in errors like

error C1083: Cannot open include file: 'sys/time.h'

有没有一种方法可以解决此问题,而无需从标头中删除所有linux代码块?

Is there a way to resolve this issue without removing all the linux blocks of code from the header?

推荐答案

__ WINDOWS __ 由 windows.h 定义.因此,您具有圆度.改用它:

__WINDOWS__ is defined by windows.h. So you have a circularity. Use this instead:

#if defined(_WIN32) # if defined(_WIN64) /*64 bit windows*/ # else /*32 bit windows*/ # endif #endif

是的,_WIN32 是在64位窗口上定义的.我不骗你.

Yes, _WIN32 is defined on 64 bit windows. I kid you not.

更多推荐

尽管有if语句,Visual Studio仍试图包括Linux标头

本文发布于:2023-11-02 07:20:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1551729.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语句   Visual   Linux   Studio

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!