如何在Visual Studio Code上修复此错误?

How can I fix this error on visual studio code?

提问人:Christopher 提问时间:11/5/2023 最后编辑:wohlstadChristopher 更新时间:11/5/2023 访问量:77

问:

我是 C 的新手,我正在尝试在 raylib 中创建一个窗口,我的编译器是 clang,但它一直给我一个错误,我需要帮助修复,这是我的代码:

#include "raylib.h"

int main(void)
{
    const int screenWidth = 800;
    const int screenHeight = 450;

    InitWindow(screenWidth, screenHeight, "raylib  example - basic window");

    SetTargetFPS(60);               
    
    // Main game loop
    while (!WindowShouldClose())    
    {
        BeginDrawing();
            ClearBackground(RAYWHITE);
            DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
        EndDrawing();
    }
    
    CloseWindow();        

    return 0;
} 

它给了我这个错误:

Undefined symbols for architecture x86_64:
  "_BeginDrawing", referenced from:
      _main in raytest-8c368e.o
  "_ClearBackground", referenced from:
      _main in raytest-8c368e.o
  "_CloseWindow", referenced from:
      _main in raytest-8c368e.o
  "_DrawText", referenced from:
      _main in raytest-8c368e.o
  "_EndDrawing", referenced from:
      _main in raytest-8c368e.o
  "_InitWindow", referenced from:
      _main in raytest-8c368e.o
  "_SetTargetFPS", referenced from:
      _main in raytest-8c368e.o
  "_WindowShouldClose", referenced from:
      _main in raytest-8c368e.o
ld: symbol(s) not found for architecture x86_64

如何解决此问题???

c 雷利库

评论

5赞 Ted Lyngmo 11/5/2023
看起来您忘记了与 raylib 库的链接。编译时添加。-lraylib
3赞 David C. Rankin 11/5/2023
Man Ted,几乎就像你以前遇到过一两次这种类型的问题一样 有关进一步的讨论,请参阅 VSCode c++ task.json 包含路径和库:)
0赞 Christopher 11/5/2023
谢谢,但我忘了提到我在 Mac OS 上并且在同一文件夹中有 raylib。它只是说.Admins-MacBook-Pro-2:C admin$ -lraylib
0赞 Ted Lyngmo 11/8/2023
clang -o raytest raytest.c -L . -lraylib
0赞 Christopher 11/8/2023
谢谢!我想你不是故意放“raytest”,因为当我有它时它说没有这样的文件或目录,但是当我删除它时,它说没有输入文件。

答: 暂无答案