在 Visual Studio 2017 Linux 项目中无法识别 Linux 头文件 [英] Linux header file not recognized in Visual Studio 2017 Linux Project

查看:78
本文介绍了在 Visual Studio 2017 Linux 项目中无法识别 Linux 头文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当在我的 C 程序的 Visual Studio 2017 上的 Linux C++ 项目中包含 Linux 头文件 ucontext.h 时,它无法识别头文件.即使我包含 sys/ucontext.h,它也无法识别我应该能够用于 ucontext_t 对象的函数,例如 getContext() 和 setContext().我不应该能够在 Linux C++ 项目中使用这些函数吗?

When including a Linux header file, ucontext.h in this case, in a Linux C++ Project on Visual Studio 2017 for my C program, it does not recognize the header file. Even when I include sys/ucontext.h, it does not recognize functions that I should be able to use for a ucontext_t object, such as getContext() and setContext(). Shouldn't I be able to use these functions in a Linux C++ project?

我正在编写的代码:

#include <stddef.h>
#include <string.h>
#include <sys/ucontext.h> 
// If I use ucontext.h instead, it gives the error: cannot open source file ucontext.h

//TCB structure
typedef struct TCB_t {
    struct TCB_t     *next;
    struct TCB_t     *prev;
    ucontext_t      context;
} TCB_t;


void init_TCB(TCB_t *tcb, void *function, void *stackP, int stack_size)
{
    memset(tcb, '', sizeof(TCB_t));   
    tcb->context.uc_stack.ss_sp = stackP;
    tcb->context.uc_stack.ss_size = (size_t)stack_size;

    int c = getcontext(tcb->context); // Cannot resolve field getcontext()
}

推荐答案

在我的 Linux 系统 (Debian Jessie) ucontext.husr/include 中包括 sys/ucontext.hgcc 将在 usr/include/i386-linux-gnu/sys 中找到.第一个定义函数getcontextsetcontext.第二个定义数据结构 ucontext_t

On my Linux system (Debian Jessie) ucontext.h is in usr/include which in turn includes sys/ucontext.h which gcc will find in usr/include/i386-linux-gnu/sys. The first defines the functions getcontext and setcontext. The second defines the data structures ucontext_t etc.

在 Windows 主机上,VCLinux 已在 C:Program Files (x86)Microsoft Visual Studio 14.0 中安装了第二个 ucontext.h(定义数据结构)的副本VCLinuxincludeusrincludex86_64-linux-gnusys .但是第一个 ucontext.h 不存在.

On the Windows host, VCLinux has installed a copy of the second ucontext.h (which defines the data structures) in C:Program Files (x86)Microsoft Visual Studio 14.0VCLinuxincludeusrincludex86_64-linux-gnusys . But the first ucontext.h is not present.

VCLinux/Visual Studio 将在 Linux 远程编译和运行这个程序:

VCLinux/Visual Studio will compile and run this program on the Linux remote:

#include <ucontext.h>
#include <iostream>
int main()
{
   ucontext ucxt;
   ::getcontext (&ucxt);
   std::cout << ucxt.uc_flags << std::endl;
   return 0;
}

但 IntelliSense 不知道函数 getcontextsetcontext 或关联的数据结构.因此,您会在名称下方看到红色的小波浪线,并且没有完成帮助.

But IntelliSense will not know about the functions getcontext and setcontext or the associated data structures. So you will get little red squiggles under the names and no completion assistance.

您可以复制第一个 ucontext.h 并将其放入 C:Program Files (x86)Microsoft Visual Studio 14.0VCLinuxincludeusr在您的 Windows 主机上包含.然后一切都会正常工作.您可以在 VCLinux GitHub 站点 上针对缺少的标头提出问题.

You can take a copy of the first ucontext.h and put it in C:Program Files (x86)Microsoft Visual Studio 14.0VCLinuxincludeusrinclude on your Windows host. Then everything will work as it should. And you could raise an issue for the missing header on the VCLinux GitHub site.

注意:Windows 路径适用于 Visual Studio 2015.它们在 2017 年将有所不同.

Note: Windows paths are for Visual Studio 2015. They will be different for 2017.

适用于 VCLinux 1.0.6.

Applies to VCLinux 1.0.6.

==============

==============

2018 年 4 月 10 日更新

Update 10-Apr-18

Microsoft 已解决 Linux 系统之间标准包含文件位置差异的问题.正如 this Visual C++ blog发布后,特定于 GCC 设置的标头从 Linux 远程复制并基于每个连接存储在 Windows 主机上.

Microsoft have addressed the issue of differences in standard include file locations between Linux systems. As explained in this Visual C++ blog post, the headers specific to the GCC setup are copied from the Linux remote and stored on the Windows host on a per-connection basis.

这篇关于在 Visual Studio 2017 Linux 项目中无法识别 Linux 头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆