Raylib 库在 C++ 项目中未正确链接

Raylib Library is not linking correctly in C++ project

提问人:Alex 提问时间:3/27/2023 最后编辑:Alex 更新时间:3/27/2023 访问量:407

问:

当我编译时,我收到这些编译器错误gcc -g -o main.exe -Wall -std=c++11 -I./include/ -L./lib main.cpp -o main.exe -lraylib

C:\mingw-w64\bin/ld.exe: C:\Users\usr\AppData\Local\Temp\ccjms0zo.o: in function `_tcf_0':
c:/mingw-w64/lib/gcc/i686-w64-mingw32/12.1.0/include/c++/iostream:74: undefined reference to `std::ios_base::Init::~Init()'
C:\mingw-w64\bin/ld.exe: C:\Users\usr\AppData\Local\Temp\ccjms0zo.o: in function `_static_initialization_and_destruction_0':
c:/mingw-w64/lib/gcc/i686-w64-mingw32/12.1.0/include/c++/iostream:74: undefined reference to `std::ios_base::Init::Init()'    
collect2.exe: error: ld returned 1 exit status

我已经尝试重新链接并重新安装库。我还遵循了许多关于如何安装 Raylib 的教程。我尝试了不同的标志.我只是得到不同的错误g++ main.cpp -lraylib -lGL -lm -lpthread -ldl -lrt -lX11

C:\mingw-w64\bin/ld.exe: cannot find -lGL: No such file or directory
C:\mingw-w64\bin/ld.exe: cannot find -ldl: No such file or directory
C:\mingw-w64\bin/ld.exe: cannot find -lrt: No such file or directory
C:\mingw-w64\bin/ld.exe: cannot find -lX11: No such file or directory
collect2.exe: error: ld returned 1 exit status
c++ 编译 链接器错误 raylib .a

评论

0赞 Botje 3/27/2023
您必须使用 g++ 来链接 C++ 代码,因此第一个代码段被构造破坏。至于第二个:你省略了 and,它分别告诉编译器在哪里查找头文件和库的链接器。-I./include-L./lib
0赞 Alex 3/27/2023
我已将标志添加到第二个标志中,它看起来像这样,但我仍然收到相同的错误。g++ main.cpp -lraylib -I./include -L./lib -lGL -lm -lpthread -ldl -lrt -lX11

答: 暂无答案