为dlib创建共享库 [英] Create a shared library for dlib

查看:93
本文介绍了为dlib创建共享库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按照说明使用cmake编译dlib(此处)会生成一个静态dlib库:

Following the instructions to compile dlib using cmake (here) generates a static dlib library:

cd examples
mkdir build
cd build
cmake ..
cmake --build . --config Release

我如何指示cmake生成共享(.so)库? / p>

How can I instruct cmake to generate a shared (.so) library instead?

推荐答案

如果要创建.so文件,请执行以下操作:

If you want to make a .so file then do this:

cd dclib/dlib
mkdir build
cd build
cmake -DBUILD_SHARED_LIBS=1 ..
make
sudo make install

在Unix系统上,它将在整个dlib系统上安装。这意味着安装.so文件以及头文件,以便您可以使用 g ++ main.cpp -ldlib 这样的命令编译程序。最后,在Linux系统上,安装任何新的共享库后,您还需要运行 sudo ldconfig

On a unix system, that will install dlib system wide. This means installing the .so file and also the header files so you can compile programs with a command like g++ main.cpp -ldlib. Finally, on linux systems you will also need to run sudo ldconfig after installing any new shared libraries.

但是,对于大多数用户,我建议使用CMake,如示例所示。这样一来,您既可以在需要时启用或禁用调试模式,也可以简化以源代码形式和编译形式进行项目的分发。例如,如果您想在Windows上进行编译,则共享库绝对不是解决之道。而且,使用示例中所示的CMake总是可以直接进行而无需任何设置。

However, for most users, I would recommend using CMake as shown in the examples. That way would allow you to enable or disable debugging modes whenever you want and also makes distributing the project easier, both in source form and compiled form. For example, if you wanted to compile on windows then shared libraries are definitely not the way to go. Moreover, using CMake as shown in the examples will always work in a straightforward manner without any setup.

这篇关于为dlib创建共享库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆