c - Visual Studio 2017 Linux 项目中无法识别 Linux 头文件

标签 c linux visual-studio visual-studio-2017

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

我正在写的代码:

#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()
}

最佳答案

On this answer to do the following you need Visual Studio Community 2017 15.9.7+ - Tested this solution on Visual Studio Enterprise 2019 Preview 4.

Visual Studio 需要在您的本地计算机中下载所有远程 header ,以实现智能感知的正确行为。

新方法“rsync_ssh”不会下载所有 header 。您可以通过 sftp_ssh 使用旧方法 .zip。

0. 添加远程连接。
工具->选项->跨平台->连接管理器

1. 选择您的连接 从工具->选项->跨平台->连接管理器->远程 header Intellisense 管理器更新。 接下来单击探索按钮。

image

2. C:\Users[你的用户]\AppData\Local\Microsoft\Linux\HeaderCache\1.0[IdNumber] 将 HeaderCache settings.xml.unused 文件重命名为 settings.xml

image

3. 在 settings.xml 文件中将 syncMethod 更改为 sftp_ssh。

image

4. 从“工具”->“选项”->“跨平台”->“连接管理器”->“远程 header Intellisense 管理器”更新 header 缓存。 5.享受吧。

之前

image

image

之后

image

image

关于c - Visual Studio 2017 Linux 项目中无法识别 Linux 头文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43022494/

相关文章:

c - 为什么 64 位 Ubuntu 中的 8 字节数组 (C) 占用 16 字节?

c - 尝试从 js-ctypes 调用 pam_start 时出现 undefined symbol

c - 我的老师做了这个功能,但我不明白它有什么用

javascript - 如何使用 JS 引入移动和淡入淡出元素

c# Numericupdown 将值传递给整数

visual-studio - 从Visual Studio搜索中排除特定文件

c++ - 比较 float 变量

java - 使用 pkill 以编程方式终止使用 Java 的服务 MAC OS X Mountain Lion

c - disable_local_irq 和内核定时器

c - C中的cd命令和chdir()的使用