gpt4 book ai didi

c++ - 我无法在我的macOS 10.14中的任何地方编译.cpp文件,但无法编译IDE项目生成的目录(例如Xcode或CLion)

转载 作者:行者123 更新时间:2023-12-02 10:57:59 28 4
gpt4 key购买 nike

我只是尝试在不使用IDE的情况下编译C++代码,但是遇到了以下错误:

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)



我正在测试的只是一个简单的hello world程序:
#include <iostream>
using namespace std;

int main ()
{
cout << "Hello World! ";
cout << "I'm a C++ program";
}

g++和clang++都不会出现相同的错误。但是,可以在CLion生成的目录中成功完成编译。我想也许是因为IDE可以自行配置有关编译器的所有内容? C++编译器的任何路径设置是否存在问题?有人可以帮忙吗?非常感谢。

最佳答案

我想到了...
原来,我在Visual Studio Code中编译之前忘了保存.cpp文件...我应该打开自动保存功能。
真是个愚蠢的错误...

关于c++ - 我无法在我的macOS 10.14中的任何地方编译.cpp文件,但无法编译IDE项目生成的目录(例如Xcode或CLion),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55084537/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com