I am trying out some code on Ubuntu. I\'m trying to run the following code
#include
#include
Interestingly, I get the same error if I try to compile a .h
file instead of a .c
file, and link against a library, all in one step.
Here is a greatly reduced example:
$ echo 'int main () {}' > test.h
$ g++ test.h -ltommath && echo success
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
In this case, the solution is to rename the file to end with .c
:
$ echo 'int main () {}' > test.c
$ g++ test.c -ltommath && echo success
success