sonic-pi-net / sonic-pi

Code. Music. Live.
https://sonic-pi.net
Other
10.85k stars 924 forks source link

Linux build fails with "undefined reference to __glew[...]" #3232

Open T-X opened 2 years ago

T-X commented 2 years ago

When trying to build a current sonic-pi "dev" branch on Linux / Debian Sid / amd64 arch linking seems to fail with various glew functions missing:

$ sudo apt-get install -y build-essential git libssl-dev ruby-dev elixir erlang-dev erlang-xmerl qttools5-dev qttools5-dev-tools libqt5svg5-dev libqt5opengl5-dev supercollider-server sc3-plugins-server alsa-utils jackd2 libjack-jackd2-dev libjack-jackd2-0 libasound2-dev pulseaudio-module-jack cmake ninja-build
[...]
$ git clone https://github.com/sonic-pi-net/sonic-pi.git
[...]
$ cd sonic-pi/app
$ ./linux-build-all.sh
[...]
Consolidate compiler generated dependencies of target QScintilla
[ 74%] Built target QScintilla
[ 74%] Automatic MOC and UIC for target sonic-pi
[ 74%] Built target sonic-pi_autogen
[ 74%] Automatic RCC for help_files.qrc
[ 75%] Automatic RCC for info_files.qrc
Consolidate compiler generated dependencies of target sonic-pi
[ 75%] Building CXX object gui/qt/CMakeFiles/sonic-pi.dir/mainwindow.cpp.o
[ 75%] Building CXX object gui/qt/CMakeFiles/sonic-pi.dir/utils/sonicpi_i18n.cpp.o
[ 75%] Building CXX object gui/qt/CMakeFiles/sonic-pi.dir/sonic-pi_autogen/EWIEGA46WW/qrc_help_files.cpp.o
[ 76%] Building CXX object gui/qt/CMakeFiles/sonic-pi.dir/sonic-pi_autogen/EWIEGA46WW/qrc_info_files.cpp.o
[ 76%] Linking CXX executable sonic-pi
[ 95%] Built target sonic-pi
Consolidate compiler generated dependencies of target sonic-pi-imgui
[ 96%] Linking CXX executable sonic-pi-imgui
/usr/bin/ld: CMakeFiles/sonic-pi-imgui.dir/backends/imgui_impl_opengl3.cpp.o: warning: relocation against `__glewBindBuffer' in read-only section `.text'
/usr/bin/ld: CMakeFiles/sonic-pi-imgui.dir/main.cpp.o: in function `main':
main.cpp:(.text+0x36f): undefined reference to `glewInit'
/usr/bin/ld: CMakeFiles/sonic-pi-imgui.dir/backends/imgui_impl_opengl3.cpp.o: in function `ImGui_ImplOpenGL3_SetupRenderState(ImDrawData*, int, int, unsigned int)':
imgui_impl_opengl3.cpp:(.text+0x1ed): undefined reference to `__glewBlendEquation'
/usr/bin/ld: imgui_impl_opengl3.cpp:(.text+0x3ba): undefined reference to `__glewUseProgram'
/usr/bin/ld: imgui_impl_opengl3.cpp:(.text+0x3cb): undefined reference to `__glewUniform1i'
/usr/bin/ld: imgui_impl_opengl3.cpp:(.text+0x3e1): undefined reference to `__glewUniformMatrix4fv'
/usr/bin/ld: imgui_impl_opengl3.cpp:(.text+0x411): undefined reference to `__glewBindSampler'
/usr/bin/ld: imgui_impl_opengl3.cpp:(.text+0x424): undefined reference to `__glewBindVertexArray'
/usr/bin/ld: imgui_impl_opengl3.cpp:(.text+0x432): undefined reference to `__glewBindBuffer'
/usr/bin/ld: imgui_impl_opengl3.cpp:(.text+0x448): undefined reference to `__glewBindBuffer'
/usr/bin/ld: imgui_impl_opengl3.cpp:(.text+0x45e): undefined reference to `__glewEnableVertexAttribArray'
/usr/bin/ld: imgui_impl_opengl3.cpp:(.text+0x46f): undefined reference to `__glewEnableVertexAttribArray'
/usr/bin/ld: imgui_impl_opengl3.cpp:(.text+0x480): undefined reference to `__glewEnableVertexAttribArray'
/usr/bin/ld: imgui_impl_opengl3.cpp:(.text+0x491): undefined reference to `__glewVertexAttribPointer'
/usr/bin/ld: imgui_impl_opengl3.cpp:(.text+0x4be): undefined reference to `__glewVertexAttribPointer'
/usr/bin/ld: imgui_impl_opengl3.cpp:(.text+0x4eb): undefined reference to `__glewVertexAttribPointer'
/usr/bin/ld: CMakeFiles/sonic-pi-imgui.dir/backends/imgui_impl_opengl3.cpp.o: in function `ImGui_ImplOpenGL3_RenderDrawData(ImDrawData*)':
imgui_impl_opengl3.cpp:(.text+0x598): undefined reference to `__glewActiveTexture'
/usr/bin/ld: imgui_impl_opengl3.cpp:(.text+0x71c): undefined reference to `__glewGenVertexArrays'
/usr/bin/ld: imgui_impl_opengl3.cpp:(.text+0x79e): undefined reference to `__glewBufferData'
/usr/bin/ld: imgui_impl_opengl3.cpp:(.text+0x7d8): undefined reference to `__glewBufferData'
[...]

Full build log here: sonic-pi-buildlog.txt

However libglew libraries seem to be installed:

$ dpkg -l | grep glew
ii  libglew-dev:amd64                                           2.2.0-4+b1                              amd64        OpenGL Extension Wrangler - development environment
ii  libglew2.2:amd64                                            2.2.0-4+b1                              amd64        OpenGL Extension Wrangler - runtime environment
ii  libglewmx1.13:amd64                                         1.13.0-5                                amd64        OpenGL Extension Wrangler (Multiple Rendering Contexts)
T-X commented 2 years ago

For the libglew issue I seem to be able to fix it with the following change:

$ git diff
diff --git a/app/gui/imgui/CMakeLists.txt b/app/gui/imgui/CMakeLists.txt
index 0cc68866d556..609b6928f70a 100644
--- a/app/gui/imgui/CMakeLists.txt
+++ b/app/gui/imgui/CMakeLists.txt
@@ -15,6 +15,7 @@ include(${CMAKE_CURRENT_LIST_DIR}/cmake/demo_common.cmake)
 find_package(gl3w CONFIG REQUIRED)
 find_package(SDL2 CONFIG REQUIRED)
 find_package(fmt CONFIG REQUIRED)
+find_package(GLEW REQUIRED)

 if (USE_SYSTEM_LIBS)
     set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
@@ -99,6 +100,7 @@ target_link_libraries (${APP_NAME}
     PRIVATE
     SonicPi::API
     fmt::fmt
+    GLEW::GLEW
     )

 if (USE_SYSTEM_LIBS)

However I'm still getting linker errors for SDL_waylandvideo.c due to various "undefined reference to libdecor[...]":

$ ./linux-build-all.sh
[...]
Consolidate compiler generated dependencies of target sonic-pi
[ 75%] Building CXX object gui/qt/CMakeFiles/sonic-pi.dir/mainwindow.cpp.o
[ 75%] Building CXX object gui/qt/CMakeFiles/sonic-pi.dir/utils/sonicpi_i18n.cpp.o
[ 75%] Building CXX object gui/qt/CMakeFiles/sonic-pi.dir/sonic-pi_autogen/EWIEGA46WW/qrc_help_files.cpp.o
[ 76%] Building CXX object gui/qt/CMakeFiles/sonic-pi.dir/sonic-pi_autogen/EWIEGA46WW/qrc_info_files.cpp.o
[ 76%] Linking CXX executable sonic-pi
[ 95%] Built target sonic-pi
Consolidate compiler generated dependencies of target sonic-pi-imgui
[ 96%] Linking CXX executable sonic-pi-imgui
/usr/bin/ld: /home/linus/dev-priv/sonic-pi/app/vcpkg/installed/x64-linux/debug/lib/libSDL2d.a(SDL_waylandvideo.c.o): in function `Wayland_LoadLibdecor':
/home/linus/dev-priv/sonic-pi/app/vcpkg/buildtrees/sdl2/src/bfc793b2ac-a3edea5847.clean/src/video/wayland/SDL_waylandvideo.c:948: undefined reference to `libdecor_new'
/usr/bin/ld: /home/linus/dev-priv/sonic-pi/app/vcpkg/installed/x64-linux/debug/lib/libSDL2d.a(SDL_waylandvideo.c.o): in function `Wayland_VideoQuit':
/home/linus/dev-priv/sonic-pi/app/vcpkg/buildtrees/sdl2/src/bfc793b2ac-a3edea5847.clean/src/video/wayland/SDL_waylandvideo.c:1098: undefined reference to `libdecor_unref'
/usr/bin/ld: /home/linus/dev-priv/sonic-pi/app/vcpkg/installed/x64-linux/debug/lib/libSDL2d.a(SDL_waylandwindow.c.o): in function `SetMinMaxDimensions':
/home/linus/dev-priv/sonic-pi/app/vcpkg/buildtrees/sdl2/src/bfc793b2ac-a3edea5847.clean/src/video/wayland/SDL_waylandwindow.c:349: undefined reference to `libdecor_frame_set_min_content_size'
/usr/bin/ld: /home/linus/dev-priv/sonic-pi/app/vcpkg/buildtrees/sdl2/src/bfc793b2ac-a3edea5847.clean/src/video/wayland/SDL_waylandwindow.c:352: undefined reference to `libdecor_frame_set_max_content_size'
/usr/bin/ld: /home/linus/dev-priv/sonic-pi/app/vcpkg/buildtrees/sdl2/src/bfc793b2ac-a3edea5847.clean/src/video/wayland/SDL_waylandwindow.c:357: undefined reference to `libdecor_state_new'
/usr/bin/ld: /home/linus/dev-priv/sonic-pi/app/vcpkg/buildtrees/sdl2/src/bfc793b2ac-a3edea5847.clean/src/video/wayland/SDL_waylandwindow.c:358: undefined reference to `libdecor_frame_commit'
/usr/bin/ld: /home/linus/dev-priv/sonic-pi/app/vcpkg/buildtrees/sdl2/src/bfc793b2ac-a3edea5847.clean/src/video/wayland/SDL_waylandwindow.c:359: undefined reference to `libdecor_state_free'
[...]

See previously uploaded/linked, full sonic-pi-buildlog.txt.

rbnpi commented 2 years ago

You may well need a more unto date elixir and Erlang. I'd try installing using the pi-install-elixir.sh script in app. Then restart your terminal and check that elixir loads from the .asdf folder in your user home folder. Also, you don't really need the imgui interface. I'd run the build-all script with parameter -n which prevents it from trying to build. EDIT I also usually install the latest cmake from snap. Some early versions can cause problems.

T-X commented 2 years ago

@rbnpi thanks for your help, building and running sonic-pi with "./linux-build-all.sh -n" worked indeed!

I would love to further help debugging the issue, but I'm a bit hesitant with updating tools user or even system wide. I was hoping that things on Debian Sid aka "unstable" would be new enough. (cmake: 3.24.2-2, elixir: 1.14.0.dfsg-2, erlang: 1:24.3.4.5+dfsg-1)

Btw. using "./linux-build-all.sh --system-libs -n" does not work for me (but I should probably file a new issue for that).

b08x commented 1 year ago

For the libglew issue I seem to be able to fix it with the following change:

$ git diff
diff --git a/app/gui/imgui/CMakeLists.txt b/app/gui/imgui/CMakeLists.txt
index 0cc68866d556..609b6928f70a 100644
--- a/app/gui/imgui/CMakeLists.txt
+++ b/app/gui/imgui/CMakeLists.txt
@@ -15,6 +15,7 @@ include(${CMAKE_CURRENT_LIST_DIR}/cmake/demo_common.cmake)
 find_package(gl3w CONFIG REQUIRED)
 find_package(SDL2 CONFIG REQUIRED)
 find_package(fmt CONFIG REQUIRED)
+find_package(GLEW REQUIRED)

 if (USE_SYSTEM_LIBS)
     set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
@@ -99,6 +100,7 @@ target_link_libraries (${APP_NAME}
     PRIVATE
     SonicPi::API
     fmt::fmt
+    GLEW::GLEW
     )

 if (USE_SYSTEM_LIBS)

However I'm still getting linker errors for SDL_waylandvideo.c due to various "undefined reference to libdecor[...]":

$ ./linux-build-all.sh
[...]
Consolidate compiler generated dependencies of target sonic-pi
[ 75%] Building CXX object gui/qt/CMakeFiles/sonic-pi.dir/mainwindow.cpp.o
[ 75%] Building CXX object gui/qt/CMakeFiles/sonic-pi.dir/utils/sonicpi_i18n.cpp.o
[ 75%] Building CXX object gui/qt/CMakeFiles/sonic-pi.dir/sonic-pi_autogen/EWIEGA46WW/qrc_help_files.cpp.o
[ 76%] Building CXX object gui/qt/CMakeFiles/sonic-pi.dir/sonic-pi_autogen/EWIEGA46WW/qrc_info_files.cpp.o
[ 76%] Linking CXX executable sonic-pi
[ 95%] Built target sonic-pi
Consolidate compiler generated dependencies of target sonic-pi-imgui
[ 96%] Linking CXX executable sonic-pi-imgui
/usr/bin/ld: /home/linus/dev-priv/sonic-pi/app/vcpkg/installed/x64-linux/debug/lib/libSDL2d.a(SDL_waylandvideo.c.o): in function `Wayland_LoadLibdecor':
/home/linus/dev-priv/sonic-pi/app/vcpkg/buildtrees/sdl2/src/bfc793b2ac-a3edea5847.clean/src/video/wayland/SDL_waylandvideo.c:948: undefined reference to `libdecor_new'
/usr/bin/ld: /home/linus/dev-priv/sonic-pi/app/vcpkg/installed/x64-linux/debug/lib/libSDL2d.a(SDL_waylandvideo.c.o): in function `Wayland_VideoQuit':
/home/linus/dev-priv/sonic-pi/app/vcpkg/buildtrees/sdl2/src/bfc793b2ac-a3edea5847.clean/src/video/wayland/SDL_waylandvideo.c:1098: undefined reference to `libdecor_unref'
/usr/bin/ld: /home/linus/dev-priv/sonic-pi/app/vcpkg/installed/x64-linux/debug/lib/libSDL2d.a(SDL_waylandwindow.c.o): in function `SetMinMaxDimensions':
/home/linus/dev-priv/sonic-pi/app/vcpkg/buildtrees/sdl2/src/bfc793b2ac-a3edea5847.clean/src/video/wayland/SDL_waylandwindow.c:349: undefined reference to `libdecor_frame_set_min_content_size'
/usr/bin/ld: /home/linus/dev-priv/sonic-pi/app/vcpkg/buildtrees/sdl2/src/bfc793b2ac-a3edea5847.clean/src/video/wayland/SDL_waylandwindow.c:352: undefined reference to `libdecor_frame_set_max_content_size'
/usr/bin/ld: /home/linus/dev-priv/sonic-pi/app/vcpkg/buildtrees/sdl2/src/bfc793b2ac-a3edea5847.clean/src/video/wayland/SDL_waylandwindow.c:357: undefined reference to `libdecor_state_new'
/usr/bin/ld: /home/linus/dev-priv/sonic-pi/app/vcpkg/buildtrees/sdl2/src/bfc793b2ac-a3edea5847.clean/src/video/wayland/SDL_waylandwindow.c:358: undefined reference to `libdecor_frame_commit'
/usr/bin/ld: /home/linus/dev-priv/sonic-pi/app/vcpkg/buildtrees/sdl2/src/bfc793b2ac-a3edea5847.clean/src/video/wayland/SDL_waylandwindow.c:359: undefined reference to `libdecor_state_free'
[...]

See previously uploaded/linked, full sonic-pi-buildlog.txt.

Check out this comment: https://github.com/microsoft/vcpkg/issues/25892#issuecomment-1272454574

libsdl2 libsdl2-dev are the packages I believe he is referring to.