SDL_PixelFormatEnumToMasks() 导致编译问题
SDL_PixelFormatEnumToMasks() causing compilation issues
我觉得我犯了一个我找不到的简单错误,每当我编译这段代码时,它都会把我带到一个名为 'Makefile.win' 的文件,并返回一堆关于 [=20] 参数的编译器错误=]().
代码:
#include <SDL.h>
int main( int argc, char *args[] )
{
Uint32 format = SDL_PIXELFORMAT_RGB888;
extern int bpp;
extern Uint32 Rmask, Gmask, Bmask, Amask;
SDL_PixelFormatEnumToMasks(format, &bpp, &Rmask, &Gmask, &Bmask, &Amask);
}
错误:
main.cpp:(.rdata$.refptr.bpp[.refptr.bpp]+0x0): undefined reference to
'bpp'
main.cpp:(.rdata$.refptr.Rmask[.refptr.Rmask]+0x0): undefined
reference to 'Rmask'
main.cpp:(.rdata$.refptr.Gmask[.refptr.Gmask]+0x0): undefined
reference to 'Gmask'
main.cpp:(.rdata$.refptr.Bmask[.refptr.Bmask]+0x0): undefined
reference to 'Bmask'
main.cpp:(.rdata$.refptr.Amask[.refptr.Amask]+0x0): undefined
reference to 'Amask' [Error] ld returned 1 exit status recipe for
target 'Project3.exe' failed
您将变量声明为 extern
。对于编译器,这意味着这些变量是在另一个文件的另一个范围内定义的,并尝试在您与 main.cpp
.
链接的任何 library/file 中找到它
如果您只是想使用像 format
这样的变量,请不要将其声明为 extern
。
我觉得我犯了一个我找不到的简单错误,每当我编译这段代码时,它都会把我带到一个名为 'Makefile.win' 的文件,并返回一堆关于 [=20] 参数的编译器错误=]().
代码:
#include <SDL.h>
int main( int argc, char *args[] )
{
Uint32 format = SDL_PIXELFORMAT_RGB888;
extern int bpp;
extern Uint32 Rmask, Gmask, Bmask, Amask;
SDL_PixelFormatEnumToMasks(format, &bpp, &Rmask, &Gmask, &Bmask, &Amask);
}
错误:
main.cpp:(.rdata$.refptr.bpp[.refptr.bpp]+0x0): undefined reference to 'bpp'
main.cpp:(.rdata$.refptr.Rmask[.refptr.Rmask]+0x0): undefined reference to 'Rmask'
main.cpp:(.rdata$.refptr.Gmask[.refptr.Gmask]+0x0): undefined reference to 'Gmask'
main.cpp:(.rdata$.refptr.Bmask[.refptr.Bmask]+0x0): undefined reference to 'Bmask'
main.cpp:(.rdata$.refptr.Amask[.refptr.Amask]+0x0): undefined reference to 'Amask' [Error] ld returned 1 exit status recipe for target 'Project3.exe' failed
您将变量声明为 extern
。对于编译器,这意味着这些变量是在另一个文件的另一个范围内定义的,并尝试在您与 main.cpp
.
如果您只是想使用像 format
这样的变量,请不要将其声明为 extern
。