Gabson
Gabson

Reputation: 431

Compile to get shared library using CMake

I'm Using Ogre3D for this project which is a 3D engine. Actually i build the project using cmake ( add_executable function )

but for the good of my project, I need to get a shared library instead of an executable.

this is my 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")

Upvotes: 0

Views: 234

Answers (1)

drescherjm
drescherjm

Reputation: 10827

From the comments the problems were that you did not use the SHARED parameter to specify a shared library and also that &{SOURCES} was used instead of ${SOURCES}.

add_library (
   TestOgre SHARED ${SOURCES}
)

Upvotes: 2

Related Questions