0

I would like to use Open3d in LAMMPS. Open3D details how to find the pre-installed Open3D package using cmake.

Using the above, I have written a cmake file that I believe LAMMPS uses during its build stage to find packages and link them. Curiously, the line

target_link_libraries(lammps PRIVATE Open3D::Open3D)

appears to cause the compiler to find errors in the LAMMPS src code, i.e.,

/home/USER/lammps/src/fmtlib_format.cpp:58:51: error: duplicate explicit instantiation of ‘struct fmt::v7_lmp::detail::basic_data<void>’ [-fpermissive]
   58 | template struct FMT_INSTANTIATION_DEF_API detail::basic_data<void>;

If I comment the target_link_libraries statement, the code compiles just fine (but doesn't link to Open3D). Apologies for being unable to provide a MWE as I do not know how to replicate this behaviour in a simple manner. Could you please explain to me why the target_link_libraries command causes the compiler to find errors in the LAMMPS src code and provide a solution to prevent this from occuring? If relevant I am using Clion 2021.1.2 and

CMAKE_CXX_COMPILER_VERSION = 9.3.0
CMAKE_CXX_STANDARD = 11
CMAKE_VERSION = 3.19.2
1QuickQuestion
  • 417
  • 6
  • 16
  • 2
    After some digging, I think I know what happens. You see, both `lammps` and `Open3D` use an external library (`libfmt`) for formatted output. While `Open3D` allows you to use an external installation of this particular library, seems like `lammps` uses a baked in version of that (namely version 7.1.1). I'm guessing in this case the git submodule from `Open3D` and the one baked into `lammps` are different (maybe even different major versions) and they clash. My suggestion? Isolate, somehow - and if possible, the parts which include libfmt (either from `Open3D` or from `lammps` – ben10 Jun 22 '21 at 11:34
  • 2
    Important also, `target_link_libraries` does a bit more than just help you with linking. It also brings in all the dependencies and public/interface include directories of `Open3D`. Thus, you may get some surprise includes. You could, potentially, export your compile commands [cmake](https://cmake.org/cmake/help/v3.15/variable/CMAKE_EXPORT_COMPILE_COMMANDS.html) to see the include paths. – ben10 Jun 22 '21 at 11:42
  • When installing Open3d from source and after running cmake, the terminal does indeed state `Building library 3rdparty_fmt from source`. Would it be a terrible idea to somehow redirect this to the lammps baked-in version of `libfmt`? – 1QuickQuestion Jun 22 '21 at 12:29
  • You would have to check if they're compatible (I think they are). Then, you need to make `Open3D` search inside `lammps`... not great. I think `Open3D` uses `find_package` when it's instructed to search for an external `libfmt` - so it won't work out of the box. With some patches here and there it could work. You could also use a small trick. Create your own `Findfmt` module which uses a predefined variable, like `fmt_ROOT`, and set that to wherever the baked in `fmt` is EDIT: I'm not sure if the formatting part is part of the public API of `lammps` so it may not actually be installed – ben10 Jun 22 '21 at 13:03

0 Answers0