C++ Definition of dllimport static data member not allowed - c++

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

Related

C++ LNK2005 already defined in B_calculating.obj

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.

Problem implementing multiples structures in different files c++

I'm trying to run an structure that one of the atributes is another structure, but I keep getting the error "does not name a type" and I'm not sure how to solve it.
Palabra.c
#include "palabra.h"
#include <stdlib.h>
struct nodoPalabra{
Cadena contenido;
nodoPalabra* sigPal;
};
Palabra.h
#ifndef PALABRA_H
#define PALABRA_H
#include "diccionario.h"
#include "editor.h"
#include "linea.h"
typedef struct nodoPalabra * Palabra;
Linea.c
#include "linea.h"
#include "palabra.h"
#include <stdlib.h>
#include<iostream>
struct nodoLinea{
nodoLinea* sigLin;
Palabra priPalab;
};
Linea.h
#ifndef LINEA_H
#define LINEA_H
#include "editor.h"
#include "diccionario.h"
#include "palabra.h"
typedef struct nodoLinea * Linea;
Editor.h
#ifndef EDITOR_H
#define EDITOR_H
enum _retorno{
OK, ERROR, NO_IMPLEMENTADA
};
typedef enum _retorno TipoRetorno;
typedef unsigned int Posicion;
typedef char* Cadena;
#endif
I might be doing something wrong, but I've tried a lot of ways to solve it and wasn't able to fix it.
The error

Included Class Type is apparently not declared, why?

I have the following issue thrown by the compiler:
include/FlowChannel.h:14:21: error: ‘LatticeCell’ was not declared in this scope
std::vector grid;
when having these 3 header files (LatticeCell.h, FlowChannel.h and Utilities.h) and 2 cpp files including them(lbm.cpp and Utilities.cpp):
LatticeCell.h
#ifndef LATTICECELL_H
#define LATTICECELL_H
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
/* Single cell */
using namespace std;
class LatticeCell{
private:
std::vector<double> matrix = {0,0,0,0,0,0,0,0,0};
unsigned int type; //fluid, no-slip, velocity or density
public:
//Constructor
LatticeCell(unsigned int inType){
type = inType;
}
};
#endif
FlowChannel.h
#ifndef FLOWCHANNEL_H
#define FLOWCHANNEL_H
#include <vector>
#include <string>
#include <cmath>
#include <iostream>
#include "LatticeCell.h"
using namespace std;
class FlowChannel{
private:
std::vector<LatticeCell> grid; //ERROR LINE
unsigned int dimX = -1;
unsigned int dimY = -1;
public:
FlowChannel(unsigned int nx, unsigned int ny){
dimX = nx+2;
dimY = ny+2;
unsigned int gridSize = dimX*dimY;
grid.reserve(gridSize);
initGrid(/*TODO Params*/);
}
};
#endif
lbm.cpp
#include <string>
#include <vector>
#include "LatticeCell.h"
#include "FlowChannel.h"
#include "Utilities.h"
int main(int argc, char** argv){
printsomething();
return 0;
}
Utilities.cpp
#include "LatticeCell.h"
#include "FlowChannel.h"
#include <string>
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
void printsomething(){
cout << "something" << std::endl;
}
double calcRelaxationTime(unsigned int ny , double reynolds, double uin){
return 3.0 * (uin * ny / reynolds) - 0.5;
}
Utilities.h
#ifndef UTILITIES_H
#define UTILITIES_H
#include "LatticeCell.h"
#include "FlowChannel.h"
#include <vector>
#include <cmath>
void printsomething();
#endif
Further my compiler flags are:
-Wall -std=c++17 -pedantic
For some reason I can't figure out, why LatticeCell wouldnt be a declared class in FlowChannel, due to it being included. Do you guys know whats wrong?
Edit: I added lbm.cpp, Utilities.cpp and Utilities.h so you guys see the full scope of the problem
You should check if the files are in the same directory.
I copy and paste your code in VS 2019 and it work for me,
here are the pictures
FlowChannel LatticeCell
It seems, that deleting #include 'LatticeCell.h' everywhere but in FlowChannel.h. I dont get the error 100% to be honest, as this wouldn't execatly cause an include loop that would induce such an error, but it works.

C++ use of undeclared identifier IOKit Functions

I am getting an error building my c++ program on xcode. For each of the various fuctions of the IOKit I am getting "use of undeclared identifier". I really don't know why I am getting this error. Here is the code:
#include <iostream>
#include <xlnt/xlnt.hpp>
#include <xlnt/xlnt_config.hpp>
#include <IOKitLib.h>
#include <IOTypes.h>
#include <IOReturn.h>
#include <IOKitKeys.h>
#include <iokitmig.h>
#include <OSMessageNotification.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <paths.h>
#include <termios.h>
#include <sysexits.h>
#include <sys/param.h>
#include <sys/select.h>
#include <sys/time.h>
#include <time.h>
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/serial/IOSerialKeys.h>
#include <IOKit/IOBSD.h>
#define LOCAL_ECHO
#ifdef LOCAL_ECHO
#define kOKResponseString “AT\r\r\nOK\r\n”
#else
#define kOKResponseString “\r\nOK\r\n”
#endif
#define kATCommandString "AT\r"
#define kMyErrReturn -1
enum {
kNumRetries = 3
};
static struct termios gOriginalTTYAttrs;
int main()
{
char path;
char text;
int fileDescriptor;
kern_return_t kernResult;
io_iterator_t serialPortIterator;
char deviceFilePath[MAXPATHLEN];
kernResult = MyFindModems(&serialPortIterator);
kernResult = MyGetModemPath(serialPortIterator, deviceFilePath,
sizeof(deviceFilePath));
Here is the image with all the errors shown: https://i.stack.imgur.com/e1UZS.jpg
Any advice would be more than appreciated. Is it because I haven't declared the functions?
Thanks in advance
Alex

Multiple definition of C++. How to split C++ program properly?

I wrote a program that works without problems, but the thing I am afraid of is that I get a lot of warnings, when I compile it with -Wall option ( it's program written in C and C++). Actually there is only one type of warning, but occurs many times : Multiple definition of .... ( contructors , destructors, and functions ). I thought I did it correcly, but obviously I am wrong. I have 9 files:
Server.h
Server.cpp - implements methods declared in Server.h
RankingCreator.h
RankingCreator.cpp - implements methods declared in RankingCreator.h
Parser.h
Parser.cpp - implements methods declared in Parser.h
PageHandler.h
PageHandler.cpp - implements methods declared in PageHandler.h
and
Main.cpp
- all header files are included in this file, because I use and combine
functionality of all classes here
Each .cpp file except Main.cpp contains only one corresponding .h file included, for instance Server.cpp contains #include "server.h" and no more .h/.cpp files listed above ( but it does contain headers like stdio.h and string.h ). I can post whole warning message here and code of classes, but the lenght of error is about 50 lines, and all classes would be about 1000 lines, so tell me if it is really needed to solve this. Any idea how to solve this? Do I have to make every function inline or something? Every header file has #if def block at the beginning.
EDIT:
Here is the warning log :
g++ LearnTidyCurl.cpp MyParser.cpp PageHandler.cpp RankingCreator.cpp Server.cpp -lcurl -ltidy -o -Wall Wynik
Here is code of one of my header files, see the way of ifdefs :
#ifndef RANKINGCREATOR_H_
#define RANKINGCREATOR_H_
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
//using namespace std;
struct rankingElement {
std::string url;
int rank;
bool operator() (rankingElement i, rankingElement j) { return (i.rank > j.rank);}
} ;
bool operator==(const rankingElement& elem, const std::string& url);
class RankingCreator {
public:
rankingElement compareRankingElements;
const static int MAX_QUERY_RESULT_SIZE = 20;
RankingCreator();
virtual ~RankingCreator();
bool checkPageRank( rankingElement rElement, std::vector<rankingElement> &ranking );
void insertIntoRanking( rankingElement rElement, std::vector<rankingElement>& ranking);
};
#endif /* RANKINGCREATOR_H_ */
I threw warning message out, because it makes this topic unreadable.
Btw. I use include guards auto-generated by Eclipse - shouldn't they be just fine? ( When creating a new class they are automatically created )
EDIT:
You can download gedit file with error log here :
http://www4.zippyshare.com/v/62324366/file.html
I didn't want to post 105-lined error here and in addition it is in crap format, so would not good look here.
Server.h :
#ifndef SERVER_H_
#define SERVER_H_
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <sys/select.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <iostream>
#include <sstream>
#include <vector>
...body...
#endif /* SERVER_H_ */
PageHandler.h
#ifndef PAGEHANDLER_H_
#define PAGEHANDLER_H_
#include <tidy.h>
#include <buffio.h>
#include <stdio.h>
#include <errno.h>
#include <iostream>
#include <string.h>
#include <curl/curl.h>
#include <vector>
#include <algorithm>
#include <stdexcept>
... body ...
#endif /* PAGEHANDLER_H_ */
MyParser.h
#ifndef MYPARSER_H_
#define MYPARSER_H_
#include <vector>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <sstream>
#include <algorithm>
#include <queue>
#include <stdlib.h>
...body...
#endif /* MYPARSER_H_ */
Main.cpp
#include <stdio.h>
#include <iostream>
#include <queue>
#include "MyParser.h"
#include "PageHandler.h"
#include "RankingCreator.h"
#include "Server.h"
#define NO_ERROR 0
std::string convertIntToString(int input) {
std::ostringstream ss;
ss << input;
std::string tmpStr = ss.str();
return tmpStr;
}
int main(int argc, char **argv) {
... body ...
return 0;
}
MyParser.cpp
#include "MyParser.h"
PageHandler.cpp
#include "PageHandler.h"
Server.cpp
#include "Server.h"
RankingCreator.cpp
#include "RankingCreator.h"
Change your inclusion guards:
#ifndef FILENAME_H
#define FILENAME_H
//Code
#endif
And I bet your problem goes away. Obviously make sure each FILENAME_H is unique :) And remember - each header needs this around all it's code, but it shouldn't be in your source files.
Write your header files the following way:
#ifndef SERVER_H
#define SERVER_H
//...
#endif
They are called #include guards to avoid double inclusion problems. Read about them here
If you are ever developing on MVSC++, you can use #pragma once as a first line of each header, but the first solution is portable on every platform.