Linux 在普通C++;项目

Linux 在普通C++;项目,linux,qt,qt4,Linux,Qt,Qt4,好吧,标题几乎说明了一切。我启动Qt Creator,我创建一个新项目,然后点击普通C++选项。它在main.cpp文件中创建以下代码: #include <iostream> using namespace std; int main() { cout << "Hello World!" << endl; return 0; } 应用程序输出: 调试开始 调试已完成 尽管这已经有几天了,我还是想添加这个解决方案,因为所描述的问题偶尔会发

好吧,标题几乎说明了一切。我启动Qt Creator,我创建一个新项目,然后点击普通C++选项。它在main.cpp文件中创建以下代码:

#include <iostream>

using namespace std;

int main()
{
    cout << "Hello World!" << endl;
    return 0;
}
应用程序输出:

调试开始 调试已完成


尽管这已经有几天了,我还是想添加这个解决方案,因为所描述的问题偶尔会发生在Qt和Creator上:Qt Creator有一个讨厌的习惯,建议将发行版和调试对象放在同一个文件夹中。因此,如果您编译一个发布版本,然后决定调试您的程序并进行调试版本,它将把调试应用程序与发布对象链接起来。
这些对象不能在中设置断点。您需要完全清理项目,在调试模式下调用qmake和makeall。然后您应该能够正确设置断点。

您可以简单地给cmake命令cmake-DCMAKE\u BUILD\u TYPE=Debug


设置(CMAKE\u BUILD\u TYPE Debug)将此行添加到CMakeLists.txt并立即调试。断点将被正确命中。

无法在Ubuntu x64上复制,断点与此代码配合良好…它是否打印出“Hello World!”?据我所知,它没有。也许你在realase模式下运行程序而不是调试?我肯定没有。在左边的绿色三角形上方,我选择了调试。我想这就是我所需要做的。
23:27:37: Running build steps for project untitled2...
23:27:37: Starting: "/usr/bin/qmake-qt4" '/home/jean-luc/Desktop/untitled folder/untitled2/untitled2.pro' -r -spec linux-g++ CONFIG+=debug CONFIG+=declarative_debug
23:27:37: The process "/usr/bin/qmake-qt4" exited normally.
23:27:37: Starting: "/usr/bin/make" -w
make: Entering directory `/home/jean-luc/Desktop/untitled folder/untitled2-build-desktop-Qt_4_8_1_in_PATH__System__Debug'
g++ -c -pipe -g -Wall -W -DQT_WEBKIT -I/usr/share/qt4/mkspecs/linux-g++ -I../untitled2 -I../untitled2 -I. -o main.o ../untitled2/main.cpp
g++  -o untitled2 main.o      
{ test -n "" && DESTDIR="" || DESTDIR=.; } && test $(gdb --version | sed -e 's,[^0-9]\+\([0-9]\)\.\([0-9]\).*,\1\2,;q') -gt 72 && gdb --nx --batch --quiet -ex 'set confirm off' -ex "save gdb-index $DESTDIR" -ex quit 'untitled2' && test -f untitled2.gdb-index && objcopy --add-section '.gdb_index=untitled2.gdb-index' --set-section-flags '.gdb_index=readonly' 'untitled2' 'untitled2' && rm -f untitled2.gdb-index || true
make: Leaving directory `/home/jean-luc/Desktop/untitled folder/untitled2-build-desktop-Qt_4_8_1_in_PATH__System__Debug'
23:27:38: The process "/usr/bin/make" exited normally.