gcc-警告:函数'get_int'的隐式声明

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

我正在做CS50课程,并决定从那里在我的PC上运行代码。

我有以下代码:

#include "cs50.h"
#include <stdio.h>

int main(void)
{
    int n;
    do
    {
        //gets an integer from a user
        n = get_int("Height: ");
    }
    while (n < 1 || n > 8);
    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j < n * 2 + 2; j++)
        {
            //prints hashes only if j is more or equal to n - 1 
            if (j >= n - i && j <= n - 1)
            {
                printf("#");
            }
            //prints empty spaces to make the pyromide right alinged
            else if (j <= n - i)
            {
                printf(" ");
            }

            //makes empty spaces between two pyromids
            else if (j >= n - 1 && j <= n + 1)
            {
                printf(" ");
            }

            //adds hashes for the second pyromid
            else if (j >= n + 2 && j <= n + 1 + i)
            {
                printf("#");
            }

        }
        //starts a new line after finishing the code
        printf("\n");
    }
}

并且当我尝试编译它时,发生这种情况:

gcc cs50.o mario.c -o mario.exe -std=c99 -lcs50
mario.c: In function 'main':
mario.c:10:9: warning: implicit declaration of function 'get_int' [-Wimplicit-function-declaration]
         n = get_int("Height: ");
         ^
C:/Program Files (x86)/Dev-Cpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lcs50
collect2.exe: error: ld returned 1 exit status

我正在Windows PC上使用gcc编译器。我还从here下载了cs50库,并尝试了多种方式来编译和运行我的代码。

例如,我尝试使用此行gcc -c cs50.c从cs50.c和cs50.h构建中间文件,它创建了一个名为cs50.o的对象,将其链接也无效。将cs50库与此-lcs50链接的最后一次尝试也没有执行任何操作。

我尝试使用以下方法,但它们对我也不起作用:

c windows gcc cs50 gcc-warning
1个回答
0
投票

Jonathan Leffler正如您所建议的那样。非常感谢您帮助解决此问题。现在编译器可以工作了,我可以运行该程序。

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