Please advise what is wrong with my case that does not work.
I have a extracted this minimal example to show the issue:
in my project folder (name is 'ttt'):
ttt$ ls
config.cpp include main.cpp
ttt$ ls include/
config.h nlohmann
ls include/nlohmann/
json.hpp json_fwd.hpp <<<<<These are copied from the 3.11.2 https://github.com/nlohmann/json/releases/tag/v3.11.2
ttt$ cat main.cpp
#include "config.h"
#include <iostream>
int main() {
Config c("../global_config.json");
std::cout << c.getParcelCount() << std::endl;
return 0;
}
ttt$ cat config.cpp
#include <nlohmann/json.hpp>
#include "config.h"
#include <fstream>
Config::Config(std::string config_path) {
std::ifstream f(config_path);
config_ = json::parse(f);
}
ttt$ cat include/config.h
#include <nlohmann/json_fwd.hpp>
using json = nlohmann::json;
class Config {
private:
json config_;
public:
Config(std::string path);
int getParcelCount() {
return config_.value("parcel_count", 3);
}
};
Running with following command:
g++ config.cpp main.cpp -std=c++17 -I include/
I am getting following errors:
In file included from main.cpp:1:0:
include/config.h:7:9: error: field ‘config_’ has incomplete type ‘json {aka nlohmann::json_abi_v3_11_2::basic_json<>}’
json config_;
^~~~~~~
In file included from include/config.h:1:0,
from main.cpp:1:
include/nlohmann/json_fwd.hpp:151:7: note: declaration of ‘using json = using json = class nlohmann::json_abi_v3_11_2::basic_json<> {aka class nlohmann::json_abi_v3_11_2::basic_json<>}’
class basic_json;
^~~~~~~~~~
I am using g++ 7.5.0 version on Jetson Xavier NX with JetPack 4.6.3
g++ (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04) 7.5.0
If more infor