How to compile and link a library (SDL) with g ++ so that I have a separate program?

I am using MinGW on Windows 7.

Simply put, I want to create a Hello World SDL program (initiate a window or something simple) and compile it so that I have a separate program that I can distribute without, say, users who need to install something additional (for example by putting SDL.dll in the Windows folder).

  • I downloaded the SDL development library, which is currently sitting in c:\SDL .
  • In my project folder, I have test.cpp and SDL.dll

I'm not too sure what to do next; At first I thought that I could enable SDL, and then just a link to the DLL on the command line and voila, but maybe I think I need to compile the SDL development library with my program first? My only goal is for my SDL program to be completed in a folder that I can distribute to other Windows platforms without requiring them to install anything extra - or did they definitely need to install SDL.dll in the Windows folder?

EDIT: Further clarification - can someone describe the steps that I will take to do this? I mean, what would the developer want to distribute his application? Does most game installers install .dll files in the Windows folder, if such applications are installed?

Source (test.cpp):

 #include <SDL/SDL.h> #include <iostream> using namespace std; int main () { cout << "Hello World!"; return 0; } 

Folder:

test.cpp SDL.dll

Command line:

g++ test.cpp -lSDL

Output:

test.cpp:2:17: fatal error: SDL.h: No such file or directory compilation terminated

+4
source share
1 answer

includes SDL and then just a link to a dll on the command line and voila

Yes, pretty much that.

but maybe I think I need to compile the SDL development library with my program first?

What? If you are not developing an embedded system, there is no separate "development" library. You are contacting the same DLL that will be loaded when your program starts.

+2
source

Source: https://habr.com/ru/post/1443376/


All Articles