首页 > 解决方案 > 尝试使用 g++ 编译 .c 文件时链接器命令失败

问题描述

刚刚发布了一个简单的 c 代码并收到此错误消息。谁能解释问题出在哪里?

ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
mac@MACs-MacBook-Pro-2 C % cd "/Users/mac/C/" && g++ tes.c++ -o tes && "/Users/mac/C/"tes
Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable

标签: c

解决方案


你必须用 gcc 而不是 g++ 编译,g++ 是编译 .cpp 或 .cc 文件

gcc tes.c++ -o tes

推荐阅读