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
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
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?
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.
Well, I just use
cmake
with aCMakeLists.txt
file that I create. Do like this:Create a CMakeLists.txt file:
In this file, I assume we want to compile the
main.cpp
file that useslibfreenect2
. So, in your local directory create abuild
folder, using the terminal:Then, run the command in the terminal:
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.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:
After, just run this in the terminal: mkdir build && cd build && cmake .. & make
This answer was my source for this second way of compiling the code.
Hope this helps!