与libfreenect2建设 [英] Building with libfreenect2

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

问题描述

会有人能够张贴的如何编译code,它使用 libfreenect2 一个简单的例子?安装库后,我的主目录中创建以下结构:

Would anyone be able to post a simple example of how to compile code which uses libfreenect2? After installing the library, the following structure is created in my home directory:

→ tree freenect2 
freenect2
├── include
│   └── libfreenect2
│       ├── config.h
│       ├── export.h
│       ├── frame_listener.hpp
│       ├── frame_listener_impl.h
│       ├── libfreenect2.hpp
│       ├── logger.h
│       ├── packet_pipeline.h
│       └── registration.h
└── lib
    ├── cmake
    │   └── freenect2
    │       └── freenect2Config.cmake
    ├── libfreenect2.so -> libfreenect2.so.0.2
    ├── libfreenect2.so.0.2 -> libfreenect2.so.0.2.0
    ├── libfreenect2.so.0.2.0
    └── pkgconfig
        └── freenect2.pc

我试图用.PC文件来编译使用类似于此pkg配置维基百科页面上找到的行:

I attempted to compile with the .pc file using a line similar to this found on the pkg-config wikipedia page:

gcc -o test test.c $(pkg-config --libs --cflags libpng)

但随着与此错误传来:

But came with up with this error:

./test: error while loading shared libraries: libfreenect2.so.0.2: cannot open shared object file: No such file or directory

显然,我什么地方搞砸编译过程,但我不知道去哪里找,因为这是在运行时,而不是在编译时发生错误。还有与库中创建一个 .cmake 文件安装,我敢肯定,将导致更强大和妥善的解决办法,但我不完全知道如何使用这一点,一直没能找到展示如何这样做一个简单的指南。为初学者友好文档的任何链接也AP preciated。在libfreenect2的文档,它说,使用该行编译时 cmake的-Dfreenect2_DIR = $ HOME / freenect2 / lib目录/ cmake的/ freenect2 - 这是什么,我会具有使库或让我的应用程序时,何时使用?

Obviously, I messed up the compilation process somewhere, but I'm not sure where to look since this is error occurs on runtime and not at compile time. There's also a .cmake file created with the library install, which I'm sure would lead to a more robust and proper solution, but I'm not entirely sure how to use that and haven't been able to find a simple guide showing how to do so. Any links to beginner-friendly documentation are also appreciated. In the documentation for libfreenect2, it says to use this line when compiling cmake -Dfreenect2_DIR=$HOME/freenect2/lib/cmake/freenect2 -- is this something that I'd have to use when making the library or when making my application?

另一个切向相关的问题,这将是更好的 /包括 / lib目录目录移动到的/ usr /本地/包括的/ usr分别为 / local / lib目录?我相信,这将安装图书馆系统范围的,但我想有一些原因,libfreenect2不会自动做到这一点,我不知道那是什么。

Another tangentially related question, would it be better to move the /include and /lib directories to /usr/local/include and /usr/local/lib respectively? I believe that would "install" the library system-wide, but I imagine there's some reason that libfreenect2 doesn't do it automatically and I'm not sure what that is.

推荐答案

好吧,我只是用 cmake的的CMakeLists.txt 我创建文件。这样做:

Well, I just use cmake with a CMakeLists.txt file that I create. Do like this:

创建的CMakeLists.txt文件:

Create a CMakeLists.txt file:

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project("My Project")

set(CMAKE_CXX_FLAGS "-std=c++11")

find_package(freenect2 REQUIRED)

include_directories("/usr/include/libusb-1.0/")

INCLUDE_DIRECTORIES(
  ${freenect2_INCLUDE_DIR}
)

add_executable(main ./main.cpp)

target_link_libraries(main ${freenect2_LIBRARIES})

在这个文件中,我认为我们要编译使用 libfreenect2 的main.cpp 文件。所以,在你的本地目录中创建一个建立文件夹,使用终端

In this file, I assume we want to compile the main.cpp file that uses libfreenect2. So, in your local directory create a build folder, using the terminal:

mkdir build && cd build

然后,在终端中运行命令:

Then, run the command in the terminal:

cmake -Dfreenect2_DIR=$HOME/freenect2/lib/cmake/freenect2 .. && make

这应该创建可执行文件在build文件夹。 请注意,这cmake的命令指定的freenect2目录。在这种情况下,我认为它被放置在 /家居目录。

this should create main executable in the build folder. Please, note that this cmake command specifies the freenect2 directory. In this case I assume it was placed in the /home directory.

不过,据我所知,不必键入长cmake的命令或搜索它在终端历史可能是枯燥的一些人。因此,有可能以嵌入这样的命令:

However, I understand that having to type that long cmake command or search for it on the terminal history may be boring for some people. So, it is possible to embed the command like this:

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project("My Project")

set(CMAKE_CXX_FLAGS "-std=c++11")
# Set cmake prefix path to enable cmake to find freenect2
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} $ENV{HOME}/freenect2/lib/cmake/freenect2)
find_package(freenect2 REQUIRED)

include_directories("/usr/include/libusb-1.0/")

INCLUDE_DIRECTORIES(
  ${freenect2_INCLUDE_DIR}
)

add_executable(main ./main.cpp)

target_link_libraries(main ${freenect2_LIBRARIES})

后,只需在终端运行如下命令:
    MKDIR构建和放大器;&安培; CD&构建功放;&安培; cmake的..&安培;让

After, just run this in the terminal: mkdir build && cd build && cmake .. & make

的回答是我的编译code的第二个办法来源。

This answer was my source for this second way of compiling the code.

希望这有助于!

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

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