microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.51k stars 1.55k forks source link

m1 mac cpp compile error #11597

Open Edenzzzz opened 1 year ago

Edenzzzz commented 1 year ago

The libraries are not properly linked and the run button is missing from top right. I also don't understand why I have to use clang instead of g++. The tutorial(https://code.visualstudio.com/docs/cpp/config-clang-mac) is not working.

image

Starting build... /usr/bin/clang -std=gnu++14 -fcolor-diagnostics -fansi-escape-codes -g "/Users/tanwenxuan/Projects/c++ test/test.cpp" -o "/Users/tanwenxuan/Projects/c++ test/test" Undefined symbols for architecture arm64: "std::__1::locale::use_facet(std::__1::locale::id&) const", referenced from: std::__1::ctype<char> const& std::__1::use_facet[abi:v15006]<std::__1::ctype<char>>(std::__1::locale const&) in test-ce518c.o "std::__1::ios_base::getloc() const", referenced from: std::__1::basic_ios<char, std::__1::char_traits<char>>::widen[abi:v15006](char) const in test-ce518c.o "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::__init(unsigned long, char)", referenced from: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::basic_string[abi:v15006](unsigned long, char) in test-ce518c.o "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::~basic_string()", referenced from: std::__1::ostreambuf_iterator<char, std::__1::char_traits<char>> std::__1::__pad_and_output<char, std::__1::char_traits<char>>(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char>>, char const*, char const*, char const*, std::__1::ios_base&, char) in test-ce518c.o "std::__1::basic_ostream<char, std::__1::char_traits<char>>::put(char)", referenced from: std::__1::basic_ostream<char, std::__1::char_traits<char>>& std::__1::endl<char, std::__1::char_traits<char>>(std::__1::basic_ostream<char, std::__1::char_traits<char>>&) in test-ce518c.o "std::__1::basic_ostream<char, std::__1::char_traits<char>>::flush()", referenced from: std::__1::basic_ostream<char, std::__1::char_traits<char>>& std::__1::endl<char, std::__1::char_traits<char>>(std::__1::basic_ostream<char, std::__1::char_traits<char>>&) in test-ce518c.o "std::__1::basic_ostream<char, std::__1::char_traits<char>>::sentry::sentry(std::__1::basic_ostream<char, std::__1::char_traits<char>>&)", referenced from: std::__1::basic_ostream<char, std::__1::char_traits<char>>& std::__1::__put_character_sequence<char, std::__1::char_traits<char>>(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, char const*, unsigned long) in test-ce518c.o "std::__1::basic_ostream<char, std::__1::char_traits<char>>::sentry::~sentry()", referenced from: std::__1::basic_ostream<char, std::__1::char_traits<char>>& std::__1::__put_character_sequence<char, std::__1::char_traits<char>>(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, char const*, unsigned long) in test-ce518c.o "std::__1::cout", referenced from: _main in test-ce518c.o "std::__1::ctype<char>::id", referenced from: std::__1::ctype<char> const& std::__1::use_facet[abi:v15006]<std::__1::ctype<char>>(std::__1::locale const&) in test-ce518c.o "std::__1::locale::~locale()", referenced from: std::__1::basic_ios<char, std::__1::char_traits<char>>::widen[abi:v15006](char) const in test-ce518c.o "std::__1::ios_base::__set_badbit_and_consider_rethrow()", referenced from: std::__1::basic_ostream<char, std::__1::char_traits<char>>& std::__1::__put_character_sequence<char, std::__1::char_traits<char>>(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, char const*, unsigned long) in test-ce518c.o "std::__1::ios_base::clear(unsigned int)", referenced from: std::__1::ios_base::setstate[abi:v15006](unsigned int) in test-ce518c.o "std::terminate()", referenced from: ___clang_call_terminate in test-ce518c.o "___cxa_begin_catch", referenced from: std::__1::basic_ostream<char, std::__1::char_traits<char>>& std::__1::__put_character_sequence<char, std::__1::char_traits<char>>(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, char const*, unsigned long) in test-ce518c.o ___clang_call_terminate in test-ce518c.o "___cxa_end_catch", referenced from: std::__1::basic_ostream<char, std::__1::char_traits<char>>& std::__1::__put_character_sequence<char, std::__1::char_traits<char>>(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, char const*, unsigned long) in test-ce518c.o "___gxx_personality_v0", referenced from: std::__1::basic_ostream<char, std::__1::char_traits<char>>& std::__1::__put_character_sequence<char, std::__1::char_traits<char>>(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, char const*, unsigned long) in test-ce518c.o std::__1::ostreambuf_iterator<char, std::__1::char_traits<char>> std::__1::__pad_and_output<char, std::__1::char_traits<char>>(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char>>, char const*, char const*, char const*, std::__1::ios_base&, char) in test-ce518c.o std::__1::ostreambuf_iterator<char, std::__1::char_traits<char>>::ostreambuf_iterator[abi:v15006](std::__1::basic_ostream<char, std::__1::char_traits<char>>&) in test-ce518c.o std::__1::basic_ios<char, std::__1::char_traits<char>>::widen[abi:v15006](char) const in test-ce518c.o ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

AlexandraKemperMS commented 1 year ago

Hi @Edenzzzz, there are a couple of different topics here:

  1. The run button is missing from the top right The run button is only shown when the file is active. When you click on the file to make it active, does that show you the run button?
  2. The tutorial is not working / libraries are not properly linked Which version of the C/C++ Extension are you using? We recently fixed this issue in the newest stable version (1.17.2). You can check your version by navigating to the Extensions view on the left, then finding the C/C++ Extension. The version number is at the top of the page, next to the title. If you have a version before 1.17, please update by clicking the "sync" button to the right of the "disable" and "uninstall" buttons. This should fix the linking issue and the tutorial not working.
  3. Using clang instead of g++ While the tutorial walks you through installing clang, you can use any compiler you wish. You can switch the compiler you are using by opening the command prompt (⇧+⌘+P on mac) and using "C/C++: Select IntelliSense Configuration" command. This opens a quick pick that has a dropdown of all the compilers you have available on your machine. Simply select the one that will be the new default to compile.
Edenzzzz commented 1 year ago

Thanks for your detailed reply!

  1. I clicked on the cpp file but no button is shown.
  2. I confirmed that my extension version is 1.17.5, and switching to 1.17.2 doesn't help.
  3. It appears that I just need to use "gcc -lstdc++" to compile. However, I'm looking for a way to automatically do that using the run button.