简体   繁体   English

VS17 SSH Linux unistd.h

[英]VS17 SSH Linux unistd.h

I'm using Visual Studio 17 on a win7 system to program linux stuff. 我在win7系统上使用Visual Studio 17对Linux进行编程。

My system is connected with a linux machine over SSH. 我的系统通过SSH与Linux计算机连接。

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. 但是由于找不到一些包含库,Visual Studio本身给了我一个视图语法错误。 () ()

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" 无法开源“ uinstd.h”

identifier "fork" is undefined 标识符“ fork”未定义

identifier "sleep" is undefined 标识符“睡眠”未定义

identifier "getpid" is undefined 标识符“ getpid”未定义

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. 转到项目属性(项目->属性->配置属性-> C / C ++->常规),然后在“其他包含目录”字段中将路径添加到.h文件。

And be sure that your Configuration and Platform are the active ones. 并确保您的配置和平台处于活动状态。 Example: Configuration: Active(Debug) Platform: Active(Win32). 示例:配置:Active(Debug)平台:Active(Win32)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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