error with building sdl_img

im trying to build sdl_img and i keep getting these errors

FAILED: showimage 
: && /usr/bin/gcc -O3 -DNDEBUG  CMakeFiles/showimage.dir/showimage.c.o -o showimage  libSDL2_image.a  /home/alyssa/coding/test2/build/x86_64-linux-gnu_Release/chalet_external/sdl/libSDL2.a && :
/usr/bin/ld: /home/alyssa/coding/test2/build/x86_64-linux-gnu_Release/chalet_external/sdl/libSDL2.a(SDL_stdlib.c.o): in function SDL_atan_REAL':
SDL_stdlib.c:(.text+0x1): undefined reference to atan'

FAILED: showanim 
: && /usr/bin/gcc -O3 -DNDEBUG  CMakeFiles/showanim.dir/showanim.c.o -o showanim  libSDL2_image.a  /home/alyssa/coding/test2/build/x86_64-linux-gnu_Release/chalet_external/sdl/libSDL2.a && :
/usr/bin/ld: /home/alyssa/coding/test2/build/x86_64-linux-gnu_Release/chalet_external/sdl/libSDL2.a(SDL_stdlib.c.o): in function SDL_atan_REAL':
SDL_stdlib.c:(.text+0x1): undefined reference to 'atan`

is there some cmake options im missing or what versions of sdl are sdl_img compatable with

Hello, “undefined reférence” means an object implementation (atan here) is missing, and you’ll find it inside a library (and that’s why you’ll have to link this library).

I’m probably not too wrong saying the missing library is the math library, so you’ll need to add -lm somewhere to make the linking work. You are probably building on Linux, where this step is mandatory.

I think you can add the following line in the CMakeLists.txt file:

EDIT : sorry, I was plain wrong. A working change could better be something like.

if (UNIX)
target_link_libraries( SDL2main  m)
endif()

IMPORTANT : I’m not testing and I’m unsure : please someone correct me if I’m wrong !

my 2 cents :slight_smile: