Linking to framework with cmake on Mac OS X

7.5k views Asked by At

I'm attempting to link a program against ogre and a few other libraries on OS X using cmake, but I keep getting this error:

ld: warning: directory '/Library/Frameworks/SDL.framework/Debug' following -L not found
ld: warning: directory '-framework Cocoa/Debug' following -L not found
ld: warning: directory '-framework Cocoa' following -L not found
ld: warning: directory '/System/Library/Frameworks/OpenAL.framework/Debug' following -L not found
ld: warning: directory '/Library/Frameworks/Ogre.framework/Debug' following -L not found
ld: warning: directory '/opt/local/lib/libogg.dylib/Debug' following -L not found
ld: warning: path '/opt/local/lib/libogg.dylib' following -L not a directory
ld: warning: directory '/Users/hydrowolfy/Documents/newphysgame/physgame/physgameengine/data/macosx/ogre/Debug' following -L not found
ld: warning: directory '/Users/hydrowolfy/Documents/newphysgame/physgame/physgameengine/data/macosx/ogre' following -L not found
ld: warning: directory '/Users/hydrowolfy/Documents/newphysgame/physgame/physgameengine/data/macosx/openal/Debug' following -L not found
ld: warning: directory '/Users/hydrowolfy/Documents/newphysgame/physgame/physgameengine/data/macosx/openal' following -L not found
ld: warning: directory '/Users/hydrowolfy/Documents/newphysgame/physgame/physgameengine/data/macosx/oggvorbis/Debug' following -L not found
ld: warning: directory '/Users/hydrowolfy/Documents/newphysgame/physgame/physgameengine/data/macosx/oggvorbis' following -L not found
ld: library not found for -lOgreMain
collect2: ld returned 1 exit status
Command /Developer/usr/bin/g++-4.2 failed with exit code 1

The same cmake files work on windows and Linux. I'm trying to link against the ogre 1.7.2 framework that I got from the SDK on ogre's site. I think this is a linking issue, not an ogre issue though. Linking against frameworks with cmake is not as intuitive as I had hoped. Any ideas on how to fix this?

1

There are 1 answers

0
AudioBubble On BEST ANSWER

First, you should note that ${APPLE} "does not imply that the system is Mac OS X, only that APPLE is #defined in C/C++ header files." Use IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") to check for OS X.

I don't have your build environment to test the following suggestions, but give them a try:

Line 309 and 321 have a typo. It should be "${OGRE_INCLUDE_DIR}" (not ${OGRE_INCLUDE_DIRS}).

At line 327, ${SDL_LIBRARY}, ${OPENAL_LIBRARY}, and ${OGG_LIBRARY} are paths to the library files when they should be the paths to the directories of those libraries. link_directories tells the linker which directories contain the libraries that you specify in target_link_libraries.

Other than OGRE, line 327 specifies libraries (SDL, AL, and OGG) whose FindXXX.cmake doesn't define a _LIB_DIR variable (or equivalent that indicates the directory containing the library). So, that line should be

link_directories("${OGRE_LIB_DIR}")

Also, line 336 does not seem to be correct syntax. target_link_libraries takes the target (which should be the physgame library in this case) as the first argument, but you've passed it the path to the directory of the Ogre library. Since you can't call that command until you define the target, you'll have to defer it to line 386.

Change line 386 from:

target_link_libraries( ${PROJECT_NAME} OgreMain ${Bullet_LibraryNames} cAudio SDL )

to:

target_link_libraries(
    ${PROJECT_NAME}
    "${OGRE_LIBRARIES}"
    ${Bullet_LibraryNames}
    "${OPENAL_LIBRARY}" 
    "${SDL_LIBRARY}"
)

You might also be interested in: http://www.ogre3d.org/forums/viewtopic.php?f=1&t=58610&start=0