当我的 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 管理器更新。 接下来单击探索按钮。
2. C:\Users[你的用户]\AppData\Local\Microsoft\Linux\HeaderCache\1.0[IdNumber] 将 HeaderCache settings.xml.unused 文件重命名为 settings.xml
3. 在 settings.xml 文件中将 syncMethod 更改为 sftp_ssh。
4. 从“工具”->“选项”->“跨平台”->“连接管理器”->“远程 header Intellisense 管理器”更新 header 缓存。 5.享受吧。
之前
之后
关于c - Visual Studio 2017 Linux 项目中无法识别 Linux 头文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43022494/