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?
Code I'm writing:
#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()
}
Visual Studio needs to download all remote headers in your localmachine for correct behavior of intellisense.
New method 'rsync_ssh' doesn't download all headers. You can use old method .zip via sftp_ssh.
0. Add remote connection.
Tools->Options->Cross Platform->Connection Manager
1. Select your connection Update from Tools->Options->Cross Platform->Connection Manager->Remote Headers Intellisense Manager. Next click on Explore button.
2. C:\Users[YourUser]\AppData\Local\Microsoft\Linux\HeaderCache\1.0[IdNumber] Rename the HeaderCache settings.xml.unused file to settings.xml
3. In the settings.xml file Change the syncMethod to sftp_ssh.
4. Update headers cache from Tools->Options->Cross Platform->Connection Manager->Remote Headers Intellisense Manager. 5. Enjoy.
Before
After
On my Linux system (Debian Jessie)
ucontext.h
is inusr/include
which in turn includessys/ucontext.h
whichgcc
will find inusr/include/i386-linux-gnu/sys
. The first defines the functionsgetcontext
andsetcontext
. The second defines the data structuresucontext_t
etc.On the Windows host, VCLinux has installed a copy of the second
ucontext.h
(which defines the data structures) inC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\Linux\include\usr\include\x86_64-linux-gnu\sys
. But the firstucontext.h
is not present.VCLinux/Visual Studio will compile and run this program on the Linux remote:
But IntelliSense will not know about the functions
getcontext
andsetcontext
or the associated data structures. So you will get little red squiggles under the names and no completion assistance.You can take a copy of the first
ucontext.h
and put it inC:\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.Note: Windows paths are for Visual Studio 2015. They will be different for 2017.
Applies to VCLinux 1.0.6.
==============
Update 10-Apr-18
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.