In a C/C++ program the main()
function provides the entry point for program startup. (there are some specialized .ctor
functions called before main()
that you will rarely, if ever, encounter)
So what you have above declares the function dummyfunction();
but there is no main()
function that the linker ld
can use as the entry point (the address where program control is passed from the shell to your program to start running)
Your error messages is quite explicit about the lack of main()
being the problem. To correct the error you need to define the main()
function, where the correct invocations are either int main (void)
or int main (int argc, char *argv[])
(you will see char *argv[]
written equivalently as char **argv
). There is also an env
variable, but that isn't important here. If your program takes no arguments on the command line, then int main (void)
is proper. With C++ the void
can be omitted as it only makes a difference for C.
Including main()
, your program will compile with:
#include <iostream>
void dummyfunction(void)
{
std::cout << "this is\n";
}
int main ()
{
dummyfunction();
}
(note: the addition of the '\n'
at the end of "this is\n"
so the output of your program terminates with a newline as specified by POSIX)
Example Use/Output
I just named to program executable dummyfunction
, but you are free to name it anything you like.
$ ./dummyfunction
this is