Background info
As the title says, I am on Ubuntu 16.04 using CLion and G++, and I am unable to link SDL2.
SDL2.h is found in the project at External Libraries/Header Search Paths/include/SDL2. This seems to link to /usr/include/SDL2.
So, with the header file found, I can #include <SDL2/SDL.h> without any issues. Yet, when I try to make use of SDL2 with something like, SDL_Init( SDL_INIT_EVERYTHING ), I get an undefined reference.
If I compile from terminal with g++ main.cpp -lSDL2 -o test I have no errors. But, if I compile from terminal with g++ main.cpp -o test, then I have the same error as CLion!
Question
How do I link SDL2 to Cmake? Did I add this flag -lsdl2 to the CMake file correctly? If I added it properly, then what am I missing?
main.cpp
#include <iostream>
#include <SDL2/SDL.h>
int main(int argc, char* argv[]) {
SDL_Init( SDL_INIT_EVERYTHING );
std::cout << "Hello, World!" << std::endl;
SDL_Quit();
return 0;
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.12)
project(untitled2)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lSDL2")
add_executable(untitled2 main.cpp)