简体   繁体   中英

Getting error clang: error: linker command failed with exit code 1 (use -v to see invocation) while compile C++ file from terminal

I'm getting this error

clang: error: linker command failed with exit code 1 (use -v to see invocation)

while i'm compiling simple cpp file from terminal

gcc hello.cpp

here's the content of hello.cpp file:

#include <iostream>
using namespace std;

// main() is where program execution begins.

int main()
{
   cout << "Hello World"; // prints Hello World
   return 0;
}

I think it might conflict with XCode compiler?

gcc hello.cpp should be g++ hello.cpp

gcc is for compiling and linking C code, while g++ is used for C++ code as you have it.

I think it might conflict with XCode compiler?

No. The point is that the gcc command is also able to compile C++ code detected from the .cpp file extension, though the libstdc++.a won't be linked automatically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM