在Mac OS X上使用cmake链接到框架

时间:2011-02-07 05:33:57

标签: c++ linker ogre3d

我正在尝试使用cmake将一个程序与OS X上的食人魔和其他一些库相关联,但我不断收到此错误:

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

相同的cmake文件适用于Windows和Linux。我试图链接到我在ogre网站上的SDK中获得的食人魔1.7.2框架。我认为这是一个关联问题,但不是一个食人魔问题。使用cmake链接框架并不像我希望的那样直观。有想法该怎么解决这个吗?

1 个答案:

答案 0 :(得分:5)

首先,您应该note ${APPLE}并不意味着系统是Mac OS X,只有 APPLE 在C / C ++头文件中是#defined。 “使用IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")检查OS X.

我没有您的构建环境来测试以下建议,但请尝试一下:

309321有拼写错误。它应该是"${OGRE_INCLUDE_DIR}"(不是${OGRE_INCLUDE_DIRS})。

line 327${SDL_LIBRARY}${OPENAL_LIBRARY}${OGG_LIBRARY}是库文件的路径,它们应该是<<}的路径这些库的em>目录。 link_directories告诉链接器哪些目录包含您在target_link_libraries中指定的库。

除了OGRE之外,line 327指定FindXXX.cmake未定义_LIB_DIR变量的库(SDL,AL和OGG)(或指示包含该库的目录的等效变量) 。那么,那条线应该是

link_directories("${OGRE_LIB_DIR}")

此外,line 336似乎不是正确的语法。 target_link_libraries将目标(在本例中应该是physgame库)作为第一个参数,但是你已经将它传递给了Ogre库目录的路径。由于在定义目标之前无法调用该命令,因此必须将其推迟到line 386

从{

}更改line 386

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

为:

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

您可能也对http://www.ogre3d.org/forums/viewtopic.php?f=1&t=58610&start=0

感兴趣