If everything is ok, when you build your program, you should have something as the hereafter message with, at the end, the sequence all ok:
$> cmt make
------> (Makefile.header) Rebuilding constituents.make
------> (constituents.make) Rebuilding setup.make Darwin.make
CMTCONFIG=Darwin
...
...
...
all ok.
But sometimes a insidious bug unawares arises. In this case the build command won’t end with all ok but with something as:
> ../src/hello.cpp: In function 'int main()':
> ../src/hello.cpp:16: error: 'cout' was not declared in this scope
So the first thing: check the messages sent by the build command!
An error is always reported with error. The compiler will also specify:
Example:
src/hello.cpp:153:error: expected ‘}’ before ‘else’
Warning
Sometimes a first error will be followed by a lot of other errors..
For example if a brace is missing:
src/hello.cpp:153: error: expected `}' before 'else'
src/hello.cpp:153: error: expected `}' before 'else'
src/hello.cpp:156: error: break statement not within loop or switch
src/hello.cpp: At global scope:
src/hello.cpp:159: error: expected declaration before '}' token
The first error is followed by another one, so that the best thing to do is to correct the first one before go on with the second one.
It is a good idea to correct the warning messages too. These arise as:
src/hello.cpp:92: warning: unused variable 'titi'
Include file missing :
> ../src/hello.cpp: In function 'int main()':
> ../src/hello.cpp:16: error: 'cout' was not declared in this scope
The incriminated line contents: std::cout << "Hello!" << std::endl;
The compiler doesn’t find cout(), this method being not declared. The include of the file iostream is missing:
#include <iostream>
‘ambiguous overload’ :
> ../src/visu2d.cpp: In member function 'void Visu2D::SaveSelection()':
> ../src/visu2d.cpp:201: error: ambiguous overload for 'operator==' in 'fname == 0'
> ../src/visu2d.cpp:201: note: candidates are: operator==(const char*, const char*) <built-in>
> ../src/visu2d.cpp:201: note: operator==(QNoImplicitBoolCast, int) <built-in>
> /usr/local/qt/lib/QtCore.framework/Headers/qstring.h:290: note: bool QString::operator==(const QString&) const
> /usr/local/qt/lib/QtCore.framework/Headers/qstring.h:723: note: bool QString::operator==(const char*) const
> /usr/local/qt/lib/QtCore.framework/Headers/qstring.h:340: note: bool QString::operator==(const QByteArray&) const
> /usr/local/qt/lib/QtCore.framework/Headers/qbytearray.h:427: note: bool operator==(const char*, const QByteArray&)
> /usr/local/qt/lib/QtCore.framework/Headers/qstring.h:735: note: bool operator==(const char*, const QString&)
> ../src/visu2d.cpp: In member function 'bool Visu2D::ReadSelection()':
> ../src/visu2d.cpp:214: error: ambiguous overload for 'operator==' in 'fname == 0'
> ../src/visu2d.cpp:214: note: candidates are: operator==(const char*, const char*) <built-in>
> ../src/visu2d.cpp:214: note: operator==(QNoImplicitBoolCast, int) <built-in>
> /usr/local/qt/lib/QtCore.framework/Headers/qstring.h:290: note: bool QString::operator==(const QString&) const
> /usr/local/qt/lib/QtCore.framework/Headers/qstring.h:723: note: bool QString::operator==(const char*) const
> /usr/local/qt/lib/QtCore.framework/Headers/qstring.h:340: note: bool QString::operator==(const QByteArray&) const
> /usr/local/qt/lib/QtCore.framework/Headers/qbytearray.h:427: note: bool operator==(const char*, const QByteArray&)
> /usr/local/qt/lib/QtCore.framework/Headers/qstring.h:735: note: bool operator==(const char*, const QString&)
> make[3]: *** [../Darwin/visu2d.o] error 1
This error, although more verbose, is simpler to resolve than it seems. Looking carefully, the first error is the following:
> ../src/visu2d.cpp:201: error: ambiguous overload for 'operator==' in 'fname == 0'
The corresponding line in the file is:
200 : QString fname = QFileDialog::getOpenFileName(this, "Choose a file", ".", "Images (*.sel)" );
201 : if ( fname == 0)
The variable fname has the QString type and the compiler can not apply the operator ==. It is proposing several solutions:
>note: bool QString::operator==(const QString&) const
>note: bool QString::operator==(const char*) const
>note: bool QString::operator==(const QByteArray&) const
>note: bool operator==(const char*, const QByteArray&)
>note: bool operator==(const char*, const QString&)
Choose the right one ! In our case, the best solution is the following:
201 : if ( fname == QString(""))
‘No such file’ :
> Headers -F/usr/local/qt/lib -DQT3_SUPPORT ../src/myWindow.cpp
> ../src/myWindow.cpp:15:20: error: wframe.h: No such file or directory
The compiler didn’t find the file wframe.h. There are several hints:
#include <iostream>
Means that the file should be in the lookup directories scanned by the compiler by default such system libraries. For example: iostream, fstream …
#include "wframe.h"
This file should be in one among the paths given to the compiler by the build command. There CMT is the manager and the include paths are specified by CMT with the requirements file and the include_dirs directive. By default the include directory is included.
Example 4 :
> In file included from ../src/myWindow.cpp:12:
> ../src/myWindow.h:4:29: error: QtGui/QMainWindow: No such file or directory
> ../src/myWindow.h:5:29: error: QtGui/QPushButton: No such file or directory
> ../src/myWindow.cpp:13:17: error: QMenu: No such file or directory
> ../src/myWindow.cpp:14:20: error: QMenuBar: No such file or directory