Hi All,
I want to compile a C prog which doesn't have a main() function call. How should i go abt it.
Regards
Satish.
Example prog:
=============
#include <stdio.h>
void print()
{
printf ("\nHello World\n");
}
Hi All,
I want to compile a C prog which doesn't have a main() function call. How should i go abt it.
Regards
Satish.
Example prog:
=============
#include <stdio.h>
void print()
{
printf ("\nHello World\n");
}
Hi
So you like to write a library, not a executable program.
to do that you should reffer to your OS documentation.
there is a way to specify which will be the entry point in your executable file but it differs from OS to OS and it is not so easy.
And also there will be a lot of additional efforts to get access to the resources that yout OS manage.
damyan
Dear Satish_Ram,
Please let us know which operating systema nd which complier you are using. If you using Unix and standard compiler, you can create library file with : cc -c <progname>.c
This will create <progname>.o file, which will be used as library while linking.
Regards,
Mangesh.
No Issues. Just go ahead and compile. It will compile all right. The compiler DOES NOT check the presence of the function 'main'.
However, it will not link. The linker checks the existance of main.
Hello friends,
I am using HP-UX . I wanted to know how to create an executable from a C prog which doen't have a main() .
main.c
------
#include <stdio.h>
print()
{
printf ("\nHello World\n");
}
---------------------------------
cc -c main.c
ld -e print /opt/langtools/lib/crt0.o main.o -lm -lc
here -e specifies the entry point ... as from the man pages of ld ..
i am getting a.out , but on running it i am getting a core dump at printf() function call ...
My doubt is can we write a C prog without main() and create an executable from it . And also what exactly the option -e in ld does.
Thanx in Advance,
Satish.
Hi!
The entry point of a C program may be main() from the viewpoint of the programmer, but from the viewpoint of the OS, the entrypoint is somewhere in the code of crt0.o. After some setup procedures (io initialization, memory allocation structures, signal handlers, whatever...), crt0 calls the main function in your program.
So you are telling the linker that your program should skip any initialisation and just start your entry function... From there you call printf which tries to write into a buffer that has not been allocated. There you are: segfault.
greetinx,
alex