You are not logged in.

#1 2020-01-14 23:02:12

Registered: 2020-01-14
Posts: 8

[SOLVED] How to install sdl2, an undefined reference when compiling.

I have a personal project that uses sdl2 and in ubuntu I needed the libsdl2-dev library (I installed arch a few days ago).
I read that Arch has no development packages and would only need to install sdl2, but installing and without installing sdl2 I get the same error

/usr/bin/ld: principal.c++:(.text+0x7f5): referencia a `SDL_GL_SetAttribute' sin definir
/usr/bin/ld: principal.c++:(.text+0x808): referencia a `SDL_SetHint' sin definir
/usr/bin/ld: principal.c++:(.text+0x82f): referencia a `SDL_CreateWindow' sin definir
/usr/bin/ld: principal.c++:(.text+0x83a): referencia a `SDL_GL_CreateContext' sin definir
/usr/bin/ld: principal.c++:(.text+0x844): referencia a `SDL_GL_SetSwapInterval' sin definir
/usr/bin/ld: principal.c++:(.text+0x893): referencia a `SDL_PollEvent' sin definir
/usr/bin/ld: principal.c++:(.text+0x8c1): referencia a `SDL_GL_SwapWindow' sin definir

In my CMakeList I have put "message" printing SDL2_INCLUDE_DIRS and contains nothing.

find_package(SDL2 REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1 -march=native")
add_executable(${PROJECT_NAME} ${todo})
target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARIES})

I speak Spanish sorry for the mistakes.

Last edited by Carlos20 (2020-01-16 01:07:05)


#2 2020-01-15 11:06:02

From: Netherlands, Europe
Registered: 2005-10-04
Posts: 8,359

Re: [SOLVED] How to install sdl2, an undefined reference when compiling.

Please use [ code ] tags for such outputs , see [1]

To get output in english you can prepend LC_ALL=C  to commands[2]

Now to the actual problem :

cmake find_package uses a specially crafted path to search for packages[3] , on archlinux that method fails very often.
Fortunately there's a much better alternative : tell cmake to use pkgconfig info. [4] … e#29316084 has a discussion and examples how to use cmake + pkgconfig to find sdl2 .


[2] … s_and_code

[3] … -procedure

[4] … onfig.html

Last edited by Lone_Wolf (2020-01-15 11:06:29)

Multi-init booting with apg Openrc and systemd coexisting
Automounting : not needed, i prefer pmount
Aur helpers : makepkg + my own local repo === rarely need them


#3 2020-01-15 13:46:11

Registered: 2020-01-14
Posts: 8

Re: [SOLVED] How to install sdl2, an undefined reference when compiling.

Thank you it worked.
It is incredible that all the dependencies that I had were already installed with the system.
sdl2 installed by ffmpeg

In ubuntu I had to install all this

and in arch everything is ready.

New cmake

find_package(PkgConfig REQUIRED)
#find_package(SDL2 REQUIRED)
pkg_check_modules(SDL2 REQUIRED sdl2)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1 -march=native")
add_executable(${PROJECT_NAME} ${todo})
target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARIES})
target_include_directories(${PROJECT_NAME} PUBLIC ${SDL2_INCLUDE_DIRS})
target_compile_options(${PROJECT_NAME} PUBLIC ${SDL2_CFLAGS_OTHER})

Last edited by Carlos20 (2020-01-16 01:09:46)


Board footer

Powered by FluxBB