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.
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.
Related
I am trying to create a AppServiceConnection but when doing so I get a Incomplete Type not allowed
I verified the header file is imported for that class as mention in other stackoverflow questions.
I tried several different attempted to define the AppServieConnection. Am I putting in the wrong place?
The only way it worked was putting it above the main method.
Here is my code
#include "pch.h"
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <windows.h>
#include <winrt/Windows.ApplicationModel.Activation.h>
#include <tchar.h>
#include <stdio.h>
#include <ppltasks.h>
#include <appmodel.h>
#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <string>
#include <ppltasks.h>
#include <windows.h>
#include <appmodel.h>
#include <malloc.h>
#include <stdio.h>
#include <assert.h>
using namespace winrt;
using namespace concurrency;
using namespace Windows::Foundation;
using namespace std;
using namespace Windows::ApplicationModel::AppService;
AppServiceConnection connection_worked; // defining it here works but cannot call any methods from it
int main()
{
init_apartment();
Uri uri(L"http://aka.ms/cppwinrt");
printf("Hello, %ls!\n", uri.AbsoluteUri().c_str());
}
class NewClass {
private:
Windows::ApplicationModel::AppService::AppServiceConnection connection{nullptr};
Windows::ApplicationModel::AppService::AppServiceConnection connection2;
Windows::ApplicationModel::AppService::AppServiceConnection connection3 = nullptr;
AppServiceConnection connection4;
AppServiceConnection connection5 = nullptr;
AppServiceConnection connection6 = AppServiceConnection();
IAsyncAction InitializeAppServiceConnection() {
}
public:
NewClass() {
}
};
The error is clear, you are missing AppServiceConnection header file.
Please add the header file
#include <winrt/Windows.ApplicationModel.AppService.h>
I'm getting an error everytime I compile the function.cpp file saying that stocks and newStock are not declared in this scope. I'm trying to use a struct inside a vector. Thanks for the help.
This is the main.cpp file
#include <fstream>
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
#include <sstream>
#include <vector>
using namespace std;
struct Stocks
{
int one;
int two;
int three;
};
vector<Stocks> portfolio;
#include "testProject2.h"
int main()
{
buyStock(portfolio);
}
This is the header file.
#include <iostream>
void buyStock(vector<Stocks>& Portfolios);
This is the function.cpp file
#include <iostream>
#include <vector>
#include "testProject2.h"
void buyStock(vector<Stocks>& Portfolios)
{
Stocks newStock;
newStock{1,2,3};
Portfolios.push_back(newStock);
}
Your function.cpp file has no way to know what the Stocks struct is. Define it in the header file:
struct Stocks {
int one;
int two;
int three;
};
And remove its definition from main.cpp.
Also in your header file, you need
#include <vector>
and refer to vector parameter as std::vector<Stocks> &Portfolios (better than using namespace std;)
Your initialization syntax newstock{1,2,3} looks incorrect too.
You use vector in your header file without it being defined.
Try changing the header file to this:
#include <vector>
#include <Stocks.h> // name of .h file where Stocks is defined
void buyStock(std::vector<Stocks>& Portfolios);
// OR
using namespace std::vector;
void buyStock(vector<Stocks>& Portfolios);
I am trying to compile the source/headers of some software into a static library, but am running into this dll issue. I haven't been able to run it down, and the standard #ifndef/#define _declspec(...) isn't working. I don't have a ton of C++ experience, so I'm probably just missing something important. Any help would be appreciated.
The errors occur on the last 4 lines of the section of source code, but I'm not sure how to fix it.
The header and source are a bit too long for here, but this is the jist:
Header(.h):
#ifdef CONVERSIONDLL_EXPORTS
#define CONVERSIONDLL_API __declspec(dllexport)
#else
#define CONVERSIONDLL_API __declspec(dllimport)
#endif
#ifndef ConversionUtility_h
#define ConversionUtility_h
#include <Config.h>
#include <iostream>
using namespace std;
#include <math.h>
#include <stdio.h>
#include <string>
#include <PropertyFileHandler.h>
#include <GWProperties.h>
#include <PureDataS.h>
#include <PureDataI.h>
class MSR_EXPORT Conversions {
Msr::GWFramework::Component::PropertyFileHandler propertyFileHandler_;
double sea_level_corr_;
public:
double static const PI;
double static const DEGREES_PER_RADIAN;
double static const FEET_PER_METER;
unsigned short static RTCODE_WGS_1984_IDENTITY;
...
Source(.cpp):
#include <CountdownTimer.h>
#include "ConversionUtility.h"
#include <Rotation.h>
#include <MsrConversionErrorException.h>
#include <sstream>
#include <stdlib.h>
#include <ctime>
#include <GWTime.h>
#include <GWManagerDefines.h>
double const Conversions::PI = 3.14159265359; // low precision: atan(1.0)*4;
double const Conversions::DEGREES_PER_RADIAN = 180/PI;
double const Conversions::FEET_PER_METER = 1/0.3048;
unsigned short Conversions::RTCODE_WGS_1984_IDENTITY = 341; // from TENA-TSPI tdl
I have absolutely no idea what's going on. I've been looking up explanations for the weirdness going on here but it seems my situation is in some ways unique. I imagined it was the order in which I include my header files in each of my files, but to no avail, I have not found a combination that seems to be the solution.
The exact error I seem to be getting is "log does not name a type" when declaring LogArray[maxLength].
One of my classes, class logmgmt:
class logmgmt
{
private:
static const int maxLength = 500;
log LogArray[maxLength];
int length;
public:
void fillLogs(int index, int iD, std::string date, double startTime, double endTime);
void displayThisLog(int index);
void setLength(int length);
};
Pre-processor directives within logmgmt.cpp:
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#include "log.h"
#include "Logmgmt.h"
And directives within main.cpp
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
#include "employee.h"
#include "log.h"
#include "employeemgmt.h"
#include "Logmgmt.h"
Remove using namespace std.
That is polluting the global namespace with lots of symbol names that can cause these conflicts.
In your example, the function std::log becomes log. So it can no longer name a global type.
I am getting errors with the following code. The errors are incomplete type is not allowed and use of undefined type 'mGame'.
header.h:
//--Libraries
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
//--Classes
class mGame;
Game.cc:
#include "header.h"
class mGame
{
private:
public:
bool intro();
};
Intro.cc:
#include "header.h"
bool mGame::intro() //--Line 3
{
printf("|-----------------------------|\n");
printf("\n Welcome to the Guessing Game!\n");
printf("\n|-----------------------------|\n");
return false;
}
The errors are both on line 3 of intro.cc. I tried finding a solution, but I couldn't for what I am doing.
header.h doesn't know any definitions of game.cc, you tell header.h only, that there is a class mGame. rename game.cc to game.h and include it into header.h and delete the line "class mGame;"
To be able to use mGame from Intro.cc, you have to move the class declaration into header.h (or into some other header file that you include from Intro.cc).
Having a forward declaration in header.h is not enough (that's what is meant by "incomplete type is not allowed").