TomSawyer TomSawyer - 2 months ago 68
C++ Question

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?

Answer

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.

Comments