diff mbox series

kernelshark: Fix "undefined reference to `glutInit'" when using CMake 3.22.1

Message ID 20220113004559.1624414-1-michal.sojka@cvut.cz (mailing list archive)
State Superseded
Headers show
Series kernelshark: Fix "undefined reference to `glutInit'" when using CMake 3.22.1 | expand

Commit Message

Michal Sojka Jan. 13, 2022, 12:45 a.m. UTC
When building with cmake 3.22.1, the build fails with the following
errors:

    /bin/ld: dataplot.cpp:(.text+0x17): undefined reference to `glutInit'
    /bin/ld: dataplot.cpp:(.text+0x62): undefined reference to `glutDisplayFunc'
    /bin/ld: dataplot.cpp:(.text+0x6d): undefined reference to `glutMainLoop'
    /bin/ld: ../../lib/libkshark-plot.so.2.0.2: undefined reference to `glutInitWindowPosition'
    /bin/ld: ../../lib/libkshark-plot.so.2.0.2: undefined reference to `glutInitDisplayMode'
    /bin/ld: ../../lib/libkshark-plot.so.2.0.2: undefined reference to `glutInitWindowSize'
    /bin/ld: ../../lib/libkshark-plot.so.2.0.2: undefined reference to `glutCreateWindow'
    /bin/ld: ../../lib/libkshark-plot.so.2.0.2: undefined reference to `glutSetOption'

The reason is this cmake commit:
https://gitlab.kitware.com/cmake/cmake/-/commit/f90d15458a9a98180fcc95158f2ab5d2b1ad3152,
which changes how the glut library is searched for. Specifically,
pkg-config is newly tried before other methods.

When pkg-config finds the library it doesn't set GLUT_LIBRARY variable
used by kernelshark, but only GLUT_LIBRARIES, as mentioned in the
official documentation:

    https://cmake.org/cmake/help/v3.22/module/FindGLUT.html

Therefore, we should switch to using the documented variable.

I also tested this change with CMake 3.21.2 (before the mentioned
commit) and it works.

Signed-off-by: Michal Sojka <michal.sojka@cvut.cz>
---
 src/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Yordan Karadzhov Jan. 13, 2022, 10:59 a.m. UTC | #1
Hi Michal,

It is cool that I received two fixes of this issue in the very same day.
I think this is a good vital sign for the KernelShark community :-)

I will take Tzvetomir's patch
https://lore.kernel.org/all/20220112153805.222437-1-tz.stoyanov@gmail.com/

since his solution does what Cmake recommends.

Anyway, thanks again.
Looking forward to see more KernelShark patches from you.

cheers,
Yordan


On 13.01.22 г. 2:45 ч., Michal Sojka wrote:
> When building with cmake 3.22.1, the build fails with the following
> errors:
> 
>      /bin/ld: dataplot.cpp:(.text+0x17): undefined reference to `glutInit'
>      /bin/ld: dataplot.cpp:(.text+0x62): undefined reference to `glutDisplayFunc'
>      /bin/ld: dataplot.cpp:(.text+0x6d): undefined reference to `glutMainLoop'
>      /bin/ld: ../../lib/libkshark-plot.so.2.0.2: undefined reference to `glutInitWindowPosition'
>      /bin/ld: ../../lib/libkshark-plot.so.2.0.2: undefined reference to `glutInitDisplayMode'
>      /bin/ld: ../../lib/libkshark-plot.so.2.0.2: undefined reference to `glutInitWindowSize'
>      /bin/ld: ../../lib/libkshark-plot.so.2.0.2: undefined reference to `glutCreateWindow'
>      /bin/ld: ../../lib/libkshark-plot.so.2.0.2: undefined reference to `glutSetOption'
> 
> The reason is this cmake commit:
> https://gitlab.kitware.com/cmake/cmake/-/commit/f90d15458a9a98180fcc95158f2ab5d2b1ad3152,
> which changes how the glut library is searched for. Specifically,
> pkg-config is newly tried before other methods.
> 
> When pkg-config finds the library it doesn't set GLUT_LIBRARY variable
> used by kernelshark, but only GLUT_LIBRARIES, as mentioned in the
> official documentation:
> 
>      https://cmake.org/cmake/help/v3.22/module/FindGLUT.html
> 
> Therefore, we should switch to using the documented variable.
> 
> I also tested this change with CMake 3.21.2 (before the mentioned
> commit) and it works.
> 
> Signed-off-by: Michal Sojka <michal.sojka@cvut.cz>
> ---
>   src/CMakeLists.txt | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
> index babb9c1..e4cf78f 100644
> --- a/src/CMakeLists.txt
> +++ b/src/CMakeLists.txt
> @@ -59,7 +59,7 @@ if (OPENGL_FOUND)
>                                        KsPlugins.cpp)
>   
>       target_link_libraries(kshark-plot  kshark
> -                                       ${GLUT_LIBRARY}
> +                                       ${GLUT_LIBRARIES}
>                                          ${OPENGL_LIBRARIES})
>   
>       set_target_properties(kshark-plot PROPERTIES  SUFFIX ".so.${KS_VERSION_STRING}")
>
diff mbox series

Patch

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index babb9c1..e4cf78f 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -59,7 +59,7 @@  if (OPENGL_FOUND)
                                      KsPlugins.cpp)
 
     target_link_libraries(kshark-plot  kshark
-                                       ${GLUT_LIBRARY}
+                                       ${GLUT_LIBRARIES}
                                        ${OPENGL_LIBRARIES})
 
     set_target_properties(kshark-plot PROPERTIES  SUFFIX ".so.${KS_VERSION_STRING}")