在Code::Blocks中编译raylib程序时遇链接错误求助
解决Code::Blocks中raylib编译链接错误
我在Code::Blocks中配置raylib库,编译时出现大量未定义引用的链接错误,错误信息如下:
-------------- Build: Debug in teste (compiler: GNU GCC Compiler)--------------- gcc.exe -LC:\Users\tiago\Documents\raylib -o bin\Debug\teste.exe obj\Debug\main.o C:\Users\tiago\Documents\raylib\libraylib.a C:\MinGW\bin/ld.exe: C:\Users\tiago\Documents\raylib\libraylib.a(rcore.o):rcore.c:(.text+0x16ba2): undefined reference to `timeEndPeriod@4' C:\MinGW\bin/ld.exe: C:\Users\tiago\Documents\raylib\libraylib.a(rcore.o):rcore.c:(.text+0x1c8cb): undefined reference to `timeBeginPeriod@4' C:\MinGW\bin/ld.exe: C:\Users\tiago\Documents\raylib\libraylib.a(rglfw.o):rglfw.c:(.text+0x18e3): undefined reference to `_imp__CreateRectRgn@16' C:\MinGW\bin/ld.exe: C:\Users\tiago\Documents\raylib\libraylib.a(rglfw.o):rglfw.c:(.text+0x1927): undefined reference to `_imp__DeleteObject@4' C:\MinGW\bin/ld.exe: C:\Users\tiago\Documents\raylib\libraylib.a(rglfw.o):rglfw.c:(.text+0x198c): undefined reference to `_imp__SwapBuffers@4' C:\MinGW\bin/ld.exe: C:\Users\tiago\Documents\raylib\libraylib.a(rglfw.o):rglfw.c:(.text+0x245d): undefined reference to `_imp__GetDeviceCaps@8' C:\MinGW\bin/ld.exe: C:\Users\tiago\Documents\raylib\libraylib.a(rglfw.o):rglfw.c:(.text+0x2b3a): undefined reference to `_imp__CreateDCW@16' C:\MinGW\bin/ld.exe: C:\Users\tiago\Documents\raylib\libraylib.a(rglfw.o):rglfw.c:(.text+0x2b50): undefined reference to `_imp__GetDeviceGammaRamp@8' C:\MinGW\bin/ld.exe: C:\Users\tiago\Documents\raylib\libraylib.a(rglfw.o):rglfw.c:(.text+0x2b5c): undefined reference to `_imp__DeleteDC@4' C:\MinGW\bin/ld.exe: C:\Users\tiago\Documents\raylib\libraylib.a(rglfw.o):rglfw.c:(.text+0x65b6): undefined reference to `_imp__CreateDCW@16' C:\MinGW\bin/ld.exe: C:\Users\tiago\Documents\raylib\libraylib.a(rglfw.o):rglfw.c:(.text+0x65ef): undefined reference to `_imp__GetDeviceCaps@8' C:\MinGW\bin/ld.exe: C:\Users\tiago\Documents\raylib\libraylib.a(rglfw.o):rglfw.c:(.text+0x661d): undefined reference to `_imp__DeleteDC@4' C:\MinGW\bin/ld.exe: C:\Users\tiago\Documents\raylib\libraylib.a(rglfw.o):rglfw.c:(.text+0x67ba): undefined reference to `_imp__GetDeviceCaps@8' C:\MinGW\bin/ld.exe: C:\Users\tiago\Documents\raylib\libraylib.a(rglfw.o):rglfw.c:(.text+0x6a5f): undefined reference to `_imp__CreateDIBSection@24' C:\MinGW\bin/ld.exe: C:\Users\tiago\Documents\raylib\libraylib.a(rglfw.o):rglfw.c:(.text+0x6aaa): undefined reference to `_imp__CreateBitmap@20' C:\MinGW\bin/ld.exe: C:\Users\tiago\Documents\raylib\libraylib.a(rglfw.o):rglfw.c:(.text+0x6b44): undefined reference to `_imp__DeleteObject@4' C:\MinGW\bin/ld.exe: C:\Users\tiago\Documents\raylib\libraylib.a(rglfw.o):rglfw.c:(.text+0x6b97): undefined reference to `_imp__DeleteObject@4' C:\MinGW\bin/ld.exe: C:\Users\tiago\Documents\raylib\libraylib.a(rglfw.o):rglfw.c:(.text+0x8574): undefined reference to `_imp__CreateDCW@16' C:\MinGW\bin/ld.exe: C:\Users\tiago\Documents\raylib\libraylib.a(rglfw.o):rglfw.c:(.text+0x8586): undefined reference to `_imp__SetDeviceGammaRamp@8' C:\MinGW\bin/ld.exe: C:\Users\tiago\Documents\raylib\libraylib.a(rglfw.o):rglfw.c:(.text+0x8592): undefined reference to `_imp__DeleteDC@4' C:\MinGW\bin/ld.exe: C:\Users\tiago\Documents\raylib\libraylib.a(rglfw.o):rglfw.c:(.text+0xe947): undefined reference to `_imp__ChoosePixelFormat@8' C:\MinGW\bin/ld.exe: C:\Users\tiago\Documents\raylib\libraylib.a(rglfw.o):rglfw.c:(.text+0xe95b): undefined reference to `_imp__SetPixelFormat@12' C:\MinGW\bin/ld.exe: C:\Users\tiago\Documents\raylib\libraylib.a(rglfw.o):rglfw.c:(.text+0xedf2): undefined reference to `_imp__DescribePixelFormat@16' C:\MinGW\bin/ld.exe: C:\Users\tiago\Documents\raylib\libraylib.a(rglfw.o):rglfw.c:(.text+0xeee5): undefined reference to `_imp__DescribePixelFormat@16' C:\MinGW\bin/ld.exe: C:\Users\tiago\Documents\raylib\libraylib.a(rglfw.o):rglfw.c:(.text+0xf2ff): undefined reference to `_imp__DescribePixelFormat@16' C:\MinGW\bin/ld.exe: C:\Users\tiago\Documents\raylib\libraylib.a(rglfw.o):rglfw.c:(.text+0xf32a): undefined reference to `_imp__SetPixelFormat@12' collect2.exe: error: ld returned 1 exit status Process terminated with status 1 (0 minute(s), 0 second(s)) 27 error(s), 0 warning(s) (0 minute(s), 0 second(s))
解决方案
这些未定义的函数都属于Windows系统库,需要在链接时显式指定依赖:
- 打开Code::Blocks,点击顶部菜单栏的
Project->Build options - 在左侧列表选中你的项目,切换到
Linker settings标签页 - 在
Other linker options输入框中添加以下内容:-lgdi32 -lwinmm -luser32 - 点击
OK保存设置,重新编译项目
说明
timeBeginPeriod/timeEndPeriod属于winmm.lib(多媒体定时库)CreateRectRgn/SwapBuffers/GetDeviceCaps等图形相关函数属于gdi32.lib(图形设备接口库)- 部分用户界面相关函数属于
user32.lib
内容的提问来源于stack exchange,提问作者Albino Almeida
相关产品推荐
相关产品推荐

