Errors when attempting to run c++ program compiled in Netbeans

I have for the last couple of hours been trying to set up a cronjob for a C++ application I developed in Netbeans. I am programming on a Windows machine and using a Ubuntu server as a build host. It sets it up so a file is put into a distribution folder and I assume that it's the one I have to execute. I execute it using the following command line:

g++ program

After that it pops up with the following errors:

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

However when I click run in Netbeans it runs just fine. Which command do I need to run in order to make this work correctly?

Answers


g++ is a compiler. It turns your source code into a program you can run directly. This is unlike Java, which runs on a separate program called a virtual machine.

So for a C++ program you have written, you would do

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

The first line compiles your code into a run-able program (this step is often more complicated, with multiple source files, and separate programs to manage the build process, such as make). You only have to do this step once (and again if you ever change the program). This part will probably be hidden from you if you use an IDE (such as NetBeans).

The second line runs the new program (assuming the first step all went well). The ./ just means "run it in this directory" (without it, your system would go off and look for the program in a few specific places).


Need Your Help

StreamSend API Blast, Sending Email

c# api httpwebrequest httpwebresponse

I need to use StreamSend API to send email, here is

AngularJS design patterns: Should I use factories to create constructor functions?

javascript design-patterns design angularjs

This is something I've been mulling over while creating an AngularJS app. When I first learned about AngularJS factories, I thought one clever usage of them would be to create and return a construc...