0

I have compiled this library https://github.com/xdspacelab/openvslam successfully, but I am having trouble now including it in C++ programs.

Here is the final directory structure:

.
├── 3rd
├── build
├── camera_params
├── cmake
├── docs
├── example
├── frames
├── frames_to_localise
├── maps
├── orb_vocab
├── ros
├── src
├── test
├── videos
└── viewer

Now this is the command I used:

cd /path/to/openvslam
mkdir build && cd build
cmake \
    -DBUILD_WITH_MARCH_NATIVE=ON \
    -DUSE_PANGOLIN_VIEWER=OFF \
    -DUSE_SOCKET_PUBLISHER=ON \
    -DUSE_STACK_TRACE_LOGGER=ON \
    -DBOW_FRAMEWORK=DBoW2 \
    -DBUILD_TESTS=ON \
    ..
make -j4

As per docs, https://openvslam.readthedocs.io/en/master/installation.html#subsection-common-linux-macos

My understanding is that this install the library locally not system-wide (like in /usr/local/bin).

So I try to compile one if their examples https://github.com/xdspacelab/openvslam/blob/master/example/run_image_localization.cc

like this: g++ run_image_localization.cc I get this error:

In file included from run_image_localization.cc:2:
./util/image_util.h:19:33: warning: defaulted function definitions are a C++11 extension [-Wc++11-extensions]
    virtual ~image_sequence() = default;
                                ^
run_image_localization.cc:10:10: fatal error: 'openvslam/system.h' file not found
#include "openvslam/system.h"
         ^~~~~~~~~~~~~~~~~~~~
1 warning and 1 error generated.

makes sense because openvslam was not included. I tried different flags such as -L, -I etc but nothing worked so far. Is there a standard solution to this ?

PS: A temporary solution was to set VERBOSE = 1 while running make and copy paste the command that was used to compile the examples... That command is 40+ lines long, it takes more time to render the command on my terminal than compile the .cc file...

EDIT: I am using a Mac

  • Why not just add the option to build the examples to your `cmake` command: `-DBUILD_EXAMPLES=ON` – Kevin Jan 31 '20 at 13:35
  • Is there an `install/lib` directory in `/path/to/openvslam` with library (.so) files? You may need to link those. – GoodDeeds Jan 31 '20 at 13:35
  • The above make command only builds the stuff. There's typically a `make install` command that installs it. But you shouldn't do this. You should learn how to use your Linux distribution's package manager to prepare an installable package. Otherwise, a misconfiguration, or a fat finger, has a distinct possibility of producing an unbootable brick. It would be a good learning experience, if you have plenty of time to reinstall Linux. But probably not what you want. – Sam Varshavchik Jan 31 '20 at 13:39
  • @squareskittles I have compiled the examples, but I need to build something based on them. I cant run make each time.. it takes ages.. –  Jan 31 '20 at 13:50
  • It looks like you copied your local source files in the same directory as this `openvslam` repo. Is that correct? If that is the approach you are trying to take, you can use CMake to build `openvslam` (as you have already done) and your local source code. Just create a top-level CMake file, and use the `add_subdirectory()` call to include your local projects, and those from `openvslam`. – Kevin Jan 31 '20 at 13:51
  • @GoodDeeds I am on a Mac. Does this matter ? I have a directory build/lib/ that has *.dylib files ? –  Jan 31 '20 at 13:53
  • @SamVarshavchik I am on a Mac –  Jan 31 '20 at 13:53
  • I am not familiar with Mac OS, but [this](https://stackoverflow.com/q/2339679/5987698) suggests that .dylib file might be what you want. – GoodDeeds Jan 31 '20 at 13:55
  • @squareskittles I have cloned the repo and run the commands to build it. That is all. I haven't copied any local source files anywhere. –  Jan 31 '20 at 13:55
  • @GoodDeeds ok so I will have to link those then I assume –  Jan 31 '20 at 13:56
  • Ok, if you're familiar with CMake, I would still suggest utilizing CMake if you're looking to compile something of your own *based* on the examples. The `openvslam` repo uses CMake, and the CMake file in their `examples` directory would essentially be what you need to generate a Makefile to compile something based on the examples. – Kevin Jan 31 '20 at 14:01
  • @squareskittles sadly I am not that familiar with CMake. Are you saying that the CMake files in their examples dir was provided for users to compile their own code ? –  Jan 31 '20 at 14:06
  • It is not necessarily provided to use for your own code, but you could use the CMake in that directory (as it does everything necessary for `openvslam`) and adopt it to also account for your source code. – Kevin Jan 31 '20 at 14:27
  • @squareskittles what do you mean by "but you could use the CMake in that directory", run cmake for example within a build dir ? Also they have two examples dirs, one in the root and one in the build, which one are you referring to ? –  Jan 31 '20 at 14:29
  • Yes, you could make your own example file source (based on the existing examples) and simply modify the CMake file to build *your* example along with the other examples. You should not need to modify **anything** in the `build` directory, as contains all of the files *generated* by CMake. You should only modify source code in the `root/examples` directory. – Kevin Jan 31 '20 at 14:35
  • @squareskittles Ok I get it now but I that means I have to run "make" everytime to build openvslam again and again ? That takes ages –  Jan 31 '20 at 14:42
  • Yes, I don't recommend tying your project to a big repo if it takes forever to build. But, to compile a simple example of your own for one-off testing, you could do something as I suggested. The `openvslam` shouldn't rebuild if you haven't changed any of the other source in the repo... – Kevin Jan 31 '20 at 14:46
  • 1
    I can't reproduce it because I don't have g2o on my linux box... but in general you should be able to compile stuff that uses cmake by first running cmake and then make. There is no reason to do `mkdir build`, just run: `cmake -S . -B build; gmake -C build`. Openvslam provide a cmake-package which makes it very easy to use by other cmake based projects, but then you have to install it first (anywhere will do, as long as you set the env.var `CMAKE_PREFIX_PATH`). It is also possible to use it without installing, but then openvslam must support this (with generator expressions). – Carlo Wood Jan 31 '20 at 15:00
  • @CarloWood I am using a Mac so gmake is not available did you mean "make" ? –  Jan 31 '20 at 15:09
  • @CarloWood Did you mean running those commands from root/examples ? –  Jan 31 '20 at 15:18
  • Yes `make`. I use gmake which is a symlink to `make` (that happens to be GNU make) because my `make` is a bash function with a mind of its own. I meant running those from the source tree. You can run them from anywhere though: -S specifies where the source tree is and -B where to build it. Then -C again where the build tree is. So, `cmake -S /path/to/source -B /path/to/builddir; make -C /path/to/builddir`. It's often just easiest not to change directory a lot while working ;). – Carlo Wood Jan 31 '20 at 22:06

0 Answers0