【问题标题】:Compile to get shared library using CMake使用 CMake 编译以获取共享库
【发布时间】:2014-05-21 20:58:17
【问题描述】:

我在这个项目中使用 Ogre3D,它是一个 3D 引擎。 实际上我使用 cmake ( add_executable function ) 构建项目

但为了我的项目的利益,我需要获取共享库而不是可执行文件。

这是我的 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")

【问题讨论】:

  • add_library (TesShared SHARED ${SOURCES})
  • 无法为非本项目构建的目标“TestOgre”指定链接库。
  • 这是意料之中的。你注释掉了 TestOgre
  • 找不到源文件:&{SOURCES} 尝试过扩展 .c 。
  • &{SOURCES} 应该是 ${SOURCES}

标签: makefile cmake shared-libraries ogre


【解决方案1】:

在 cmets 中,问题在于您没有使用 SHARED 参数来指定共享库,并且使用了 &{SOURCES} 而不是 ${SOURCES}。

add_library (
   TestOgre SHARED ${SOURCES}
)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-09
    • 2021-05-02
    • 2016-02-16
    • 1970-01-01
    • 2018-03-06
    • 2017-05-29
    • 2010-10-03
    • 2016-10-02
    相关资源
    最近更新 更多