In my makefile on this project, I am specifying 3 location for the compiler to find #includes.
INCLUDES=-I. -I/home/kelly/xerces/xerces-c-3.1.1/src -I/home/kelly/Utilities_New
When I compile the following sample code with the command line found in the comment:
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <xercesc/util/XMLString.hpp>
using namespace std;
/*
g++ -I. -I/home/kelly/xerces/xerces-c-3.1.1/src -I/home/kelly/Utilities_New test.cpp
*/
int main(int argc, char* argv[])
{
cout << "this works" << endl;
}
In file included from /home/kelly/Utilities_New/string.h:5:0,
from /home/kelly/xerces/xerces-c-3.1.1/src/xercesc/framework/XMLBuffer.hpp:28,
from /home/kelly/xerces/xerces-c-3.1.1/src/xercesc/util/XMLString.hpp:26,
from test.cpp:7:
/home/kelly/Utilities_New/defs.h:26:21: fatal error: windows.h: No such file or directory
compilation terminated.
Clearly the compiler has decided that when it processes the Xerces #includes and finds string.h in the Utilities_New directory, it has found what it needs and stops there.
This other string.h was written by another programmer and I am attempting to use his library.
I thought that the standard locations were searched first. I'm a little lost here. I may be missing something super obvious to you all.
Also, wasn't there some rule about #include files that had <> vs. "" around them and where the compiler was supposed to look?
The standard locations are searched last.
#include "blah" is identical to #include <blah> unless blah is found in the same directory as the file that tries to include it. (And unless you use the rare and gcc-specific -iquote option).
For more information see here.
Related
When I try to build test sources I get an error like after this.
stl_tree.h:542:14: error: ‘__node’ does not name a type
::new(__node) _Rb_tree_node<_Val>;
Executor's content.
#include <CppUTest/TestHarness.h>
#include <CppUTest/CommandLineTestRunner.h>
#include <CppUTest/UtestMacros.h>
#include <CppUTestExt/MockSupport.h>
int main(int argc, char** argv) {
MemoryLeakWarningPlugin::turnOffNewDeleteOverloads();
return CommandLineTestRunner::RunAllTests(argc, argv);
}
My test' s source code starts with below includes.
#include <CppUTest/TestHarness.h>
#include <CppUTest/CommandLineTestRunner.h>
#include <CppUTest/UtestMacros.h>
#include <CppUTestExt/MockSupport.h>
#include <iostream>
#include "common/data_util_astro_cfg.h"
TEST_GROUP(ASTRO_UTIL_TEST) {
void setup() { }
void teardown() { }
};
And the "common/data_util_astro_cfg.h" file has following includes.
#include "../data/data_type_file.h"
#include <json/json.h>
static AstroConfigs toAstroConfigs(std::string content)
My problem is I get compilation error with these includes, when I remove line json.h include everything is fine I can get binary output.
I think the problem is about new operator' s conflict. The solution is offered by Cpputest side and it is located on http://cpputest.github.io/manual.html#memory_leak_detection. But it isn't clear somehow. :(
The question has been already defined on Compilation error after including <map>. It is so similar to mine but the problem has solved with creating new project. In that case I have no option for that. I'm using Yocto project and the project has created with auto generation tools as well.
Can you help me on this? (Thank you for your time.)
Unfortunately, I solved the problem after a while. It seems something wrong with CPPUTest. At the top of the test file, I have several includes. Some of them belong to CPPUTest library, some of them are mine. My includes are following CPPUTest that's why I’m getting an error. If I changed their places, it would be working correctly. It seems meaningless, but it is the correct solution. ”PROBLEM SHOULD BE RESOLVED WITH DEFINE CPPUTEST LIBRARIES AT THE BOTTOM OF YOUR INCLUDE LIST.”
I am trying to compile the following code:
#include<stdio.h>
#include <algorithm.h>
int main() {
printf("hello, world!\n");
return 0;
}
But when I run emcc test.c -o test.html I get the following error:
fatal error: 'algorithm.h' file not found
When I remove the line that imports algorithm.h the code compiles perfectly.
Why is this happening? I was under the impression that algorithm.h was part of the standard library.
Edit:
I changed the name of the file from test.c to test.cpp, I updated the header names to <cstdio> and <algorithms>, and I also set -std=c++11 and it works now.
If this is C++ use
#include <cstdio>
in place of stdio.h and
#include <algorithm>
instead
In standard C++ there is no <algorithm.h> - there is only <algorithm>
Also in C++ the stdio header is both accessible from <cstdio> and <stdio.h> for compatibility.
Also since you are including algorithm the file extension should be .cc or .cpp and not .c or else emcc/gcc will treat it as a C source instead of a C++ one.
I've installed boost, so i'm trying to run compiler like this:g++ -LC:\MinGW\boost_1_55_0\stage\lib -lboost_regex-mgw49-mt-1_55 test.cpp
My programm test.cpp is not very complicated:
#include <iostream>
int main()
{
std::cout << "Hello, world!" << std::endl;
boost::regex rex("[test]");
}
I'm of course failed: error: 'boost' has not been declared. I can't understand what I must write in my test.cpp file next to #include <iostream>? #include <boost> doesn't work, i'm getting error fatal error: boost: No such file or directory.
#include <boost/regex.hpp> also yield this error, maybe #include <boost_regex-mgw49-mt-1_55>? But it still doesn't work.
You need to include regex.hpp in your main. You hint that you tried to, but it apparently didn't work.
Make sure regex.hpp is where you tell the compiler it is relative to one of your search directories. It's not good enough to tell the compiler to include boost/regex.hpp, the file has to actually exist where the compiler is looking for it to be able to find it.
You will need to copy that file from wherever you downloaded it to somewhere the compiler will know to look for it. Once you do that, it should find it and that error should go away.
Also note that the same applies to the object file you're trying to link in. If the linker can't find that file, you'll just get a linker error once you clear up this compiler error.
That's my code:
It works good on my mac.
But I'm not sure is that the problem of Gcc version or not.
they said the sstream and string header are wrong.
1779655.134485/Main.c:8:19: fatal error: sstream: No such file or directory
compilation terminated.
here is the hint
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
You are trying to include C++ header file in your C program.
Gcc is C compiler.
You need to rename Main.c to Main.cpp and use g++ compiler...
I am at the absolutely newest level of new when it comes to C++. It may seem like a noob mistake, but I think I'm missing something with my first program, "Hello World!".
I'm running from Ubuntu (not sure if this is any different from working with Windows), and I'm using a book called Teach Yourself C++ in 21 Days.
The code I'm resembling looks exactly like this:
#include <iostream.h>
int main()
{
cout <<"Hello World!\n";
return 0;
}
I have this exactly in my text editor, but I keep getting greeted by the same error whenever I try to compile it!
first.cpp:2:22: fatal error: iostream.h: No such file or directory
compilation terminated.
I'm pretty distressed as this is literally the first step in my coding career! I'm not sure if ubuntu needs to be treated differently than Windows (which is what the book is using as reference).
Help!
There are two problems here:
You need to omit the .h suffix:
#include <iostream>
Also, cout is an unqualified name, and needs to be qualified with the std namespace since you are not using namespace std:
std::cout << "Hello World!\n";
There shouldn't be any iostream.h it's simply called iostream and should look like this:
#include <iostream>
int main()
{
std::cout <<"Hello World!\n";
return 0;
}
(also notice the std:: before the cout, since it means that it's from the standard namespace.)
You want just iostream
#include <iostream>
I suspect the book is very old. Names are qualified in the std namespace, so you may want to add
using namespace std;
For now at least.
use
#include <iostream>
in general STL header file don't have a .h
you need to compile using g++ compiler, not by gcc
g++ hello.cpp