Build errors on Unix (undefined reference)

Apologies, I was wrong since I didn’t catch you were using cmake, and you are right, there is no need to add " -l " and so on, because this is cmake job.

Now, after reading the log, indeed the libSDL2 is not found at link time. Searching with cmake and SDL2 linking keywords, looks like a similar question was already asked there (if I’m not wrong):

and maybe:

Anyway, after some search, and If I was you, I’d try :slight_smile:


add_subdirectory(SDL)
# and right after :
include_directories(SDL/include)

# adapt to your need
add_executable(${PROJECT_NAME}
    ${SOURCES}
  )

# and at the end, the linking step
# replace SDL2-static with SDL2 if shared library
  target_link_libraries(${PROJECT_NAME}
    SDL2-static
    (other libs)
  )


Last but not least : don’t forget to delete CMakeCache.txt after every try, to avoid corrupted env.

Feel free to correct me if I was wrong.

EDIT : fixed wrong order, sorry

HTH

1 Like