Question:
can execute c program in Linux but compiled?
vijayan
2011-08-17 14:28:34 UTC
hi I'm using Ubuntu 11.04 natty narwhal(32 bit) as my operating system and the hardware configuration displayed on system monitor is
memory:3.2 gb
processor:core i5 cpu 650@3.20ghz
but actual hardware configuration of my ram is 8gb ddr3 1.3 ghz but due to using 32bit os it restricted upto 4gb of ram only coming to the real part
when i type the following program
************************************************
/*Name:pun*/
/*Purpose:prints a bad pun*/
/*Author:vijayan*/
#include
int main(void)
{
printf("To c,or not to c: that is the question.\n");
return 0;
}
************************************************************

then i open the terminal using x-terminal-emulator command and go to the path
and compile the program in many ways. even in the following sort of way as mentioned below
********************************************************************************
gcc -m32 -o pun pun.c
*******************************************************************************
it replies that
*********************************************************************************
/usr/bin/ld: unrecognised emulation mode: 32
Supported emulations: elf_i386 i386linux elf_x86_64 elf_l1om
collect2: ld returned 1 exit status
**********************************************************************************
then i tried like this also fails
*********************************************************************************
gcc -o -melf_i386 pun.c
*************************************************************************************
then i try to execute (note:compilation is successful but execution is failure)
using ./pun
it say permission denied
i think its a problem due to 64bit or 32 bit architecture.

********************
* *
*need a solution:*
* *
********************
i can compile c program but while i execute it show
************************************************
bash: ./pun: Permission denied
***************************************************
Four answers:
McFate
2011-08-17 14:50:13 UTC
Try:



chmod 755 pun



before executing it.
Stoill
2011-08-19 08:35:19 UTC
No chmod is needed. The output file of Gnu C Compiler (gcc) is always chmodded +x. You did not compile correctly with the chosen flags or you don't know that by default the compiled result filename is always "a.out". Try executing very simple compile and run. Here is the output with my Slackware:



[stoill] ~ > cat >> pun.c

/*Name:pun*/

/*Purpose:prints a bad pun*/

/*Author:vijayan*/

#include

int main(void)

{

printf("To c,or not to c: that is the question.\n");

return 0;

}

[stoill] ~ > gcc pun.c

[stoill] ~ > ./a.out

To c,or not to c: that is the question.

[stoill] ~ >



... And guys ... C is crafted for Unix. Everything C is working BEST in Unix/Linux. printf function too.
Blackcompe
2011-08-17 22:39:54 UTC
Yes, you need to set the permissions, because it's owned by the root. If you run gcc in a user directory or run gcc as the root with 'sudo,' you won't get that message when you try to run pun.
Apurv Appy
2011-08-18 04:29:06 UTC
i think there is problem in printf() function i think we cannot use printf in linux....


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...