I've tried the code on Codeblocks and Clion and I'm still getting a redefinition of struct tm error.
#include <iostream>
#include <ctime> // Needed for the true randomization
#include <cstdlib>
using namespace std;
int main ()
{
int xRan;
srand( time(0)); // This will ensure a really randomized number by help of time.
xRan=rand()%15+1; // Randomizing the number between 1-15.
cout << "Shows a random number between 1-15: " << xRan;
return 0;
}
When ever I use the library I get the error. Not sure if theres something
buggy in the minigw include folder or what. Would deleting all my ide's and reinstalling help? Any ideas maybe why?
In file included from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ctime:42:0,
from C:\Users\Kelvindavis\CLionProjects\untitled\main.cpp:2:
c:\mingw\include\time.h:172:8: error: redefinition of 'struct tm'
struct tm
^
In file included from
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar:44:0,
from
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\postypes.h:40,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iosfwd:40,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38from
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39from
C:\Users\Kelvindavis\CLionProjects\untitled\main.cpp:1:
c:\mingw\include\wchar.h:87:8: error: previous definition of 'struct tm'
struct tm {
^
mingw32-make.exe[3]: * [CMakeFiles/untitled.dir/main.cpp.obj] Error 1
CMakeFiles\untitled.dir\build.make:61: recipe for target
'CMakeFiles/untitled.dir/main.cpp.obj' failed
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/untitled.dir/all'
failed
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/untitled.dir/rule'
failed
mingw32-make.exe[2]: [CMakeFiles/untitled.dir/all] Error 2
mingw32-make.exe[1]: [CMakeFiles/untitled.dir/rule] Error 2
mingw32-make.exe: * [untitled] Error 2
Makefile:117: recipe for target 'untitled' failed
Related
I am new in C++ development , As I learn online about extern variable - I tried it to string variables and its working fine.But I have to work with string variable as its not working.Please look as follow.
globals.h
#include <iostream>
using namespace std;
#ifndef SIMULATIONFILEPARSER_GLOBALS_H
#define SIMULATIONFILEPARSER_GLOBALS_H
//sequence of files to be execute
extern string ipFiles[];
#endif //SIMULATIONFILEPARSER_GLOBALS_H
globals.cpp
#include "../headers/globals.h"
//sequence of files to be execute
string ipFiles[] = {"in.relaxSubstrate", "in.relaxFluid"};
main.cpp
#include <iostream>
#include "Source/headers/globals.h"
int main() {
for (string &ipFileName :ipFiles) {
std::cout << ipFileName << std::endl;
}
return 0;
}
When I try to run this project , It gives following error
C:\Users\king\ClionProjects\SimulationFileParser\main.cpp: In function 'int main()':
C:\Users\king\ClionProjects\SimulationFileParser\main.cpp:5:30: error: range-based 'for' expression of type 'std::__cxx11::basic_string<char> []' has incomplete type
for (string &ipFileName :ipFiles) {
^
CMakeFiles\SimulationFileParser.dir\build.make:61: recipe for target 'CMakeFiles/SimulationFileParser.dir/main.cpp.obj' failed
mingw32-make.exe[3]: *** [CMakeFiles/SimulationFileParser.dir/main.cpp.obj] Error 1
mingw32-make.exe[3]: *** Waiting for unfinished jobs....
mingw32-make.exe[2]: *** [CMakeFiles/SimulationFileParser.dir/all] Error 2
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/SimulationFileParser.dir/all' failed
mingw32-make.exe[1]: *** [CMakeFiles/SimulationFileParser.dir/rule] Error 2
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/SimulationFileParser.dir/rule' failed
mingw32-make.exe: *** [SimulationFileParser] Error 2
Makefile:117: recipe for target 'SimulationFileParser' failed
The compiler doesn't complain about a symbol, that's not visible. It's telling you, that the type is incomplete:
range-based 'for' expression of type 'std::__cxx11::basic_string []' has incomplete type
Until the compiler knows the size of the array, it cannot compile the range-based for loop. To change this, you need to declare a complete type. This could be an array with an explicit size, or - and that's the recommended solution - a standard container1:
globals.h
#pragma once
#include <string>
#include <vector>
extern std::vector<std::string> ipFiles;
globals.cpp
std::vector<std::string> ipFiles{"in.relaxSubstrate", "in.relaxFluid"};
You don't have to change main.cpp. But if you want to make it fancy, you could use auto as well as exercising const-correctness:
int main() {
for (const auto& ipFileName : ipFiles) {
std::cout << ipFileName << std::endl;
}
return 0;
}
1 The size of a standard container does not need to be known at compile time. All the compiler needs are the (forward) iterators to begin() and end() of the controlled sequence. An array, on the other hand, doesn't provide those as member functions, and the compiler needs to generate them. It needs to know the size to generate the equivalent of end().
This loop does not know the size of array.
for (string &ipFileName :ipFiles)
Change in global.h
extern string ipFiles[2];
change in global.cpp
string ipFiles[2] = {"in.relaxSubstrate", "in.relaxFluid"};
After this your code should compile properly.
i have included the path to python.h(C:\Users\vinay\AppData\Local\Programs\Python\Python37-32\include) file and gave the library path of the project to "C:\Users\AppData\Local\Programs\Python\Python37-32\Lib"
and my code is as pasted below:-
#include <iostream>
#include <Python.h>
using namespace std;
int main(int argc, char **argv)
{
PyObject *pInt;
Py_Initialize();
PyRun_SimpleString("print('Hello world from embedded python!!!\n')");
Py_Finalize();
cout<<"now i am finally out of the python"<<endl;
return 0;
}
when i compile the program there is no error but when i build the project i get the following erros
C:/Users/Documents/CppWorkspace/Cpp_in_python/main.cpp:8: undefined reference to `_imp__Py_Initialize'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:/Users/Documents/CppWorkspace/Cpp_in_python/main.cpp:9: undefined reference to `_imp__PyRun_SimpleStringFlags'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:/Users/Documents/CppWorkspace/Cpp_in_python/main.cpp:10: undefined reference to `_imp__Py_Finalize'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[1]: *** [Debug/Cpp_in_python] Error 1
mingw32-make.exe: *** [All] Error 2
Cpp_in_python.mk:78: recipe for target 'Debug/Cpp_in_python' failed
mingw32-make.exe[1]: Leaving directory 'C:/Users/vinay/Documents/CppWorkspace/Cpp_in_python'
Makefile:4: recipe for target 'All' failed
====4 errors, 0 warnings====
I've looked through a few posts on this same error and it seems this happens when the compiler can't find a constructor that matches the signature?
But I can't rule out the possibility since my case is rather different - it has a __declspec(dllexport) and I'm not sure if this it the culprit causing the problem.
Here is the error message:
yuqiong#yuqiong-G7-7588:/media/yuqiong/DATA/Vignetting_corrector/C++/Vig_Correction/build$ make
Scanning dependencies of target correction
[ 50%] Building CXX object CMakeFiles/correction.dir/Vig_Correction.cpp.o
In file included from /media/yuqiong/DATA/Vignetting_corrector/C++/Vig_Correction/Vig_Correction.cpp:5:0:
/media/yuqiong/DATA/Vignetting_corrector/C++/Vig_Correction/ColorCorrection.hpp:16:10: error: expected constructor, destructor, or type conversion before ‘(’ token
_declspec(dllexport) int VignettingCorrectionUsingRG(unsigned char* pImage, int ht, int wd,
^
/media/yuqiong/DATA/Vignetting_corrector/C++/Vig_Correction/Vig_Correction.cpp: In function ‘int VignettingCorrect(IplImage*)’:
/media/yuqiong/DATA/Vignetting_corrector/C++/Vig_Correction/Vig_Correction.cpp:47:65: error: ‘VignettingCorrectionUsingRG’ was not declared in this scope
int flag=VignettingCorrectionUsingRG(pImageBuffer, sht, swd, vp);
^
CMakeFiles/correction.dir/build.make:62: recipe for target 'CMakeFiles/correction.dir/Vig_Correction.cpp.o' failed
make[2]: *** [CMakeFiles/correction.dir/Vig_Correction.cpp.o] Error 1
CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/correction.dir/all' failed
make[1]: *** [CMakeFiles/correction.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
Here is my ColorCorrection.hpp file...
#ifndef COLOR_CORRECTION_HPP
#define COLOR_CORRECTION_HPP
#include <vector>
using namespace std;
__declspec(dllexport) int VignettingCorrectionUsingRG(unsigned char* pImage, int ht, int wd, vector<double>& vp);
#endif
Thanks so much for your help in advance...
I am currently working with the thrift examples: Click
The following test code I created doesn't compile.
#include <thrift/transport/TSocket.h>
#include <thrift/transport/TBufferTransports.h>
#include <thrift/protocol/TBinaryProtocol.h>
using namespace apache::thrift;
using namespace apache::thrift::protocol;
using namespace apache::thrift::transport;
int main(int argc, char **argv) {
boost::shared_ptr<TSocket> socket(new TSocket("localhost", 9090));
boost::shared_ptr<TTransport> transport(new TBufferedTransport(socket));
boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
return 0;
}
When trying to compile, the following exception occurs:
/opt/JetBrains/apps/CLion/ch-0/181.5087.36/bin/cmake/bin/cmake --build /home/user/Documents/Projects/VerteilteSysteme/Insurer/cmake-build-debug --target Insurer -- -j 2
Scanning dependencies of target Insurer
[ 50%] Building CXX object CMakeFiles/Insurer.dir/main.cpp.o
/home/user/Documents/Projects/VerteilteSysteme/Insurer/main.cpp: In function ‘int main(int, char**)’:
/home/user/Documents/Projects/VerteilteSysteme/Insurer/main.cpp:10:38: error: variable ‘boost::shared_ptr<apache::thrift::transport::TSocket> socket’ has initializer but incomplete type
boost::shared_ptr<TSocket> socket(new TSocket("localhost", 9090));
^
/home/user/Documents/Projects/VerteilteSysteme/Insurer/main.cpp:11:44: error: variable ‘boost::shared_ptr<apache::thrift::transport::TTransport> transport’ has initializer but incomplete type
boost::shared_ptr<TTransport> transport(new TBufferedTransport(socket));
^
/home/user/Documents/Projects/VerteilteSysteme/Insurer/main.cpp:12:42: error: variable ‘boost::shared_ptr<apache::thrift::protocol::TProtocol> protocol’ has initializer but incomplete type
boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
^
make[3]: *** [CMakeFiles/Insurer.dir/build.make:63: CMakeFiles/Insurer.dir/main.cpp.o] Error 1
make[2]: *** [CMakeFiles/Makefile2:68: CMakeFiles/Insurer.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:80: CMakeFiles/Insurer.dir/rule] Error 2
make: *** [Makefile:118: Insurer] Error 2
I double-checked, both, boost and thrift is properly installed on my system. (ArchLinux x64). Whats the cause of this error?
#include <boost/shared_ptr.hpp>
maybe it is forward declared somewhere in thrift's headers?
I am new in C++ development , As I learn online about extern variable - I tried it to string variables and its working fine.But I have to work with string variable as its not working.Please look as follow.
globals.h
#include <iostream>
using namespace std;
#ifndef SIMULATIONFILEPARSER_GLOBALS_H
#define SIMULATIONFILEPARSER_GLOBALS_H
//sequence of files to be execute
extern string ipFiles[];
#endif //SIMULATIONFILEPARSER_GLOBALS_H
globals.cpp
#include "../headers/globals.h"
//sequence of files to be execute
string ipFiles[] = {"in.relaxSubstrate", "in.relaxFluid"};
main.cpp
#include <iostream>
#include "Source/headers/globals.h"
int main() {
for (string &ipFileName :ipFiles) {
std::cout << ipFileName << std::endl;
}
return 0;
}
When I try to run this project , It gives following error
C:\Users\king\ClionProjects\SimulationFileParser\main.cpp: In function 'int main()':
C:\Users\king\ClionProjects\SimulationFileParser\main.cpp:5:30: error: range-based 'for' expression of type 'std::__cxx11::basic_string<char> []' has incomplete type
for (string &ipFileName :ipFiles) {
^
CMakeFiles\SimulationFileParser.dir\build.make:61: recipe for target 'CMakeFiles/SimulationFileParser.dir/main.cpp.obj' failed
mingw32-make.exe[3]: *** [CMakeFiles/SimulationFileParser.dir/main.cpp.obj] Error 1
mingw32-make.exe[3]: *** Waiting for unfinished jobs....
mingw32-make.exe[2]: *** [CMakeFiles/SimulationFileParser.dir/all] Error 2
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/SimulationFileParser.dir/all' failed
mingw32-make.exe[1]: *** [CMakeFiles/SimulationFileParser.dir/rule] Error 2
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/SimulationFileParser.dir/rule' failed
mingw32-make.exe: *** [SimulationFileParser] Error 2
Makefile:117: recipe for target 'SimulationFileParser' failed
The compiler doesn't complain about a symbol, that's not visible. It's telling you, that the type is incomplete:
range-based 'for' expression of type 'std::__cxx11::basic_string []' has incomplete type
Until the compiler knows the size of the array, it cannot compile the range-based for loop. To change this, you need to declare a complete type. This could be an array with an explicit size, or - and that's the recommended solution - a standard container1:
globals.h
#pragma once
#include <string>
#include <vector>
extern std::vector<std::string> ipFiles;
globals.cpp
std::vector<std::string> ipFiles{"in.relaxSubstrate", "in.relaxFluid"};
You don't have to change main.cpp. But if you want to make it fancy, you could use auto as well as exercising const-correctness:
int main() {
for (const auto& ipFileName : ipFiles) {
std::cout << ipFileName << std::endl;
}
return 0;
}
1 The size of a standard container does not need to be known at compile time. All the compiler needs are the (forward) iterators to begin() and end() of the controlled sequence. An array, on the other hand, doesn't provide those as member functions, and the compiler needs to generate them. It needs to know the size to generate the equivalent of end().
This loop does not know the size of array.
for (string &ipFileName :ipFiles)
Change in global.h
extern string ipFiles[2];
change in global.cpp
string ipFiles[2] = {"in.relaxSubstrate", "in.relaxFluid"};
After this your code should compile properly.