简单 qtest 失败,'multiple definition of main'
Simple qtest fails with 'multiple definition of main'
这是我第一次做测试,我决定在Qt中尝试,因为我现在正在做一个Qt项目。我试图做的基本上是一个单元测试的"你好世界",这样我就可以熟悉Qt测试了。然而,问题是编译测试失败:
$ make
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -DQT_WEBKIT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I/usr/include/qt4/QtTest -I. -I. -o test_simple.o test_simple.cpp
/usr/bin/moc-qt4 -DQT_WEBKIT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I/usr/include/qt4/QtTest -I. -I. test_simple.h -o moc_test_simple.cpp
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -DQT_WEBKIT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I/usr/include/qt4/QtTest -I. -I. -o moc_test_simple.o moc_test_simple.cpp
g++ -m64 -Wl,-O1 -o qtests test_simple.o moc_test_simple.o -L/usr/lib/x86_64-linux-gnu -lQtTest -lQtGui -lQtCore -lpthread
moc_test_simple.o: In function `main':
moc_test_simple.cpp:(.text.startup+0x0): multiple definition of `main'
test_simple.o:test_simple.cpp:(.text.startup+0x0): first defined here
collect2: ld returned 1 exit status
make: *** [qtests] Error 1
该代码由Simple类和test_Simple测试类组成。
simple.h:
#ifndef SIMPLE_H
#define SIMPLE_H
#include <QObject>
class Simple : public QObject
{
int _a,_b;
public:
void setA(int a) { _a = a; }
void setB(int b) { _b = b; }
int a() { return _a; }
int b() { return _b; }
};
#endif //SIMPLE_H
testrongimple.h:
#ifndef TEST_SIMPLE_H
#define TEST_SIMPLE_H
#include <QTest>
#include "simple.h"
class test_Simple : public QObject
{
Q_OBJECT
private slots:
void testNothing();
};
QTEST_MAIN( test_Simple )
#endif //TEST_SIMPLE_H
testrongimple.cpp:
void test_Simple::testNothing()
{
Simple s;
s.setA(3);
QCOMPARE( s.a(), 3 );
QCOMPARE( s.a(), 2 );
}
编辑:除了这个问题,我想确认你不能测试一个不是从QObject继承的类,对吗?
QTEST_MAIN(test_Simple)
这为您定义了一个主函数——所以只需将它放在您的测试用例"main".cpp中,而不是放在头中!
相关文章:
- "multiple definition of"链接错误
- 编译mbed操作系统程序时"multiple definition of `main'"错误
- 注册 Clang 检查器时出错:"out-of-line-definition of register"
- "Default member initializer needed within definition of enclosing class outside of member functions
- C++:" multiple definition of 'mainCRTStartup' "错误等
- 解决方法:"out of line definition of 'graph' does not match any declaration in 'graph'"
- 在 OpenGL 计划链路状态检查期间"No definition of main in vertex shader"
- "multiple definition of value"在 g++ 中编译具有未初始化全局但不是 gcc 的 C 程序时
- 调试"multiple definition of ..."错误的一般技术?
- 编写仅标头模板库时"Multiple definition of"错误
- C++ - definition of (*this)
- GNU GCC 编译器错误"multiple definition of main"
- 简单 qtest 失败,'multiple definition of main'
- Definition of size_t for Code composer studio
- 使用 -Wall 而不是 -o 时出现"multiple definition of _start"错误
- 编译简单的Hello World时进行多次"multiple definition of ..."
- 使用嵌套模板时出现"template definition of non-template"错误
- "Multiple Definition Of"错误。我做错了什么?
- "Multiple definition of.." "First defined here"数据结构中的同一行中
- 奇怪的"multiple definition of"错误类型