【问题标题】:Visual studio 2017 problem compiling C++ code whereas the code is compiled in LinuxVisual Studio 2017 编译 C++ 代码的问题,而代码是在 Linux 中编译的
【发布时间】:2019-05-19 10:04:45
【问题描述】:

我在 Linux 中编写了我的代码,它是在 Linux 平台上编译的,最近我在跨平台项目下的 Visual Studio 2017 Enterprise 中导入了代码。我的远程构建器是在其上编译代码的机器。但是VS编译项目时,找不到or or之类的头文件,编译失败。

我发现包含文件(VC\Linux\include\usr\include\c++\5 等)的 VS 路径不包含丢失的头文件。但微软社区表示,这种缺失只会导致 IntelliSense 出现故障,代码必须由 VS 编译到远程构建器上!!

#include <errno.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
.
.
.
int main(int argc, char **argv)
{   
     char device_string[1000];
     char * reordered;
     BIO *bio, * b64;
     BUF_MEM * b64buff;
...
}

错误(活动)E1696 无法打开源文件“unistd.h”硬件检查

等等

【问题讨论】:

  • unistd.h 不是标准的 C++ 头文件 - 它是一个 posix 头文件,这就是它在 linux 上工作的原因。
  • 你在VS中安装Linux交叉编译组件了吗?默认情况下它们是可选的。
  • 感谢您的回复。但这正是我的问题,Visual Studio 2017 中的非标准头文件应该如何处理?
  • VS 应该能够找到它们。您的设置可能存在一些问题。你能在没有VS的机器上编译这段代码吗?
  • 不,我不能。问题是 Windows 没有一些库。我想在 Windows 上通过 VS 编写代码,但在 VS 中定义远程构建器。正如我提到的,代码是在 Linux (Debian 8) 中编译的

标签: c++ visual-studio cross-platform


【解决方案1】:

unistd.h,fcntl.h等是Unix标准的头文件。在Windows操作系统中找不到,如果你想在两个平台上编译你的代码,也许你可以这样写你的代码:

#ifdef _WIN32
//code for windows
#elif defined __linux__
//code for linux
#endif

【讨论】:

  • 我只想在 Linux 上编译它,但受益于 Visual Studio IDE。
猜你喜欢
  • 1970-01-01
  • 2020-04-02
  • 2016-10-20
  • 1970-01-01
  • 2019-09-05
  • 1970-01-01
  • 1970-01-01
  • 2011-07-07
  • 2019-07-19
相关资源
最近更新 更多