-1

Errors:

LNK2005 "private: static char const * const boost::json::key_value_pair::empty_" (?empty_@key_value_pair@json@boost@@0QBDB) already defined in B_calculating.obj
LNK2005 "private: static struct boost::json::object::table boost::json::object::empty_" (?empty_@object@json@boost@@0Utable@123@A) already defined in B_calculating.obj
LNK2005 "private: static struct boost::json::array::table boost::json::array::empty_" (?empty_@array@json@boost@@0Utable@123@A) already defined in B_calculating.obj

And so on... There are about a hundred of these errors and they are all related to boost json

before asking this question, I spent almost the whole day reading and searching for materials on this topic. It seems that I have already tried everything, but the error remains. I have a few files:

main.cpp:

#include <stdlib.h>
#include <iostream>
#include <mysql/jdbc.h>
#include <boost/json/src.hpp>
#include <boost/json.hpp>
#include <typeinfo>
#include <string>
#include <vector>
#include <math.h>
#include <B_calculating.h>
#include <Level.h>
#include <string>
using namespace std;

//here using B_calculating
//Unfortunately, you won't be able to fully reproduce the example, as it requires data from the database and so on.
....

B_calculating.h:

#pragma once
#include <vector>
#include <boost/json/src.hpp>
#include <boost/json.hpp>
#include <mysql/jdbc.h>
#include <Level.h>

class B_calculating
{
public:
    std::vector<Level> depth;
    sql::ResultSet* sql_result_query;
    const int parameter_value;
    const float step;
    B_calculating(sql::ResultSet* sql_result, int parameter, float input_step);
    void start_processing();
private:
    void request_processing(boost::json::value const& jv);
    void set_level_and_custom_size(Level& l, float zero_level_price);
    void calculate_levels_and_custom_size();
};

B_calculating.cpp:

#include <Q_calculating.h> 
using namespace std;
// here I define functions from .h file

Level.h have similar structure and it works fine.

Alan Birtles
  • 32,622
  • 4
  • 31
  • 60
Vernadsky
  • 3
  • 3
  • 1
    You forgot the full, actual error message. The "already defined" should include both there it is "already defined" **and** where it is (apparently) defined *again*. When faced with perplexing error messages, it is *critical* the *entire* message be included verbatim [in your question](https://stackoverflow.com/posts/71194444/edit). That said, it seems odd that `B_calculating.cpp` doesn't appear to include `B_calculating.h`. Thus the importance of proper [mcve]s. – WhozCraig Feb 20 '22 at 12:37
  • Thank you, I will put more code and all errors – Vernadsky Feb 20 '22 at 12:42
  • I tried to complete the description of the problem. Unfortunately, I'm not sure if you can replicate my program as it is based on a large dataset. I have tried to give the general idea. This is one of my first C++ questions, so I may not know the specific data needed for a C++ question. – Vernadsky Feb 20 '22 at 12:53
  • If you are asking about a compiler error we don't need the runtime data as part of the [mre] – Alan Birtles Feb 20 '22 at 13:04

1 Answers1

3

There is a clue in the boost/json/src.hpp header:

This file is meant to be included once, in a translation unit of the program.

You should only include boost/json/src.hpp in one cpp file. You should remove it from B_calculating.h and only include it in main.cpp.

Alan Birtles
  • 32,622
  • 4
  • 31
  • 60