简体   繁体   中英

VS17 SSH Linux unistd.h

I'm using Visual Studio 17 on a win7 system to program linux stuff.

My system is connected with a linux machine over SSH.

When I debug everything runs fine and the console output is correct.

But visual studio itselves gives me a view syntax errors due to not finding some include libraries. ()

I wonder why i get several errors while building but it is running fine while debugging...

In addition to that the syntax errors are very annoying...

Does someone know how to solve this?

Here an example code:

#include <unistd.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>

static int global_var = 1;
int main(void) {
    pid_t pid;
    int lokal_var = 1;
    switch (pid = fork()) {
    case -1:
        printf("X");
        break;
    case 0:
        sleep(1);   /* Kurze Pause */
        printf("X (%d) ---\n", getpid());
        printf("X = %d X : %p\n",
            global_var, &global_var);
        printf("X  = %d X ; %p\n",
            lokal_var, &lokal_var);
        fflush(stdout);
        ++global_var;
        ++lokal_var;
        printf("--- X (%d) ---\n", getpid());
        printf("global_var = %d X : %p\n",
            global_var, &global_var);
        printf("X  = %d X ; %p\n",
            lokal_var, &lokal_var);
        fflush(stdout);
        break;
    default:
        printf("--- X (%d) ---\n", getpid());
        printf("global_var = %d X : %p\n",
            global_var, &global_var);
        printf("lokal_var  = %d X ; %p\n",
            lokal_var, &lokal_var);
        fflush(stdout);
        sleep(2);
        printf("--- X (%d) ---\n", getpid());
        printf("global_var = %d X : %p\n",
            global_var, &global_var);
        printf("lokal_var  = %d X ; %p\n",
            lokal_var, &lokal_var);
        fflush(stdout);
        break;
    }
    return EXIT_SUCCESS;
}

Errors:

cannot open source "uinstd.h"

identifier "fork" is undefined

identifier "sleep" is undefined

identifier "getpid" is undefined

Go to your Project properties (Project -> Properties -> Configuration Properties -> C/C++ -> General) and in the field Additional Include Directories add the path to your .h file.

And be sure that your Configuration and Platform are the active ones. Example: Configuration: Active(Debug) Platform: Active(Win32).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM