【问题标题】:Errors when attempting to run c++ program compiled in Netbeans尝试运行在 Netbeans 中编译的 C++ 程序时出错
【发布时间】:2012-08-20 12:35:35
【问题描述】:

在过去的几个小时里,我一直在尝试为我在 Netbeans 中开发的 C++ 应用程序设置一个 cronjob。我在 Windows 机器上编程并使用 Ubuntu 服务器作为构建主机。它进行了设置,因此将文件放入分发文件夹中,我假设这是我必须执行的文件。我使用以下命令行执行它:

g++ program

之后它会弹出以下错误:

testproject: In function `_start':
(.text+0x0): multiple definition of `_start'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o:(.text+0x0):
first defined here
testproject: In function `_fini':
(.fini+0x0): multiple definition of `_fini'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crti.o:(.fini+0x0):
first defined here
testproject:(.rodata+0x0): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o:(.rodata.cst4
+0x0): first defined here
testproject: In function `__data_start':
(.data+0x0): multiple definition of `__data_start'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o:(.data+0x0):
first defined here
testproject: In function `__data_start':
(.data+0x8): multiple definition of `__dso_handle'
/usr/lib/gcc/x86_64-linux-gnu/4.6/crtbegin.o:(.data+0x0): first defined here
testproject: In function `_init':
(.init+0x0): multiple definition of `_init'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crti.o:(.init+0x0):
first defined here
/usr/lib/gcc/x86_64-linux-gnu/4.6/crtend.o:(.dtors+0x0): multiple definition of
`__DTOR_END__'
testproject:(.dtors+0x8): first defined here
/usr/bin/ld: error in testproject(.eh_frame); no .eh_frame_hdr table will be cre
ated.
collect2: ld returned 1 exit status

但是,当我在 Netbeans 中单击运行时,它运行得很好。我需要运行哪个命令才能使其正常工作?

【问题讨论】:

  • g++ 不用于运行程序,仅用于编译。编译完成后,只需将其作为 program(或者可能是 ./program)运行即可。
  • 太棒了。那行得通。我需要 ./ 你能把它作为答案发布吗?

标签: c++ netbeans


【解决方案1】:

g++ 是一个compiler。它将您的源代码变成您可以直接运行的程序。这与 Java 不同,Java 运行在一个名为 virtual machine 的单独程序上。

所以对于你编写的C++ 程序,你会这样做

g++ my_source.cpp -o my_program
./my_program

第一行将你的代码编译成一个可运行的程序(这一步通常比较复杂,有多个源文件和单独的程序来管理构建过程,例如make)。您只需执行一次此步骤(如果您更改程序,则再次执行)。如果您使用 IDE(例如 NetBeans),这部分可能对您隐藏。

第二行运行新程序(假设第一步一切顺利)。 ./ 仅表示“在此目录中运行它”(没有它,您的系统将关闭并在几个特定位置查找程序)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多