1

我正在尝试使用 cmake 将程序与 OS X 上的 ogre 和其他一些库链接,但我不断收到此错误:

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 获得的 ogre 1.7.2 框架。我认为这是一个链接问题,而不是一个食人魔问题。使用 cmake 链接框架并不像我希望的那样直观。有想法该怎么解决这个吗?

4

1 回答 1

5

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

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

309321行有一个错字。应该是"${OGRE_INCLUDE_DIR}"(不是${OGRE_INCLUDE_DIRS})。

第 327 行${SDL_LIBRARY}${OPENAL_LIBRARY}${OGG_LIBRARY}是库文件的路径,而它们应该是这些库目录的路径。link_directories告诉链接器哪些目录包含您在target_link_libraries.

除了 OGRE,第 327 行指定了库(SDL、AL 和 OGG),它们FindXXX.cmake没有定义_LIB_DIR变量(或表示包含库的目录的等效项)。所以,那条线应该是

link_directories("${OGRE_LIB_DIR}")

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

将第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

于 2011-02-13T21:17:53.093 回答