0

I am on Ubuntu 20.04.1 LTS and currently I am working through the OpenSceneGraph 3.0 Tutorial by Rui Wang and Xuelei Qian and I am on page 87 trying to create the Teapot which requires the glut libraries and includes. After some research, I downloaded freeglut 3.2.1 and built it in my own directory. Needless to say I am a Ubuntu beginner and don't quite understand where something goes after the cmake make command, let alone where something goes after the cmake install command.

The following error comes up when trying to build:

/usr/bin/ld: CMakeFiles/MyProject.dir/main.cpp.o: in function `TeapotDrawable::drawImplementation(osg::RenderInfo&) const':
main.cpp:(.text+0x129): undefined reference to `glutSolidTeapot'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/MyProject.dir/build.make:91: MyProject] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/MyProject.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

So far I have used the following CMakeLists.txt file:

cmake_minimum_required(VERSION 2.6)

PROJECT(MyProject)

#find_package( GL )
find_package( OpenGL )
#find_package( freeglut REQUIRED ) // added REQUIRED
find_package( OpenThreads )
find_package( osg )
find_package( osgDB )
find_package( osgUtil )
find_package( osgViewer )

macro ( config_project PROJNAME LIBNAME )
                include_directories( ${${LIBNAME}_INCLUDE_DIR} )
                target_link_libraries( ${PROJNAME} ${${LIBNAME}_LIBRARY} )
endmacro()

add_executable( MyProject main.cpp )
config_project( MyProject OPENTHREADS )
config_project( MyProject OSG )
config_project( MyProject OSGDB )
config_project( MyProject OSGUTIL )
config_project( MyProject OSGVIEWER )
#config_project( MyProject FREEGLUT )
config_project( MyProject GLUT )
config_project( MyProject OPENGL )

The uncommented lines are me trying to get this to work. This has worked for the other examples used in the book so far. Freeglut, OSG and OpenGL are installed under the usr/local/include dir

If any information is missing, I will of course edit this question accordingly. Thank you.

Edit: After adding the REQUIRED keyword, I get the following error from CMake:

CMake Error at CMakeLists.txt:7 (find_package):
  By not providing "Findfreeglut.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "freeglut",
  but CMake did not find one.

  Could not find a package configuration file provided by "freeglut" with any
  of the following names:

    freeglutConfig.cmake
    freeglut-config.cmake

  Add the installation prefix of "freeglut" to CMAKE_PREFIX_PATH or set
  "freeglut_DIR" to a directory containing one of the above files.  If
  "freeglut" provides a separate development package or SDK, be sure it has
  been installed.
Tand
  • 16
  • 1
  • 4
  • So, what happens if you uncomment the line `find_package( freeglut )`? – Tsyvarev Nov 23 '20 at 12:35
  • If I uncomment this I would also have to uncomment #config_project ( My project FREEGLUT ) right? That still gives me the same error. – Tand Nov 23 '20 at 12:38
  • 1
    Are you sure that all packages (including `freeglut`) you search with `find_package()` are **actually** found? You may add `REQUIRED` keyword, so CMake will automatically fail upon a package not found. Also note, that usual suffices for variables set by `find_package` are `_INCLUDE_DIRS` and `_LIBRARIES`. See e.g. documentation for script [FindGLUT.cmake](https://cmake.org/cmake/help/latest/module/FindGLUT.html). (This script could be used via `find_package(GLUT)`.) – Tsyvarev Nov 23 '20 at 12:47
  • How do I go about setting the _INCLUDE_DIRS and such ? cmake-gui ? I have tried that as well, but when I use cmake .. afterwards, the settings get overwritten, and Yes, freeglut isn't found. I have edited the question with the propper error. – Tand Nov 23 '20 at 13:38
  • Okay, so upon reading your comment more thourougly, I did write find_package( GLUT REQUIRED ) which seems to work, at least now I get another error :) which is: freeglut ERROR: Function called without first calling 'glutInit'. Any idea what that might be? – Tand Nov 23 '20 at 13:55
  • So you need to call `glutInit` before using GLUT functions. It could be that there is some other function, which in turn calls `glutInit`. But I am not an expert in GL, so I cannot suggest anything else than reading some tutorial. – Tsyvarev Nov 23 '20 at 13:58
  • Ok, thank you for your help, I am currently testing out different approaches for glutInit(). What is common practice here? Do I mark your comment and put it as an answer? – Tand Nov 23 '20 at 14:07
  • 1
    I have marked your question as a **duplicate** for the one on the same topic (using freeglut in CMake). Note, that the "duplicate" mark is only for prevent same **answers** to be posted on many question posts. Your question is not deleted (and is not intended to be deleted), and still can be voted. – Tsyvarev Nov 23 '20 at 14:19
  • Thank you. I am getting stuck on the glutInit() function. Might have to write the next question soon. – Tand Nov 23 '20 at 14:21

0 Answers0