c++ 配置netbeans 8.0 gdb以使用gradle cpp插件

eimct9ow  于 2022-12-20  发布在  其他
关注(0)|答案(2)|浏览(108)

最近,我从Windows 7中的Visual Studio切换到了带有NetBeans 8.0(C++)的Ubuntu。从那时起,我在从NetBeans调试应用程序时遇到了很大的问题(gdb工作得很好)。我用gradle编写了hello world c++来演示我的问题。我花了很多时间,但没有取得任何重大进展。

Gradle项目

构建版本分级

apply plugin: 'cpp'

executables {
    helloWorld
}
binaries.all {
     cppCompiler.args "-g"
}

main.cpp:

#include <stdio.h>
#include <stdlib.h>

int main(void) {
    int a = 10;
    int b = 12;
    int c = a + b;
    puts("Hello World!!!");
    return EXIT_SUCCESS;
}

然后我构建并运行gdb

robert-Aspire-S3:~/NetBeansProjects/helloWorld$ gradle helloWorldExecutable
robert-Aspire-S3:~/NetBeansProjects/helloWorld$ gdb ./build/binaries/helloWorldExecutable/helloWorld                     
....
Reading symbols from ./build/binaries/helloWorldExecutable/helloWorld...done.
(gdb) b 5
Breakpoint 1, main () at /home/robert/NetBeansProjects/helloWorld/src/helloWorld/cpp/main.cpp:5
5           int a = 10;
(gdb) n                                                                                                                         
6           int b = 12;
(gdb) print a
$1 = 10
(gdb) n
7           int c = a + b;
(gdb) c
Continuing.
Hello World!!!
[Inferior 1 (process 3693) exited normally]

下一步是从NetBeans 8.0附加到gdb进程。我还在第5行中放置了NetBeans中的断点,希望可以获得gdb输出。x1c 0d1x

遗憾的是,Netbeans在编辑器区域没有遇到断点,我不知道为什么。我也打开了Debbuger Console,并粘贴了logs (pastebin)以获取更多信息。

C++应用程序

当我从NetBeans向导创建标准的C/C++应用程序并尝试调试时,一切都运行良好。

对于该会话,我还使用了upload logs
我发现日志中有一处不同:

  • 梯度cpp:10-file-symbol-file "/usr/bin/gdb"
  • NetBeans cpp:10-file-exec-and-symbols "/home/robert/NetBeansProjects/CppApplication_1/dist/Debug/GNU-Linux-x86/cppapplication_1"

这是Gradle的一行代码的问题吗?如果是,我该如何修复它?有人能帮我将NetBeans可视化调试器附加到Gradle cpp项目吗?谢谢帮助。

cngwdvgl

cngwdvgl1#

我认为问题出在build.gradle中,所以您必须检查gradle程序中使用的语法。http://gradle.org/getting-started-native/本网站包含一些示例。请阅读并修复您的问题。

ia2d9nvy

ia2d9nvy2#

您在使用NetBeans和Gradle调试C应用程序时遇到的问题似乎与GDB正在使用的符号文件有关。在Gradle C项目的日志中,GDB正在使用符号文件“/usr/bin/gdb”,而在NetBeans C项目的日志中,GDB正在使用符号文件“/home/robert/NetBeansProjects/cpp应用程序1/dist/调试/GNU-Linux-x86/cpp应用程序1”。
要解决此问题,您可能需要为GDB指定正确的符号文件,以便在Gradle C
项目中使用。您可以通过向build.gradle文件添加以下行来实现此目的:
gdb命令行=“gdb -符号/路径/目标/符号/文件”
将“/path/to/symbol/file”替换为项目符号文件的正确路径,这样可以让GDB使用正确的符号文件,让NetBeans正确地附加到GDB进程并在编辑器中命中断点。

相关问题