1832990 Members
2344 Online
110048 Solutions
New Discussion

Re: C compiling in UX

 
Henry Chua
Super Advisor

C compiling in UX

Hi Guys,

I have this really fundamental question.. how to u compile a C source code in UX?

e.g. source code "test.c"

#inclde

void main(){

printf("hello world");

}

I try compiling "cc test.c"

but it keep givin me

/usr/ccs/bin/ld: Unexpected end of file in test.c

wats wrong?
18 REPLIES 18
Biswajit Tripathy
Honored Contributor

Re: C compiling in UX

Change

> #inclde
> void main(){
> printf("hello world");
> }

to

#include
int main ()
{
printf ("hello world");
return 0;
}

The real error in you code is the first line (#include).

- Biswajit
:-)
Muthukumar_5
Honored Contributor

Re: C compiling in UX

Inclusion of header file must be as,

#include

#include
void main(){

printf("hello world");

}

Compile as,

cc -v test.c

It will give more informations.

HTH.
Easy to suggest when don't know about the problem!
Biswajit Tripathy
Honored Contributor

Re: C compiling in UX

One nitpick.
It's bad programming practice to use
void main().

In C, main() is designed to return int, so
int main() is what you should be using.

- Biswajit
:-)
Henry Chua
Super Advisor

Re: C compiling in UX

Been trying to compile this source code but keep getting errors returned.. what have I done wrong?

"
#include
#include
#include
#include
#include

main() {
char fn[]="try.txt";
struct stat info;
int file_descriptor;

if ((file_descriptor = creat(fn, S_IWUSR)) < 0)
perror("creat() error");
else {
if (fstat(file_descriptor, &info) != 0)
perror("fstat() error");
else {
puts("fstat() returned:");
printf(" inode: %d\n", (int) info.st_ino);
printf(" dev id: %d\n", (int) info.st_dev);
printf(" mode: %08x\n", info.st_mode);
printf(" links: %d\n", info.st_nlink);
printf(" uid: %d\n", (int) info.st_uid);
printf(" gid: %d\n", (int) info.st_gid);
}
close(file_descriptor);
unlink(fn);
}
}

"
Biswajit Tripathy
Honored Contributor

Re: C compiling in UX

Post the compiler error message.
- Biswajit
:-)
Biswajit Tripathy
Honored Contributor

Re: C compiling in UX

I just cut-n-paste your code and it compiled and
ran fine on my HP-UX 11.11 system. What exactly
is the problem you are seeing?

- Biswajit
:-)
VEL_1
Valued Contributor

Re: C compiling in UX



At the end of C file, give one new line. hope It will solve your problem
VEL_1
Valued Contributor

Re: C compiling in UX


In Editor, at the end of C file, give one new line(ENTER) . hope It will solve your problem
Biswajit Tripathy
Honored Contributor

Re: C compiling in UX

tech123,
C compilers don't usually care anout an extra line at
the end of C file.

- Biswajit
:-)
Henry Chua
Super Advisor

Re: C compiling in UX

Hi Guys, I am using HPUX10.20b, when I compile this code "cc test.c" it return me:
"cc: "test.c", line 8: error 1716: Automatic aggregate initialization is an ANSI feature."

so I decided to do it this way "cc -Aa test.c"

it then gives me: "
cc: "test.c", line 9: error 1574: Unknown size for "info".
cc: "test.c", line 12: error 1588: "S_IWUSR" undefined.
cc: "test.c", line 19: error 1530: Undefined struct or union.
cc: "test.c", line 19: error 1527: Incompatible types in cast: Must cast from scalar to scalar or to void type.
cc: "test.c", line 20: error 1530: Undefined struct or union.
cc: "test.c", line 20: error 1527: Incompatible types in cast: Must cast from scalar to scalar or to void type.
cc: "test.c", line 21: error 1530: Undefined struct or union.
cc: "test.c", line 21: warning 563: Argument #2 is not the correct type.
cc: "test.c", line 22: error 1530: Undefined struct or union.
cc: "test.c", line 22: warning 563: Argument #2 is not the correct type.
cc: "test.c", line 23: error 1530: Undefined struct or union.
cc: "test.c", line 23: error 1527: Incompatible types in cast: Must cast from scalar to scalar or to void type.
cc: "test.c", line 24: error 1530: Undefined struct or union.
cc: "test.c", line 24: error 1527: Incompatible types in cast: Must cast from scalar to scalar or to void type.

"



Peter Godron
Honored Contributor

Re: C compiling in UX

Henry,
if you are going to use C more often it may be worthwhile getting the proper C compiler.
Either buy the HP product or use free gcc.
The compiler with the OS is normally only used for kernel compiles, so may not have full functionality.
Regards
Henry Chua
Super Advisor

Re: C compiling in UX

Hi Peter,
if this the case, can u advise me where I should go to download the gcc for my hpux10.20b . What should I do to install it?
Peter Godron
Honored Contributor

Re: C compiling in UX

Hendry,
have a look at :
https://www.beepz.com/personal/merijn/#Downloads
Regards
Biswajit Tripathy
Honored Contributor

Re: C compiling in UX

Henry,
I tried to compile your code on a 11.11 system that
does not have a ANSI C compiler and I did get the
error you are getting ("Automatic aggregate
initialization is an ANSI feature"). The native C
compiler seems to have a problem with the line

char fn[]="try.txt";

Changing the above line to the following fixed the
problem and the program compiled fine without
ANSI compiler and ran fine.

char *fn = "try.txt;

- Biswajit
:-)
Henry Chua
Super Advisor

Re: C compiling in UX

Hi Pewter & Biswajit,

Thanks for the feedback, I am trying to install the GNU C compiler now.. but as for the latter, do you see the other errors I have after fixing the first problem? thank u


Best regards
Henry


Biswajit Tripathy
Honored Contributor

Re: C compiling in UX

Henry wrote:
> do you see the other errors I have after fixing the
> first problem? thank u

Though I did not see the other errors, I think all of
them have one source, the compiler does not know
about the struct stat. As this is defined in
sys/stat.h, my guess is that the header is not
included correctly in your code. Make sure that the
line
#include
in your code starts from the first column of the line
(i.e no spaces before # character).

- Biswajit

:-)
Peter Godron
Honored Contributor

Re: C compiling in UX

Henry,
looking at your new thread postings, I guess you managed to get a copy of the 10.20 gcc code and have installed it.

Can you please assign points to answers and close the thread.

Happy coding!

Regards
Henry Chua
Super Advisor

Re: C compiling in UX

Have used an alternate system with better compiler.. will be installing the GCC as guided soon. THanks guys!