1

I am doing my uni course by following the inscructions for Mac that were given on the uni website.

This is what we are supposed to write:

#include <stdio.h>

int main(void) {

    printf("C is cool!!!");

    return 0;

}

This is what shows up in the console:

make all 
Building target: SimpleProj
Invoking: MacOS X C Linker
gcc  -o "SimpleProj"  ./src/MyProg.o   
Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [SimpleProj] Error 1

16:51:54 Build Failed. 2 errors, 0 warnings. (took 129ms)

I have Eclipse CDT installed with a proper Java 10.

The sample "Hello World" program ran normally when I tried it. But now I ran into this.

Tried searching for similar issues online but those were different from mine. If you know any idea on how I would proceed, any tips are welcome.

howlger
  • 31,050
  • 11
  • 59
  • 99
  • Don't use Eclipse (it usually is confusing). Compile on the command line after using a simple [source code editor](https://en.wikipedia.org/wiki/Source_code_editor) (I recommend [emacs](https://www.gnu.org/software/emacs), but you could use others). Show the compilation command of the source file containing `main` (perhaps some `MyProg.c` file). Maybe you should use something like `gcc -Wall -g -c MyProg.c` in the appropriate directory. BTW, for simple programs, it usually is not worth having some `src/` subdirectory. You probably want to terminate each `printf` format string with a `\n` – Basile Starynkevitch Aug 18 '18 at 13:22
  • Interesting input that I will check out and will be useful for other users, cheers. My problem is solved. – Mark Horowitz Aug 18 '18 at 13:45
  • Could you clarify, for the benefit of future readers, how your problem was solved? Thanks! – HighCommander4 Aug 24 '18 at 18:21
  • Absolutely. Essentially you just need to save before you compile and run the program. And you should also: right click -> "run as" -> "local c container" as opposed to just clicking the green arrow. – Mark Horowitz Aug 26 '18 at 11:47
  • Restart the program (Eclipse) if an error shows up. If I recall this was also part of the solution. – Mark Horowitz Aug 26 '18 at 11:55

0 Answers0