开发者

Error: method was not declared in this scope (but it is included)

I have two folders, f1 and f2, and they are on same level (have same folder for parent). In f1 I have source code of my project, and in f2 I have unit tests.

The problem occurs when I try to include file from my project into unit test class. I just get this:

natty:/tmp/test/f2$ qmake-qt4 .
natty:/tmp/test/f2$ make
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I/usr/include/qt4/QtTest -I../f1 -I. -o main.o main.cpp
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I/usr/include/qt4/QtTest -I../f1 -I. -o tcommon.o tcommon.cpp
tcommon.cpp: In member function ‘void tcommon::tCalculateMD5_str()’:
tcommon.cpp:21:50: 开发者_JAVA百科error: ‘CalculateMD5’ was not declared in this scope
tcommon.cpp: In member function ‘void tcommon::tCalculateMD5_uint()’:
tcommon.cpp:43:50: error: ‘CalculateMD5’ was not declared in this scope
make: *** [tcommon.o] Error 1

What is going on? The code in relevant files is, test/f2/tcommon.cpp:

#include "tcommon.h"
#include <common.h>

// ...

void tcommon::tCalculateMD5_str()
{
    QFETCH(QString, string);
    QFETCH(QString, result);

    // THIS IS LINE 21 <-----------------------------------------------
    QCOMPARE(CalculateMD5(string), result);
}
// ...

And here is common.h from test/f1/common.h (the include is found just fine):

#ifndef COMMON_H
#define COMMON_H

#include <QtCore>

QString CalculateMD5(uint number);
QString CalculateMD5(QString str);

#endif // COMMON_H

Here is project that won't compile (3 kb): http://www.xx77abs.com/test2.rar


Your problem is that you have duplicated the header guards from f1/common.h in f2/tcommon.h.

Change these to (in tcommon.h):

#ifndef TCOMMON_H
#define TCOMMON_H

//...

#endif // TCOMMON_H

and the problem is fixed, the program builds and you can run it. In response: fixed.zip (see source of this answer)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜