Operating System - HP-UX
1834201 Members
2623 Online
110066 Solutions
New Discussion

Re: cannot execute c-program

 
SOLVED
Go to solution
Martin V.
Advisor

cannot execute c-program

hi,

i want to execute my c-program:

/* time.c */
#include
#include
int main() {
time_t gmt;
(void) time (&gmt);
printf("%d\n", gmt);
}

to print the system time in seconds since 1970-01-01, but it doesn't work. i still become the error message "cannont execute"! can someone help me, please?

thanks
13 REPLIES 13
Pete Randall
Outstanding Contributor

Re: cannot execute c-program

Does it have the execute bit set in it's permissions?


Pete

Pete
Martin V.
Advisor

Re: cannot execute c-program

hi pete,

yes the permissions set on 777 (-rwxrwxrwx)

martin
Peter Godron
Honored Contributor

Re: cannot execute c-program

Martin,
if the executable is called timer
ll timer
chmod 755 timer

To run:
./timer
MarkSyder
Honored Contributor

Re: cannot execute c-program

I've just tired it on my system and it worked. The only differences I made were:

#include (instead of stdlib.h)

and I omitted include

Mark Syder (like the drink but spelt different)
The triumph of evil requires only that good men do nothing
Martin V.
Advisor

Re: cannot execute c-program

hi peter,

the executable called time.out an i changed the permissons on 755 but it doesent work!

Error:

/sbin/sh: ./time.out: cannot execute

thanks

martin
James R. Ferguson
Acclaimed Contributor

Re: cannot execute c-program

Hi:

By default, the execute bit should be set for the object created by the compilation.

What are you running? Did you name the object or let it default to 'a.out' ?

Regards!

...JRF...
Peter Godron
Honored Contributor
Solution

Re: cannot execute c-program

Martin,
looks as if your are calling a shell ??
/sbin/sh whcih then calls the time.out
Can you run the time.out from the command line.

/usr/bin/sh
./time.out

also env | grep -i shell
Martin V.
Advisor

Re: cannot execute c-program

i'm running

gcc -g time.c -o time.out

Peter Godron
Honored Contributor

Re: cannot execute c-program

Hi,
although for Linux, please step through:
http://linuxhelp.blogspot.com/2006/04/steps-to-compile-c-c-programs-using.html

On my machine:
$ gcc -g time.c -o time.out
$ ./time.out
1164722127
$ ll time.out
-rwxr-xr-x 1 godronpw users 38912 Nov 28 13:55 time.out
A. Clay Stephenson
Acclaimed Contributor

Re: cannot execute c-program

My best guess is that you have somehow configured gcc to output another machines object code format. Do this:

file ./time.out

and

ls -l ./time.out.

and post the results.

That should indicate what is wrong.
If it ain't broke, I can fix that.
Martin V.
Advisor

Re: cannot execute c-program

hi,

the result is:

./time.out: ELF-32

thanks

martin


Martin V.
Advisor

Re: cannot execute c-program

hi,

i thank you for your help. i found the problem and no it work!!

thanks
Martin V.
Advisor

Re: cannot execute c-program

done