SDL2 - Cross-Platform Open URL Command?


Working on an older SDL2 game project now.
Is there a cross-platform open URL command?(Windows/macOS/Linux)
Let us know, thanks!


1 Like

Look at my implementation for win32, ios, Android


I don’t see the actual code that opens a URL?
Also, I need this for Windows/macOS/Linux.


#include “ProcInfo/procinfo.h”

// Windows
process_execute(“start “””);

process_execute("open “”);

// Linux
process_execute("xdg-open “”);

The repository at that link includes a lot of other useful functions, for example, you can wait for the browser window to open by checking if pids_from_ppid(ppid) does not equal an empty string and recursively convert the string to a process id and check that function again until you get the browser pid, then check that against pid_from_top to get the topmost process, and then get the browser window id from wid_from_top and lastly make the browser a child window (requires converting window handle of the parent window to a window id using wid_from_window()) this allows the browser to stay on top of the game window and works even on mac (figuring this out on mac was a nightmare)


We have Windows open URL working:

#ifdef __WIN32__
    #include <windows.h>
    #include <shellapi.h>
// ...
#ifdef __WIN32__
    ShellExecute(NULL, "open", "", NULL, NULL, SW_SHOWNORMAL);

Just need macOS and Linux…


Without all the extra fluff its simply

#include <stdlib.h>

system(“commands in my previous post”)

Got it working, thanks!