简体   繁体   中英

SDL2 undefined reference to `SDL_CreateWindowAndRenderer'

This is my class code:

#include <SDL2/SDL.h>

#include "graphics.h"

/* Graphics class
 * Holds all information dealing with graphics for the game
 */

Graphics::Graphics() {
    SDL_CreateWindowAndRenderer(640, 480, 0, &this->_window, &this->_renderer);
    SDL_SetWindowTitle(this->_window, "Cavestory");

}


Graphics::~Graphics() {
    SDL_DestroyWindow(this->_window);
}

this is the error:

g++ "-LC:\\MinGW\\lib" -o cavestory-developement.exe "source\\src\\cavestory-developement.o" "source\\src\\graphics.o" -lmingw32 -lSDL2main -lSDL2 
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: source\src\graphics.o: in function `ZN8GraphicsC2Ev':
C:\Users\John Park\eclipse-workspace\cavestory-developement\Debug/../source/src/graphics.cpp:10: undefined reference to `SDL_CreateWindowAndRenderer'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\John Park\eclipse-workspace\cavestory-developement\Debug/../source/src/graphics.cpp:11: undefined reference to `SDL_SetWindowTitle'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: source\src\graphics.o: in function `ZN8GraphicsD2Ev':
C:\Users\John Park\eclipse-workspace\cavestory-developement\Debug/../source/src/graphics.cpp:17: undefined reference to `SDL_DestroyWindow'
collect2.exe: error: ld returned 1 exit status

19:06:06 Build Failed. 5 errors, 0 warnings. (took 223ms)
______________________________________________________________________________________________________

not sure why SDL_SetWindowTitle is recognized (shows parameters and details about the function) when I hover over it with my mouse, but SDL_CreateWindowAndRenderer and SDL_DestroyWindow are not.

It compile fine for me on Fedora 32 x86_64, both as a native program and as a Windows program:

echo 'struct Graphics { Graphics(); ~Graphics(); SDL_Window *_window; SDL_Renderer *_renderer; } g;int main(int argc,char **argv){return 0;}' >graphics.h;g++ -o sdl2 sdl2.C -Wall -g $(pkg-config --cflags --libs sdl2);sudo dnf install mingw64-SDL2 mingw64-gcc-c++;x86_64-w64-mingw32-c++ -o sdl2.exe sdl2.C -Wall -g $(/usr/x86_64-w64-mingw32/sys-root/mingw/bin/sdl2-config --cflags --libs);(d=$PWD;cd /usr/x86_64-w64-mingw32/sys-root/mingw/bin;wine64 $d/sdl2.exe)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM