Jump to content
  • Advertisement
Sign in to follow this  
garyfletcher

problem linking SDL with libraries

This topic is 4992 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi again folks I am having seroius difficulties linking to the SDL dll library. I am using DEV-C++ v4.9.9.2 with XP pro. I have checked that the dll is installed, it is, I can even see it in the package manager. I have included the include DIR and made sure that the complier is using the dll dir when liking...but I still get the following errors: Complie log: Compiler: Default compiler Executing g++.exe... g++.exe "C:\SDL\TestSDL.cpp" -o "C:\SDL\TestSDL.exe" -I"include\c++\3.3.1\mingw32" -I"include\c++\3.3.1" -I"lib\gcc\mingw32\3.4.2\include" -I"include\c++\3.4.2\backward" -I"include\c++\3.4.2\mingw32" -I"include\c++\3.4.2" -I"include" -I"C:\Dev-Cpp\include\SDL" -L"lib" -L"C:\Dev-Cpp\dll" -L"C:\Dev-Cpp\dll\Redist" -lobjc C:\DOCUME~1\Gary\LOCALS~1\Temp/ccSWbaaa.o(.text+0x133):TestSDL.cpp: undefined reference to `SDL_Init' C:\DOCUME~1\Gary\LOCALS~1\Temp/ccSWbaaa.o(.text+0x13d):TestSDL.cpp: undefined reference to `SDL_GetError' C:\DOCUME~1\Gary\LOCALS~1\Temp/ccSWbaaa.o(.text+0x1c8):TestSDL.cpp: undefined reference to `SDL_Quit' C:/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.2/../../../libmingw32.a(main.o)(.text+0x106):main.c: undefined reference to `WinMain@16' collect2: ld returned 1 exit status Execution terminated The code is pretty simple: #include <iostream> #include "SDL.h" using namespace std; int main() { cout << "Quick program to see if SDL works currently with DEV-C++" << endl; /* Initialize defaults, Video and Audio */ if((SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO)==-1)) { cout << "Could not initialize SDL: " << SDL_GetError() << endl; return EXIT_FAILURE; } cout << "SDL initialized." << endl; cout << "Quiting SDL." << endl; /* Shutdown all subsystems */ SDL_Quit(); cout << "Quiting...." << endl; system("pause"); return EXIT_SUCCESS; } Any ideas?

Share this post


Link to post
Share on other sites
Advertisement
Your main should be: int main(int argc, char *argv[])

And you need to link with: -lmingw32 -lSDLmain -lSDL

If you don't know how to link, you just go to project settings -> Parameters -> add those under linker

The End, it's just that simple.

Share this post


Link to post
Share on other sites
You need to include the libraries specifically the directory just tells DEvCPP/mingw32 where to search for the files. Much like using the directory c:/sdl/include wont include sdl.h in your source.

Go to project -> project options -> parameters and add "-lSDLmain -lSDL" into the linker text area.

Share this post


Link to post
Share on other sites
Okay, done that. But now getting:

Compiler: Default compiler
Building Makefile: "C:\SDL\Makefile.win"
Executing make...
make.exe -f "C:\SDL\Makefile.win" all
g++.exe sdltest.o -o "sdltest.exe" -L"lib" -L"C:/Dev-Cpp/dll" -lmingw32 -lSDLmain -lSDL -lobjc

C:/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.2/../../../libSDLmain.a(SDL_main.o)(.text+0x307): undefined reference to `SDL_main'
collect2: ld returned 1 exit status

make.exe: *** [sdltest.exe] Error 1

Execution terminated

What am I missing?

Share this post


Link to post
Share on other sites
Quote:
Original post by garyfletcher
What am I missing?


DerAnged's post is exactly what you need to look at. Especially the way the main function is done.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!