実現したいこと
Macで競プロ用(C++)のローカル環境を作りたい
VSCode使用
前提
https://qiita.com/dhirabayashi/items/fc4327b1771d07502adc
https://qiita.com/granddaifuku/items/c26b58b89d73b4a3de98
上記URLを参考にしました。
シンボリックリンクは下記のように設定
sudo ln -s /usr/local/bin/gcc-12 /usr/local/bin/gcc
sudo ln -s /usr/local/bin/g++-12 /usr/local/bin/g++
これでclangからgccに切り替えているつもりです。
stdc++.hファイルのパスは
/usr/local/include/bits/stdc++.h
です。
VSCodeには
C/C++
C/C++ Extension Pack
Code Runner
をインストールしています
VSCodeのターミナルで
gcc cpp.cpp
を実行すると下記のエラーが生じます。
VSCodeにこだわりないので、もし他に良いエディタ環境があればアドバイスお願いします。
発生している問題・エラーメッセージ
Undefined symbols for architecture x86_64: "__ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE7compareEPKc", referenced from: __ZSteqIcSt11char_traitsIcESaIcEEbRKNSt7__cxx1112basic_stringIT_T0_T1_EEPKS5_ in ccKyomWg.o "__ZNSirsERi", referenced from: _main in ccKyomWg.o "__ZNSolsEPFRSoS_E", referenced from: _main in ccKyomWg.o "__ZNSolsEi", referenced from: _main in ccKyomWg.o "__ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1Ev", referenced from: _main in ccKyomWg.o "__ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED1Ev", referenced from: _main in ccKyomWg.o "__ZNSt8ios_base4InitC1Ev", referenced from: __Z41__static_initialization_and_destruction_0ii in ccKyomWg.o "__ZNSt8ios_base4InitD1Ev", referenced from: __Z41__static_initialization_and_destruction_0ii in ccKyomWg.o "__ZSt17__throw_bad_allocv", referenced from: __ZNSt15__new_allocatorIiE8allocateEmPKv in ccKyomWg.o __ZNSt15__new_allocatorISt4pairIcSt6vectorIiSaIiEEEE8allocateEmPKv in ccKyomWg.o __ZNSt15__new_allocatorISt4pairIciEE8allocateEmPKv in ccKyomWg.o "__ZSt20__throw_length_errorPKc", referenced from: __ZNKSt6vectorIiSaIiEE12_M_check_lenEmPKc in ccKyomWg.o __ZNKSt6vectorISt4pairIcS_IiSaIiEEESaIS3_EE12_M_check_lenEmPKc in ccKyomWg.o __ZNKSt6vectorISt4pairIciESaIS1_EE12_M_check_lenEmPKc in ccKyomWg.o "__ZSt24__throw_out_of_range_fmtPKcz", referenced from: __ZNKSt6vectorISt4pairIciESaIS1_EE14_M_range_checkEm in ccKyomWg.o "__ZSt28__throw_bad_array_new_lengthv", referenced from: __ZNSt15__new_allocatorIiE8allocateEmPKv in ccKyomWg.o __ZNSt15__new_allocatorISt4pairIcSt6vectorIiSaIiEEEE8allocateEmPKv in ccKyomWg.o __ZNSt15__new_allocatorISt4pairIciEE8allocateEmPKv in ccKyomWg.o "__ZSt3cin", referenced from: __Z13int_calculateiSt6vectorISt4pairIciESaIS1_EE in ccKyomWg.o __Z8vec_readc in ccKyomWg.o _main in ccKyomWg.o "__ZSt4cout", referenced from: _main in ccKyomWg.o "__ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_", referenced from: _main in ccKyomWg.o "__ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c", referenced from: _main in ccKyomWg.o "__ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_RS3_", referenced from: __Z13int_calculateiSt6vectorISt4pairIciESaIS1_EE in ccKyomWg.o __Z8vec_readc in ccKyomWg.o _main in ccKyomWg.o "__ZStrsIcSt11char_traitsIcESaIcEERSt13basic_istreamIT_T0_ES7_RNSt7__cxx1112basic_stringIS4_S5_T1_EE", referenced from: _main in ccKyomWg.o "__ZdlPvm", referenced from: __ZNSt15__new_allocatorISt4pairIciEE10deallocateEPS1_m in ccKyomWg.o __ZNSt15__new_allocatorISt4pairIcSt6vectorIiSaIiEEEE10deallocateEPS4_m in ccKyomWg.o __ZNSt15__new_allocatorIiE10deallocateEPim in ccKyomWg.o "__Znwm", referenced from: __ZNSt15__new_allocatorIiE8allocateEmPKv in ccKyomWg.o __ZNSt15__new_allocatorISt4pairIcSt6vectorIiSaIiEEEE8allocateEmPKv in ccKyomWg.o __ZNSt15__new_allocatorISt4pairIciEE8allocateEmPKv in ccKyomWg.o (maybe you meant: __ZnwmPv) "___gxx_personality_v0", referenced from: Dwarf Exception Unwind Info (__eh_frame) in ccKyomWg.o ld: symbol(s) not found for architecture x86_64 collect2: error: ld returned 1 exit status
該当のソースコード
c++
1-cpp.cpp- 2#include <bits/stdc++.h> 3using namespace std; 4 5int main(){ 6 cout << "hello"<< cin; 7} 8 9以下c_cpp_properties.json 10-------------------------------- 11{ 12 "configurations": [ 13 { 14 "name": "Mac", 15 "includePath": [ 16 "${workspaceFolder}/**", 17 "/usr/local/include/bits" 18 ], 19 "defines": [], 20 "macFrameworkPath": [ 21 "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks" 22 ], 23 "compilerPath": "/usr/local/bin/gcc", 24 "cStandard": "c17", 25 "cppStandard": "c++14", 26 "intelliSenseMode": "macos-gcc-x64" 27 } 28 ], 29 "version": 4 30}
補足情報(FW/ツールのバージョンなど)
MacOS Monterey ver12.6.3
VSCode Version: 1.76.2
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2023/03/16 07:55