PDA

View Full Version : How to compile a C/C++ program



Dark Sorrow
November 20th, 2009, 09:12 AM
I have written a simple C Hello World program using a Code::Block 8.2 IDE which i have downloaded. When ever I build my file i get Nothing to Build message in my Build Log Tab.
When i run then i get the following error message.

sh: /home/ishaankarnik/HelloWorld: Permission denied

Press Enter to continue.

Arndt
November 20th, 2009, 10:12 AM
I have written a simple C Hello World program using a Code::Block 8.2 IDE which i have downloaded. When ever I build my file i get Nothing to Build message in my Build Log Tab.
When i run then i get the following error message.

I don't know how your IDE works, but it seems there is a program HelloWorld which isn't executable. That may be because there were errors during an earlier compilation/linking and the resulting file wasn't removed.

Use a shell to see if this is the case. If so, remove the file and try again.

Dark Sorrow
November 20th, 2009, 05:18 PM
I have downloaded and installed several C/C++ IDE like Code::Block, Anjuta IDE and KDevelop from Add/Remove program.
I have written a simple hello world program but i am unable to compile it.
In Code::Block IDE the problem i face after i build or run is explained in the following thread.
http://ubuntuforums.org/showthread.php?p=8352802#post8352802.
In Anjuta IDE their is no effect after i execute program.
I even tried to compile using the terminal by giving the complier name gc/gc++ and then the absolute path of my file.
The files i created using IDE are C source code(text/x-csrc).

Slimbo
November 20th, 2009, 06:37 PM
Is build-essential installed ?

Can+~
November 20th, 2009, 07:09 PM
I even tried to compile using the terminal by giving the complier name gc/gc++ and then the absolute path of my file.

What was the output of this one?

cariboo
November 20th, 2009, 07:36 PM
Please don't double post on the same subject, I have merged your two threads.

Dark Sorrow
November 21st, 2009, 03:39 AM
What was the output of this one?

(1)For the files i created using IDE i get the following error

File Format not recognized
collect2: ld returned 1 exit status. However the file type shown in property window is C source code (text/x-csrc).
(2)For the files i created using gEdit i get the following error

/tmp/ccKgLpYn.o:(.en_frame+0x11): undefined reference to '__gxx_personality_v0
collect2: ld returned 1 exit status.
Here the file type is C++ source code(text/x-c++src).

Dark Sorrow
November 21st, 2009, 03:42 AM
Is build-essential installed ?

How do i find if build-essential is installed? If not installed then how should i install.

dwhitney67
November 21st, 2009, 03:59 AM
/tmp/ccKgLpYn.o.en_frame+0x11): undefined reference to '__gxx_personality_v0
collect2: ld returned 1 exit status.
Here the file type is C++ source code(text/x-c++src).

I bet you are using 'gcc' to compile a C++ source module. Use 'g++' instead, or alternatively link with the stdc++ library.

Option 1:


g++ module.cpp


Option 2 (which is not often used):


gcc module.cpp -lstdc++


P.S. To install build-essential:


sudo apt-get install build-essential

This instruction is CLEARLY indicated in the stickies.

Dark Sorrow
November 21st, 2009, 04:20 AM
I bet you are using 'gcc' to compile a C++ source module. Use 'g++' instead, or alternatively link with the stdc++ library.

Option 1:


g++ module.cpp


Option 2 (which is not often used):


gcc module.cpp -lstdc++


P.S. To install build-essential:


sudo apt-get install build-essential

This instruction is CLEARLY indicated in the stickies.

But what about the first case where the file is of type Csource code (text/x-csrc). It should atleast work with gcc normally.

dwhitney67
November 21st, 2009, 12:21 PM
But what about the first case where the file is of type Csource code (text/x-csrc). It should atleast work with gcc normally.
Yes, and it also works with 'g++'. The convention, however, is to use 'gcc' with C code, 'g++' with C++.