gcc gives error when called from c program gcc gives error when called from c program bash bash

gcc gives error when called from c program


Make sure your hello world program has a .c extension and not a .cpp (or similar) extension

gcc can compile C++ programs but it does not link in the C++ standard library, it links in the standard C library.

If your program is C++ your main function will be name mangled which will explain why the C library cannot find it.

If you want to compile C++ with the C++ standard library use g++.


You could try using the system function in C to call the bash script.

system("bash /path/to/compile.sh %s %u");

I use this very simple method often. Just make sure to use #include <stdlib.h> as well.

The error that you are getting is a Linker error. Usually it is caused by not defining int main() in C/C++ code you are trying to run. Though the hello world C code compiles and runs fine, your main C code may be missing the int main() function. Check to make sure the main program has the int main() function and if you still get the linker error, use the system call function which will send a command to the default shell interpreter on your linux box. In Ubuntu this is usually bash. If the shell script then runs while using a system call, then you know you had a mere syntax error causing your linker error.