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

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

问题描述

在这种情况下,当包含Linux头文件ucontext.h时,在Visual Studio 2017上针对我的C程序的Linux C ++项目中,它无法识别头文件.即使当我包含sys/ucontext.h时,它也无法识别我应该用于ucontext_t对象的功能,例如

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, '\0', 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.h,而gcc将在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\VC\Linux\include\usr\include\x86_64-linux-gnu\sys中安装了第二个ucontext.h的副本(定义了数据结构).但是第一个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.0\VC\Linux\include\usr\include\x86_64-linux-gnu\sys . 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的副本,并将其放在Windows主机上的C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\Linux\include\usr\include中.这样,一切都会正常进行.并且您可能会因 VCLinux GitHub网站上缺少的标头而产生问题.

You can take a copy of the first ucontext.h and put it in C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\Linux\include\usr\include 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 Studio2015.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.

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

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

更新18年4月10日

Microsoft已解决Linux系统之间标准包含文件位置差异的问题.如此Visual C ++博客中所述后,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天全站免登陆