在C中未定义对select@20的引用

问题描述 投票:1回答:1

我想给用户一定的时间进入移动,我发现一个教程,特点是 fflush()select()但是,出现了一个错误。

未定义对select@20的引用

我的一个脱胎换骨版本的代码。

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

int main() {
    struct timeval tmo;
    fd_set readfds;

    for (int x = 0;;x++) {
        do {
        printf("\nEnter a move: ");
        fflush(stdout);

        /* wait only 5 seconds for user input */
        FD_ZERO(&readfds);
        FD_SET(0, &readfds);
        tmo.tv_sec = 5;
        tmo.tv_usec = 0;

        switch (select(1, &readfds, NULL, NULL, &tmo)) {
        case -1:
            err(1, "select");
            break;
        case 0:
            printf("User didn't give an input.");
            return (1);
        }

        scanf(" %c", &userInput);
        translateUserInput(userInput, &dx, &dy);
        }
        while (!isDirectionOk(field, snake, dx, dy));
    }
}

对了,我用的是Windows系统

c input linker-errors
1个回答
1
投票

你需要链接 Ws2_32.lib.

如果你使用的是MinGW,这个库叫做 libwsock32.a.

对于任何使用Code::Blocks的人来说,去Project -> Build Options -> Linker Settings -> Add -> libwsock32.a。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.