简体   繁体   中英

C++ files stopped compiling - keep getting error: linker command failed with exit code 1 (use -v to see invocation)

I've had no problems compiling in the past, and code that I wrote previously is compiling fine, but it is now giving this error when I try to compile a very simple C++ file using Visual Studio Code on my M1 Mac:

Code:

#include<iostream>
using namespace std;

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

The terminal commands I've tried (all give same error):

g++ -std=c++14 test.cpp -o test
g++ -std=c++11 test.cpp -o test
g++ test.cpp -o test

Error:

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)

I've tried to delete and re-create the file with different names, restarting VSC, using different output file names and nothing changes this.

This was occurring as I hadn't saved the file prior to compiling and therefore the compiler couldn't find it.

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