简体   繁体   English

使用Qt和Boost编译针对应用程序的CppUTest测试时的奇怪行为

[英]Weird behaviour when compiling CppUTest tests for application using Qt and Boost

I've following problem. 我在跟踪问题。 When I try to compile .so library everything works fine. 当我尝试编译.so库时,一切正常。

Scanning dependencies of target logger
[ 11%] Building CXX object CMakeFiles/logger.dir/src/defaultconfig.cpp.o
[ 22%] Building CXX object CMakeFiles/logger.dir/src/loggerstate.cpp.o
[ 33%] Building CXX object CMakeFiles/logger.dir/src/configmanager.cpp.o
[ 44%] Building CXX object CMakeFiles/logger.dir/src/configuration.cpp.o
[ 55%] Building CXX object CMakeFiles/logger.dir/src/formatter.cpp.o
[ 66%] Building CXX object CMakeFiles/logger.dir/src/levelmap.cpp.o
[ 77%] Building CXX object CMakeFiles/logger.dir/src/logger.cpp.o
[ 88%] Building CXX object CMakeFiles/logger.dir/src/logworker.cpp.o
[100%] Linking CXX shared library liblogger.so
[100%] Built target logger

By when I try to create executable which use for example logger.cpp eg. 当我尝试创建可执行文件时,例如使用logger.cpp test file I get wall of errors. 测试文件中出现错误墙。 Full log is here . 完整日志在这里 However the most funny thing that it compiles on ones developer computer. 但是,它在开发人员计算机上编译的最有趣的事情。 We check compiler version, cmake version and everything is the same . 我们检查编译器版本,cmake版本,并且一切都相同 The cpputest version wasn't the same. cpputest版本不同。

Maybe anyone of you have face such problem and know what we doing wrong. 也许你们中的任何人都面临这样的问题,并且知道我们做错了什么。

In file included from /opt/Qt5.3.2/5.3/gcc_64/include/QtCore/qobject.h:51:0,
                 from /opt/Qt5.3.2/5.3/gcc_64/include/QtCore/qabstractanimation.h:45,
                 from /opt/Qt5.3.2/5.3/gcc_64/include/QtCore/QtCore:4,
                 from /opt/Qt5.3.2/5.3/gcc_64/include/QtConcurrent/QtConcurrentDepends:2,
                 from /opt/Qt5.3.2/5.3/gcc_64/include/QtConcurrent/QtConcurrent:3,
                 from /tmp/Quantum/src/logger/include/logworker.h:5,
                 from /tmp/Quantum/src/logger/include/logger.h:5,
                 from /tmp/Quantum/src/logger/tests/logger_test.cpp:5:
/opt/Qt5.3.2/5.3/gcc_64/include/QtCore/qlist.h: In member function ‘void QList<T>::node_construct(QList<T>::Node*, const T&)’:
/opt/Qt5.3.2/5.3/gcc_64/include/QtCore/qlist.h:374:44: error: ‘n’ does not name a type
     else if (QTypeInfo<T>::isComplex) new (n) T(t);
                                            ^

The error looks like the <new> header hasn't been included. 该错误似乎未包含<new>标头。 Check that there isn't another file called "new" somewhere in the include paths, and check that no other headers define a macro like _NEW or _LIBCPP_NEW which would prevent <new> from being included correctly. 检查包含路径中某处是否没有另一个名为“ new”的文件,并检查是否没有其他标头定义_NEW_LIBCPP_NEW类的宏,以防止<new>被正确包含。

You might need to compile one of the failing files with a flag such as -save-temps so you can examine the preprocessed output, to see which files are being included, and if their content is being included. 您可能需要使用-save-temps类的标志编译失败的文件之一,以便可以检查预处理的输出,查看包含了哪些文件以及是否包含了它们的内容。

You should also tell CMake to be verbose, so it prints the full compiler commands. 您还应该告诉CMake冗长,以便它打印完整的编译器命令。 It's useless to hide the details of the compilation if the compilation is failing - you need to know what's happening! 如果编译失败,则隐藏编译的细节是没有用的-您需要知道发生了什么!

Finally we beat that problem. 最后,我们解决了这个问题。 The issue here was, as suggest @Jonathan Wakely, that cpputest defines macro _NEW which prevent new from being included correctly. 这里的问题是,作为建议@Jonathan Wakely,即cpputest定义宏_NEW其防止new被正确地包括在内。 To resolve the issue we reorder the includes to include all libs before including cpputest headers. 为了解决该问题,我们在对cpputest标头进行包含之前,将includes重新排序为包括所有库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM