Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Treating 'c' input as 'c++' when in C++ mode

Tags:

c

g++

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)
like image 403
M. Khromov Avatar asked Oct 20 '25 20:10

M. Khromov


2 Answers

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.

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.

like image 40
Milind Deore Avatar answered Oct 23 '25 11:10

Milind Deore