Home >Backend Development >C++ >Why Does 'cc' Fail to Compile C Code on OS X Lion, and How Can I Fix It?

Why Does 'cc' Fail to Compile C Code on OS X Lion, and How Can I Fix It?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-12-25 18:09:19863browse

Why Does

Error when Compiling Simple C Code on OS X Lion

When attempting to compile C code using "cc" on OS X Lion, an error may occur, resulting in undefined symbols for architecture x86_64. This error typically indicates that the linker is not using the C libraries during the compilation.

Solution

To resolve this issue, use the C compiler "g " or "clang " instead of "cc". These compilers understand and compile C code, and they include the necessary C libraries in the linking process.

Example

Replace the compilation command:

cc main.cpp

with:

g++ main.cpp

or:

clang++ main.cpp

Explanation

Using "cc" (the C compiler) without specifying options to use the C standard libraries can lead to errors during linking. The C compilers "g " and "clang " are specifically designed to handle C code and automatically include the required libraries.

By using "g " or "clang ", the compiler invocation involves the C link line that includes libstdc and other necessary libraries, resolving the undefined symbols error.

The above is the detailed content of Why Does 'cc' Fail to Compile C Code on OS X Lion, and How Can I Fix It?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn