nasa / trick

Trick Simulation Environment. Trick provides a common set of simulation capabilities and utilities to build simulations automatically.
Other
34 stars 19 forks source link

How to add third party libraries to trick build system? #1654

Closed yusufcananar closed 7 months ago

yusufcananar commented 7 months ago

I am using a library called nlohmann/json.hpp (which is a single header file project) within trick_source/sim_services/DRMongo.cpp (I am adding db adapter to trick). I have created a folder called third_party and loaded the library inside as third_party/include/nlohmann/json.hpp at TRICK_HOME When i make the trick I got this following error and my build is not completed. I think swig or icg (where i am not familiar its working principle) is the reason for this error. I want to know how to add third party libraries to trick build system?

io_src/io_json.cpp: In function ‘void io_src_destruct_nlohmann__json_abi_v3_11_3__detail__nonesuch(void*, int)’:
io_src/io_json.cpp:63:27: error: use of deleted function ‘nlohmann::json_abi_v3_11_3::detail::nonesuch::~nonesuch()’
   63 |         temp[ii].~nonesuch();
      |         ~~~~~~~~~~~~~~~~~~^~
In file included from io_src/io_json.cpp:19:
/home/fjolnirr/trick/third_party/include/nlohmann/json.hpp:269:5: note: declared here
  269 |     ~nonesuch() = delete;
      |     ^
/usr/bin/g++ -I/home/fjolnirr/trick/third_party/include -I/usr/local/include/mongocxx/v_noabi -I/usr/local/include/bsoncxx/v_noabi -I/usr/local/include/bsoncxx/v_noabi/bsoncxx/third_party/mnmlstc -Wno-unused-but-set-variable -isystem/home/fjolnirr/trick/trick_source -isystem/home/fjolnirr/trick/include -isystem/home/fjolnirr/trick/include/trick/compat -DTRICK_VER=19 -DTRICK_MINOR=7 -fpic  -DUSE_ER7_UTILS_INTEGRATORS -std=c++11 -Wno-invalid-offsetof -c io_src/io_lqueue.cpp -o object_Linux_11.4_x86_64/io_lqueue.o
io_src/io_json.cpp: In function ‘void io_src_delete_nlohmann__json_abi_v3_11_3__detail__nonesuch(void*)’:
io_src/io_json.cpp:68:59: error: use of deleted function ‘nlohmann::json_abi_v3_11_3::detail::nonesuch::~nonesuch()’
   68 |     delete (nlohmann::json_abi_v3_11_3::detail::nonesuch*)address;
      |                                                           ^~~~~~~
In file included from io_src/io_json.cpp:19:
/home/fjolnirr/trick/third_party/include/nlohmann/json.hpp:269:5: note: declared here
  269 |     ~nonesuch() = delete;
      |     ^
io_src/io_json.cpp: In function ‘void* io_src_allocate_nlohmann__json_abi_v3_11_3__detail__dtoa_impl__boundaries(int)’:
io_src/io_json.cpp:1265:82: error: use of deleted function ‘nlohmann::json_abi_v3_11_3::detail::dtoa_impl::boundaries::boundaries()’
 1265 |         new(&temp[ii]) nlohmann::json_abi_v3_11_3::detail::dtoa_impl::boundaries();
      |                                                                                  ^
In file included from io_src/io_json.cpp:19:
/home/fjolnirr/trick/third_party/include/nlohmann/json.hpp:17083:8: note: ‘nlohmann::json_abi_v3_11_3::detail::dtoa_impl::boundaries::boundaries()’ is implicitly deleted because the default definition would be ill-formed:
17083 | struct boundaries
      |        ^~~~~~~~~~
/home/fjolnirr/trick/third_party/include/nlohmann/json.hpp:17083:8: error: no matching function for call to ‘nlohmann::json_abi_v3_11_3::detail::dtoa_impl::diyfp::diyfp()’
/home/fjolnirr/trick/third_party/include/nlohmann/json.hpp:16972:15: note: candidate: ‘constexpr nlohmann::json_abi_v3_11_3::detail::dtoa_impl::diyfp::diyfp(uint64_t, int)’
16972 |     constexpr diyfp(std::uint64_t f_, int e_) noexcept : f(f_), e(e_) {}
      |               ^~~~~
/home/fjolnirr/trick/third_party/include/nlohmann/json.hpp:16972:15: note:   candidate expects 2 arguments, 0 provided
/home/fjolnirr/trick/third_party/include/nlohmann/json.hpp:16965:8: note: candidate: ‘constexpr nlohmann::json_abi_v3_11_3::detail::dtoa_impl::diyfp::diyfp(const nlohmann::json_abi_v3_11_3::detail::dtoa_impl::diyfp&)’
16965 | struct diyfp // f * 2^e
      |        ^~~~~
/home/fjolnirr/trick/third_party/include/nlohmann/json.hpp:16965:8: note:   candidate expects 1 argument, 0 provided
/home/fjolnirr/trick/third_party/include/nlohmann/json.hpp:16965:8: note: candidate: ‘constexpr nlohmann::json_abi_v3_11_3::detail::dtoa_impl::diyfp::diyfp(nlohmann::json_abi_v3_11_3::detail::dtoa_impl::diyfp&&)’
/home/fjolnirr/trick/third_party/include/nlohmann/json.hpp:16965:8: note:   candidate expects 1 argument, 0 provided
/home/fjolnirr/trick/third_party/include/nlohmann/json.hpp:17083:8: error: no matching function for call to ‘nlohmann::json_abi_v3_11_3::detail::dtoa_impl::diyfp::diyfp()’
17083 | struct boundaries
      |        ^~~~~~~~~~
/home/fjolnirr/trick/third_party/include/nlohmann/json.hpp:16972:15: note: candidate: ‘constexpr nlohmann::json_abi_v3_11_3::detail::dtoa_impl::diyfp::diyfp(uint64_t, int)’
16972 |     constexpr diyfp(std::uint64_t f_, int e_) noexcept : f(f_), e(e_) {}
      |               ^~~~~
/home/fjolnirr/trick/third_party/include/nlohmann/json.hpp:16972:15: note:   candidate expects 2 arguments, 0 provided
/home/fjolnirr/trick/third_party/include/nlohmann/json.hpp:16965:8: note: candidate: ‘constexpr nlohmann::json_abi_v3_11_3::detail::dtoa_impl::diyfp::diyfp(const nlohmann::json_abi_v3_11_3::detail::dtoa_impl::diyfp&)’
16965 | struct diyfp // f * 2^e
      |        ^~~~~
/home/fjolnirr/trick/third_party/include/nlohmann/json.hpp:16965:8: note:   candidate expects 1 argument, 0 provided
/home/fjolnirr/trick/third_party/include/nlohmann/json.hpp:16965:8: note: candidate: ‘constexpr nlohmann::json_abi_v3_11_3::detail::dtoa_impl::diyfp::diyfp(nlohmann::json_abi_v3_11_3::detail::dtoa_impl::diyfp&&)’
/home/fjolnirr/trick/third_party/include/nlohmann/json.hpp:16965:8: note:   candidate expects 1 argument, 0 provided
/home/fjolnirr/trick/third_party/include/nlohmann/json.hpp:17083:8: error: no matching function for call to ‘nlohmann::json_abi_v3_11_3::detail::dtoa_impl::diyfp::diyfp()’
17083 | struct boundaries
      |        ^~~~~~~~~~
/home/fjolnirr/trick/third_party/include/nlohmann/json.hpp:16972:15: note: candidate: ‘constexpr nlohmann::json_abi_v3_11_3::detail::dtoa_impl::diyfp::diyfp(uint64_t, int)’
16972 |     constexpr diyfp(std::uint64_t f_, int e_) noexcept : f(f_), e(e_) {}
      |               ^~~~~
/home/fjolnirr/trick/third_party/include/nlohmann/json.hpp:16972:15: note:   candidate expects 2 arguments, 0 provided
/home/fjolnirr/trick/third_party/include/nlohmann/json.hpp:16965:8: note: candidate: ‘constexpr nlohmann::json_abi_v3_11_3::detail::dtoa_impl::diyfp::diyfp(const nlohmann::json_abi_v3_11_3::detail::dtoa_impl::diyfp&)’
16965 | struct diyfp // f * 2^e
      |        ^~~~~
/home/fjolnirr/trick/third_party/include/nlohmann/json.hpp:16965:8: note:   candidate expects 1 argument, 0 provided
/home/fjolnirr/trick/third_party/include/nlohmann/json.hpp:16965:8: note: candidate: ‘constexpr nlohmann::json_abi_v3_11_3::detail::dtoa_impl::diyfp::diyfp(nlohmann::json_abi_v3_11_3::detail::dtoa_impl::diyfp&&)’
/home/fjolnirr/trick/third_party/include/nlohmann/json.hpp:16965:8: note:   candidate expects 1 argument, 0 provided

I have tried to add TRICK_SWIG_EXCLUDE += ${TRICK_HOME}/third_party/include this to Makefile.common but still same error. Also I have added the lines below to Makefile at TRICK_HOME dir;

TRICK_CXXFLAGS += -O0 -g -I${TRICK_HOME}/third_party/include \
            -I/usr/local/include/mongocxx/v_noabi \
            -I/usr/local/include/bsoncxx/v_noabi \
            -I/usr/local/include/bsoncxx/v_noabi/bsoncxx/third_party/mnmlstc 

Make system is a little bit complicated for me especially in this project sorry in advance if i am asking very simple task. Also is there any document that describes trick build system(not for the sims but for the source code development)?

yusufcananar commented 7 months ago

I have managed to build successfully. Makefile.common :

# This is required for 3rd party nlohmann/json header
TRICK_SWIG_EXCLUDE += /$(TRICK_HOME)/third_party
TRICK_ICG_EXCLUDE += $(TRICK_HOME)/third_party

# This is required for 3rd party MongoDB library
TRICK_EXEC_LINK_LIBS += -L/usr/local/lib -lpthread -lcrypto -lssl -lmongocxx -lbsoncxx

Also adding preprocessor directives to my adapter(DRMongo) where i used json functions :

#ifndef SWIG
#include "nlohmann/json.hpp"
#endif
.
.
.
#ifndef SWIG
            /**
             * @brief Turns variable strings into json format
             * @return json
            */
            nlohmann::json variable_string_to_json(nlohmann::json j, std::string str, std::string value);
#endif

But I know it is not the best practice(or it is just the beginning of it) for adding a 3rd party. I have seen civetweb and hdf5 usage but they have many relations (and conditions) in the code like in ./configure or Makefile.common or even makefiles of their own folder has sth unique.

What is the harm excluding from swig and ICG? I have tried my code is working as expected nothing broken. I am afraid if excluding the class from swig harms me in later.

hchen99 commented 7 months ago

Could also use TRICK_EXCLUDE to instruct both SWIG and ICG to skip. Won't be able to data recording and input process

sharmeye commented 7 months ago

Just to follow up with what @hchen99 said, if you SWIG_EXCLUDE then you lose the ability to interact with your classes via the input processor or variable server (same thing really). If you ICG_EXCLUDE, then Trick will not be able to manage the memory, provide data recording, drop or load checkpoints, and things like that. If you have any further questions please reach out.