nvidia-isaac / nvblox

A GPU-accelerated TSDF and ESDF library for robots equipped with RGB-D cameras.
Other
707 stars 77 forks source link

'gflags' has not been declared compilation error. #5

Closed Isarm closed 2 years ago

Isarm commented 2 years ago

When trying to build using make I get the following error:

[ 83%] Building CXX object experiments/CMakeFiles/fuse_3dmatch.dir/src/fuse_3dmatch.cpp.o
/nvblox/nvblox/experiments/src/fuse_3dmatch.cpp: In function ‘int main(int, char**)’:
/nvblox/nvblox/experiments/src/fuse_3dmatch.cpp:44:3: error: ‘gflags’ has not been declared
   44 |   gflags::ParseCommandLineFlags(&argc, &argv, true);
      |   ^~~~~~
make[2]: *** [experiments/CMakeFiles/fuse_3dmatch.dir/build.make:63: experiments/CMakeFiles/fuse_3dmatch.dir/src/fuse_3dmatch.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:1375: experiments/CMakeFiles/fuse_3dmatch.dir/all] Error 2
make: *** [Makefile:130: all] Error 2

It seems that gflags made a switch in namespace from google to gflags in version 2.1. On my system I was building in a terminal that had a catkin workspace sourced in which I will be using this library, and a different library seems to be using an older version of gflags there, which clashes with my system install. Building in a terminal that does not source this works fine.

Caffe for example also uses gflags and this issue with build failing on older versions of gflags is known there too:

https://github.com/BVLC/caffe/issues/2597

They get around it by doing this:

#ifndef GFLAGS_GFLAGS_H_
namespace gflags = google;
#endif  // GFLAGS_GFLAGS_H_

See here

A similar suggestion is made on stackoverflow here

The Caffe fix actually does not work for me, as they use GFLAGS_GFLAGSH to detect which version of gflags is installed, but because I also have the new gflags installed, it incorrectly determines the version as it sees the system GFLAGS_GFLAGS_H, but still uses the older version gflags.h header file defined in the catkin workspace include folder. (I think at least, it really is quite the mess.)

The fix from the stackoverflow link does work for me (also for the non-catkin-sourced environment).

If someone else happens to run into this highly specific issue of things clashing, here is a branch with the fix applied.

helenol commented 2 years ago

Glad you figured out the source of the issue at least! One suggestion that might be a simpler fix if it works: instead of find_package(gflags REQUIRED) give it a hint, like: find_package(gflags REQUIRED PATHS /usr/lib/x86_64-linux-gnu/cmake/gflags) or some variation of the paths there. No idea if this will fix it/work but worth trying and a little bit less invasive if it does!

Isarm commented 2 years ago

Thanks, that works! Definitely a lot nicer that way!