编译以使用CMake获取共享库

时间:2014-05-21 20:58:18

标签: makefile cmake shared-libraries ogre

我正在使用Ogre3D这个项目是一个3D引擎。 实际上我使用cmake(add_executable函数)

构建项目

但是为了我的项目,我需要获得一个共享库而不是可执行文件。

这是我的CMakeLists.txt

project(TestOgre)
cmake_minimum_required(VERSION 2.6)
set(CMAKE_MODULE_PATH "/usr/local/lib/OGRE/cmake/")
#set(CMAKE_CXX_FLAGS "-Wall -W -Werror -ansi -pedantic -g")                                          

# Il s'agit du tutoriel d'exemple, qui utilise quelques fichiers prédéfinis de Ogre. Il faut indique\
r à cmake où se trouvent les includes en question                                                    
include_directories ("/usr/local/include/OGRE/")

# Bien sûr, pour compiler Ogre, il faut le chercher, et définir le répertoire contenant les includes\
.                                                                                                    
find_package(OGRE REQUIRED)
include_directories (${OGRE_INCLUDE_DIRS})

# L'exemple dépend aussi de OIS, une lib pour gérer la souris, clavier, joystick...                  
find_package(OIS REQUIRED)

# On définit les sources qu'on veut compiler                                                         
SET(SOURCES
main.cpp
Map.cpp
Case.cpp
AObject.cpp
Player.cpp
Game.cpp
UpdateOgre.cpp
InitOgre.cpp
AppDemarrage.cpp)

# On les compile                                                                                     
#add_executable (                                                                                    
 #  TestOgre ${SOURCES}                                                                              
#)                                                                                                   


// what i have add to get a shared library
add_library (
   TestOgre SHARED &{SOURCES}
)

target_link_libraries(TestOgre ${OGRE_LIBRARY} ${OIS_LIBRARY} "/usr/lib/x86_64-linux-gnu/libboost_sy\
stem.so.1.53.0")

1 个答案:

答案 0 :(得分:2)

根据评论,问题在于您没有使用SHARED参数来指定共享库,而且还使用& {SOURCES}代替$ {SOURCES}。

add_library (
   TestOgre SHARED ${SOURCES}
)