如何使用cmake制作自定义库?
我正在尝试制作一个自定义库,以使用CMAKE安装。这是一个个人公用事业库,因此包含诸如扩展数学库,扩展的向量,文件IO功能等的内容。
我对Cmake非常陌生,并且我正在努力构建/安装它作为库。我希望这是我安装的单个输出文件。我希望能够将其(和所有子库)与
#include <MaxLib.h>
我的makefile添加-lmaxlib一起包含。
我的文件结构就是这样:
- MaxLib.h
- CMakeLists.txt
- File
- File.cpp
- File.h
- CMakeLists.txt
- Geom
- File.cpp
- File.h
- CMakeLists.txt
我尝试编译单个sublibraries ie:
add_library(File SHARED ${CMAKE_CURRENT_SOURCE_DIR}/File.cpp)
target_include_directories(File)
我尝试将它们一起加入:
add_library(${PROJECT_NAME} STATIC
${CMAKE_CURRENT_SOURCE_DIR}/MaxLib.h
)
add_subdirectory(File)
add_subdirectory(Geom)
target_link_libraries(MaxLib File)
target_link_libraries(MaxLib Geom)
尽管此编译和我可以安装它,但用于文件的对象文件和GEOM并未与Maxlib
I 链接给人的印象是我做错了这一切...制作图书馆的正确方法是什么?
我应该尝试制作这样的静态图书馆吗?
是否应该在构建单个静态对象的根文件夹中只有一个makefile?
欢迎任何建议!预先感谢
I am trying to make a custom library to install with CMake. This is a personal utilities library so contains things like an extended math library, extended vectors, file IO functions etc.
I am very new to CMake and I am struggling to build/install this as a library. I would like this to be a single output file which I install. And I would like to be able to include it (and all sub libraries) with
#include <MaxLib.h>
and by adding -LMaxLib to my makefile.
My file structure is like this:
- MaxLib.h
- CMakeLists.txt
- File
- File.cpp
- File.h
- CMakeLists.txt
- Geom
- File.cpp
- File.h
- CMakeLists.txt
I have tried compiling the individual sublibraries i.e:
add_library(File SHARED ${CMAKE_CURRENT_SOURCE_DIR}/File.cpp)
target_include_directories(File)
and I have tried joining them all together with:
add_library(${PROJECT_NAME} STATIC
${CMAKE_CURRENT_SOURCE_DIR}/MaxLib.h
)
add_subdirectory(File)
add_subdirectory(Geom)
target_link_libraries(MaxLib File)
target_link_libraries(MaxLib Geom)
And although this compiles and I can install it, the object files for File and Geom are not becoming linked with MaxLib
I get the impression that I'm doing this all wrong... What is the correct way to make a library?
Should I be attempting to make a static or shared library like this?
Should it just be one makefile in the root folder which builds a single static object?
Any advice is welcome! Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论