0

I'm trying to setup KDevelop with Gcc, but I can't get it to properly link to external libraries. I get the following error:

/home/tahsin/Projects/glWrap/build> make
Linking CXX executable glwrap
CMakeFiles/glwrap.dir/main.cpp.o: In function `main':
/home/_/Projects/glWrap/main.cpp:11: undefined reference to `glutInit'
collect2: error: ld returned 1 exit status
make[2]: *** [glwrap] Error 1
make[1]: *** [CMakeFiles/glwrap.dir/all] Error 2
make: *** [all] Error 2
*** Failed ***

My code is a simple opengl file:

#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <cassert>

using namespace std;

int main(int argC, char **argV) 
{
    glutInit(&argC, argV);
}

I can of course compile the file fine from my command line Makefile, but not from kDevelop. I've tried setting up the CMakeList (although I'm new to this, I usually just use Makefiles). The CMakeList associated with the kDev project looks like this:

cmake_minimum_required(VERSION 2.8)
project(glwrap)
set(CMAKE_CXX_FLAGS "-lglut -lGLU -lGL -I/path/to/the/include/dir")
include_directories( /usr/include )
include_directories( /usr/lib )
include_directories( /usr/include )
link_directories( /usr/lib64 )
link_directories( /usr/lib32 )

add_executable(glwrap main.cpp)
install(TARGETS glwrap RUNTIME DESTINATION bin)

Is there anything specific that needs to be set up from the GUI?

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Tahsin M
  • 129
  • 2
  • 7

1 Answers1

0

I'm not a CMake expert, but I believe your problem is that CMake needs some help in finding the GLUT includes. Two solutions that might work are:

  1. Find them yourself and insert additional explicit include_directories( ) commands in the CMakeList file for your program.
  2. (This uses a powerful feature of the CMake system.) Use the CMake FindGLUT command. (Check the CMake documentation for FindXXX usage.) CMake will look for the GLUT files for you.

In either case, after inserting changes into the CMakeList file, you should run the configure command in the KDevelop4 Project menu. CMake will execute the CMakeLIst changes and report if the GLUT files were found.

Lukas Knuth
  • 25,449
  • 15
  • 83
  • 111
Steve
  • 1