How to use IMG_Load on macOS Mojave and Ubuntu 18?

What is the right way to use IMG_Load(const char*) on macOS Mojave and Ubuntu 18?

I’m following the Let’s Make Games tutorial on youtube, specifically the TextureManager one: https://youtu.be/RqvpkZ7I1aU

I can open a window with SDL2 but IMG_Load(cost char*) can’t be referenced.

On macOS Mojave I’m using CLion 2019.2 just to write the code, building and compiling on the command line with CMake 3.15.3, and have installed sdl2 and sdl2_image using brew. The SDL.h and SLD_image.h files are in usr/local/include/SDL2/. Neither CLion nor CMake (using clang++ I think) find the SDL_image.h header file.

I’ve tried using
#include <SDL_image/SDL_image.h>
and
#include <SDL_image.h>
and
#include “SDL_image.h”

I see that file /usr/local/include/SDL2/SDL.h does not reference /usr/local/include/SDL2/SDL_image.h. So we must have to include it separately. But I’m very confused why <SDL.h> works and <SDL_image.h> doesn’t.

On Ubuntu 18.04.3 LTS (running on VMWare Professional Version 10.1.6) the headers are /usr/include/SDL2/SDL.h and /usr/include/SDL2/SDL_image.h. I installed libsdl2-image-2.0-0 and libsdl2-image-dev as well as other libsdl2 dev using apt.

Any help is appreciated. Thanks,
-boz

You need to tell the compiler where to find the SDL_image headers and library

Thanks for the reply @sjr … yes, this was more about my learning CMake than SDL.

Eventually I found https://github.com/trenki2/SDL2Test.git and it works.

Specifically, I created a cmake directory in my project and copied the FindSDL2.cmake and FindSDL2_image.cmake files into it. Then added this in my CMakeLists.txt

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
find_package(SDL2 REQUIRED)
find_package(SDL2_image REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS} ${SDL2_IMAGE_INCLUDE_DIRS})
target_link_libraries(lame-game ${SDL2_LIBRARIES} ${SDL2_IMAGE_LIBRARIES})