4

我已经构建了自己的 Ogre3D http://ogre3d.org二进制文件,现在我想将我在 Qt 中的项目链接到它们(我使用 CMake 作为我的构建工具)。这是我的CMakeLists.txt文件:

project(ogre_face_test)
cmake_minimum_required(VERSION 2.8)
aux_source_directory(. SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST})

include_directories( "/home/XXX/programming/SDKs/OGRE_1.8.1_BUILD/include" "." )

link_directories("/home/XXX/programming/SDKs/OGRE_1.8.1_BUILD/lib")
target_link_libraries( ogre_face_test "OgreMain" )

.../BUILD/lib目录中,我有 : 等libOgreMain.so文件libOgreMain.so.1.8.1

我在 Qt Creator 中链接时收到此错误:

/usr/bin/cmake -H/home/XXX/programming/c++/ogre_face_sample/ogre_face_test -B/home/XXX/programming/c++/ogre_face_sample/ogre_face_test-build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/XXX/programming/c++/ogre_face_sample/ogre_face_test-build/CMakeFiles /home/XXX/programming/c++/ogre_face_sample/ogre_face_test-build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory `/home/XXX/programming/c++/ogre_face_sample/ogre_face_test-build'
make -f CMakeFiles/ogre_face_test.dir/build.make CMakeFiles/ogre_face_test.dir/depend
make[2]: Entering directory `/home/XXX/programming/c++/ogre_face_sample/ogre_face_test-build'
cd /home/XXX/programming/c++/ogre_face_sample/ogre_face_test-build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/XXX/programming/c++/ogre_face_sample/ogre_face_test /home/XXX/programming/c++/ogre_face_sample/ogre_face_test /home/XXX/programming/c++/ogre_face_sample/ogre_face_test-build /home/XXX/programming/c++/ogre_face_sample/ogre_face_test-build /home/XXX/programming/c++/ogre_face_sample/ogre_face_test-build/CMakeFiles/ogre_face_test.dir/DependInfo.cmake --color=
make[2]: Leaving directory `/home/XXX/programming/c++/ogre_face_sample/ogre_face_test-build'
make -f CMakeFiles/ogre_face_test.dir/build.make CMakeFiles/ogre_face_test.dir/build
make[2]: Entering directory `/home/XXX/programming/c++/ogre_face_sample/ogre_face_test-build'
Linking CXX executable ogre_face_test
/usr/bin/cmake -E cmake_link_script CMakeFiles/ogre_face_test.dir/link.txt --verbose=1
/usr/bin/c++       CMakeFiles/ogre_face_test.dir/main.cpp.o CMakeFiles/ogre_face_test.dir/FacialAnimation.cpp.o  -o ogre_face_test -rdynamic -lOgreMain 
/usr/bin/ld: cannot find -lOgreMain
collect2: error: ld returned 1 exit status
make[2]: *** [ogre_face_test] Error 1
make[2]: Leaving directory `/home/XXX/programming/c++/ogre_face_sample/ogre_face_test-build'
make[1]: *** [CMakeFiles/ogre_face_test.dir/all] Error 2
make[1]: Leaving directory `/home/XXX/programming/c++/ogre_face_sample/ogre_face_test-build'
make: *** [all] Error 2

编辑

另一方面,如果我使用qmake而不是CMake这个文件:

TARGET = qt_test_1
TEMPLATE = app

SOURCES += main.cpp\
        FacialAnimation.cpp

HEADERS  += FacialAnimation.h

INCLUDEPATH += /usr/include\
            /home/monkey/programming/SDKs/OGRE_1.8.1_BUILD/include
DEPENDPATH += /usr/include
LIBS += -L/home/monkey/programming/SDKs/OGRE_1.8.1_BUILD/lib -lOgreMain

它链接得很好。

4

1 回答 1

7

CMake 文档说:

  • link_directories:指定链接器将在其中查找库的目录。

    link_directories(directory1 directory2 ...)
    

    指定链接器应在其中搜索库的路径。该命令仅适用于调用后创建的目标。由于历史原因,赋予此命令的相对路径不变地传递给链接器(与许多相对于当前源目录解释它们的 CMake 命令不同)。

(强调我的)所以你必须在调用add_executable.

于 2012-10-10T12:25:40.650 回答