2012-10-10 92 views
3

我已經建立了自己OGRE3D http://ogre3d.org二進制文件,現在我想我在Qt工程(我使用的CMake作爲我的生成工具)鏈接到它們。這是我的CMakeLists.txt文件:的CMake將共享庫 - 找不到lOgreMain

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.solibOgreMain.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 

它鏈接正常。

+1

就可以運行make具有詳細= 1(做,不cmake並沒有qmake的)參數來檢查習慣於實際的命令行? –

+0

@JanHudec感謝您的提示;)請看看我的更新。 – Patryk

回答

7

CMake的文件說:

  • link_directories:指定目錄中的鏈接將尋找庫。

    link_directories(directory1 directory2 ...) 
    

    指定鏈接器應搜索庫的路徑。 它被稱爲後,該命令將只適用於創建目標。由於歷史的原因,考慮到該命令相對路徑被傳遞給鏈接器不變(與許多CMake的命令,其解釋它們相對於當前源目錄)。

(重點煤礦)所以你要設置的目錄了,你叫add_executable之前。

+2

@JanHudes非常感謝! :) +我要補充一句,'target_link_libraries(...)'必須是add_executable(...)後'' - 它不是那麼明顯了我,我看了一些Linux的庫鏈接教程之前。 – Patryk