You are not logged in.

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

Carlos20
Member
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)
include_directories(${SDL2_INCLUDE_DIRS})
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)

Offline

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

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 11,911

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]

https://stackoverflow.com/questions/291 … e#29316084 has a discussion and examples how to use cmake + pkgconfig to find sdl2 .




[1] https://bbs.archlinux.org/help.php#bbcode

[2] https://wiki.archlinux.org/index.php/Co … s_and_code

[3] https://cmake.org/cmake/help/latest/com … -procedure

[4] https://cmake.org/cmake/help/latest/mod … onfig.html

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


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.


(A works at time B)  && (time C > time B ) ≠  (A works at time C)

Offline

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

Carlos20
Member
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
libglew-dev
libsdl2-dev
libglm-dev
libfreetype6-dev
libicu-dev

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)

Offline

Board footer

Powered by FluxBB