4

sorry for my question, I get homework in my university, I need make a programm in C programming language, but when I start with on Mac OS (in school we use OpenSolaris I think) I got this problem, can I fix it without Unix installation?

Console output: (screenshot)

MBP-Maxim:cv01 maxim$ g++ main.c 

clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]

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)
Amessihel
  • 5,891
  • 3
  • 16
  • 40
M. Khromov
  • 113
  • 1
  • 2
  • 8
  • 1
    Invoke the C compiler instead of the C++ compiler. `g++` is the C++ compoiler – UnholySheep Oct 28 '18 at 19:50
  • 2
    Welcome to stackoverflow.com. Please take some time to read [the help pages](http://stackoverflow.com/help), especially the sections named ["What topics can I ask about here?"](http://stackoverflow.com/help/on-topic) and ["What types of questions should I avoid asking?"](http://stackoverflow.com/help/dont-ask). Also please [take the tour](http://stackoverflow.com/tour) and [read about how to ask good questions](http://stackoverflow.com/help/how-to-ask). Lastly please read [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). – Some programmer dude Oct 28 '18 at 19:52
  • 5
    Post your errors as text, not as an image. – Joseph Sible-Reinstate Monica Oct 28 '18 at 19:53
  • @JosephSible I have posted – M. Khromov Oct 28 '18 at 19:57
  • Possible duplicate of [Linking C from C++ in OS X Mavericks](https://stackoverflow.com/questions/19644816/linking-c-from-c-in-os-x-mavericks) – Joseph Sible-Reinstate Monica Oct 28 '18 at 19:57
  • @JosephSible yes thank you I solve problem with "treating 'c' input as 'c++' when in C++ mode", the second problem "Undefined symbols for architecture x86_64:" still exist... – M. Khromov Oct 28 '18 at 20:23

2 Answers2

8

You have two problems:

  1. g++ is a C++ compiler. Your source file is C, not C++. Use gcc to compile C source code.

  2. The file you are trying to compile doesn't have a main function, which is required to generate an executable. Write one.

1

Just to elaborate more on @duskwuff-inactive- reply

For warning like this clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]

Your file name is main.c instead of main.cpp or main.cc when compiling with g++ compiler or use gcc compiler for main.c.

Milind Deore
  • 2,887
  • 5
  • 25
  • 40