How to Solve "Unresolved Inclusion: <Iostream>" in a C++ File in Eclipse Cdt

Unresolved inclusion error with Eclipse CDT for C standard library headers

The compiler Eclipse is using is able to resolve the symbols just fine, so the code will compile fine.

But the code-completion/indexer or preprocessor Eclipse is using doesn't know where stdio.h exists.

You need to specify the filesystem path where stdio.h is located.

The Eclipse documentation describes this in several sections for the compiler:

  • Adding include paths and symbols
  • C/C++ Project Properties, Paths and Symbols, Includes

And if the code-completion/indexer or preprocessor specifically also cannot locate stdio.h:

  • Setting up include paths and macros for C/C++ indexer
  • C/C++ Project properties: Preprocessor Include Paths, Macros, etc.

The exact location of stdio.h will depend on the system you are intending to write the code for. If you are writing code for the same system you are running Eclipse on, then the standard location is /usr/include/stdio.h for Linux, macOS, Cygwin, etc.

If you are cross-compiling for a separate/remote target system (e.g. Android, Raspberry Pi, STM32), then it will be located somewhere in the SDK you installed for that system. You will need to refer to that particular SDK documentation.

string could not resolved error in Eclipse for C++ (Eclipse can't resolve standard library)

The problem was that I needed to have both minGW and MSYS installed and added to PATH.

The problem is now fixed.

Unresolved inclusion in Eclipse

The screenshot only shows that the directories exist, not that the right files within them exist.

To fix these kind of dependency issues:

sudo apt-get --install-suggests install eclipse-cdt

or on yum-based distributions

sudo yum install eclipse-cdt

This should install all the necessary dependencies. If it installs eclipse-cdt but doesn't install all its dependencies on your distribution, well that's a bug in that distribution.

no match for 'operator ' (operand types are '__FILE*' {aka '__sFILE64*'} and 'MyObject' ) error C++

For starters there is a typo

class MyObject {
private:
string s1;
sting s2;
^^^^^
//...

This operator

std::ostream& operator<<(MyObject const& o);

is not the same as this operator

std::ostream& operator<<(std::iostream& os, MyObject const& o) {
std::string s = toString();
os << s;
return os;
}

And it seems this member function

std::ostream& operator<<(MyObject const& o);

is redundant.

Moreover in definitions of members of the class outside the class you have to use a qualified name as for example

MyObject::MyObject(){
s1 = "hello";
s2 = "world";
}

The class can be defined in the header like

class MyObject {
private:
string s1;
sting s2;
public:
MyObject();
std::string toString() const;
};

Class members can be defined like

MyObject::MyObject() : s1( "hello" ), s2( "world" ){
}

std::string MyObject::toString() const {
return s1 + " " + s2;
}

and the operator << can be defined in the header like

inline std::ostream & operator<<(std::ostream& os, MyObject const& o) {
return os << o.toString();
}

Note that it should take a std::ostream&, not a std::iostream&.

Unresolved iostream in Eclipse, Ubuntu

The reason is that Eclipse simply cannot import a proper header. C++ iostream header in Ubuntu can be found:

$: sudo find / -name iostream

/home/beniamin/QtSDK/Madde/toolchains/arm-2009q3-67-arm-none-linux-gnueabi-x86_64-unknown-linux-gnu/arm-2009q3-67/arm-none-linux-gnueabi/include/c++/4.4.1/iostream
/home/beniamin/QtSDK/Madde/sysroots/harmattan_sysroot_10.2011.34-1_slim/usr/include/c++/4.4/iostream
/usr/share/gccxml-0.9/GCC/2.95/iostream
/usr/include/c++/4.6/iostream
/usr/include/boost/tr1/tr1/iostream

So basically, I suppose the one you are looking for is /usr/include/c++/4.6/iostream, so you should in some place include this directory.

Edit: You should also have installed g++, or simply install build-essential package, which is obligatory for building debian packages. Nevertheless, g++ should have been included in your Ubuntu installation anyway.



Related Topics



Leave a reply



Submit