2

I have a CMake module to locate FreeGLUT:

FIND_PATH(FREEGLUT_INCLUDE_DIR NAMES GL/freeglut.h)
FIND_LIBRARY(FREEGLUT_LIBRARY NAMES freeglut freeglut_static)

SET(FREEGLUT_LIBRARIES ${FREEGLUT_LIBRARY})
SET(FREEGLUT_INCLUDE_DIRS ${FREEGLUT_INCLUDE_DIR})

INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(FreeGLUT DEFAULT_MSG FREEGLUT_LIBRARY FREEGLUT_INCLUDE_DIR)

MARK_AS_ADVANCED(FREEGLUT_INCLUDE_DIR FREEGLUT_LIBRARY)

It works fine and locates freeglut_static.lib when I generate NMake Makefiles on Windows. I'm attempting to statically link FreeGLUT into my DLL:

FIND_PACKAGE(FreeGLUT REQUIRED)

ADD_LIBRARY(vti SHARED ${VTI_SOURCES})
ADD_DEFINITIONS("-DBUILD_VTI=1 -DFREEGLUT_STATIC=1")
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${FREEGLUT_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(vti ${FREEGLUT_LIBRARIES})

My source code builds correctly, but when it gets to the linking stage, VC++ fails with:

LINK : fatal error LNK1104: cannot open file 'freeglut.lib'

Which is strange since freeglut.lib isn't mentioned anywhere that I can see in the generated NMake makefiles. It should be trying to link with freeglut_static.lib, which CMake locates and sets in FREEGLUT_LIBRARIES.

What might be causing this?

David Brown
  • 35,411
  • 11
  • 83
  • 132

1 Answers1

2

This is caused with pragma directives in FreeGLUT code (see freeglut_std.h). Using FREEGLUT_STATIC should really fix that for you, but I think you should pass it to CMake without quotes: ADD_DEFINITIONS(-DBUILD_VTI -DFREEGLUT_STATIC)

istepura
  • 399
  • 3
  • 8
  • Yep, the quotes were the problem. Thanks! – David Brown Oct 24 '11 at 23:44
  • +1 Dis answer was also useful for me although I had a problem with a different library than FreeGLUT. I would suggest to also post the pragma lines causing this problem to this answer so people having the same Problem with another libarry can search for this specific pragma in their library. – Random Citizen Dec 07 '13 at 17:51