0

I'm learning C and in general I code with VS Code in Ubuntu. For convenience, I'm trying to migrate my learning materials to Windows where a lot of my other works happen, so I installed WSL 2 and its distro Ubuntu 18.04 LTS. After installing VS Code for Windows and its remote extension to work with WSL, I boot up a new WSL session in VS Code, install the C/C++ extension with IntelliSense then write a simple program like below just for demonstration:

#include <signal.h> int main() { kill(-1, SIGKILL); } 

The problem with VS Code is that while the program compiles, its IntelliSense doesn't detect the kill function in the signal.h header. By further investigating the header file, I observe that the following part is darkened

#ifdef __USE_POSIX extern int kill (__pid_t __pid, int __sig) __THROW; #endif /* Use POSIX. */ 

along with other parts where __USE_POSIX is checked, including but not limited to siginfo_t, struct sigaction.

Is there a way to make VS Code recognise these macros/variables to enable IntelliSense's assistance?

2 Answers 2

0

You could either add #define __USE_POSIX above where you include the header in question, or if you want to define it as a compiler arg (Perhaps through a -D flag or via CMake or something), the file .vscode/c_cpp_properties.json allows you to specify which flags are being used this way like so:

"configurations": [{ "defines":["__USE_POSIX"] }] 

See https://github.com/Microsoft/vscode-cpptools/issues/304 for further information on this feature.

-1

the following config is effective

"configurations": [{ "defines": ["_XOPEN_SOURCE"] }] 
1
  • Please explain how to use this.  Also, can you explain how/why it works? Commented Aug 19, 2024 at 18:58

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.