ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [M1, M2] 맥북 bits/stdc++.h include 되지 않을 때
    MAC 2022. 12. 19. 14:35
    반응형

    방법 1 :

    다음 폴더로 이동한다 : 

    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1

    여기에 bits폴더를 만들고 안에 다음 파일을 집어넣는다.

    stdc++.h
    0.00MB

    stdc++.h 전체 파일 내용 : 

    // C++ includes used for precompiling -*- C++ -*-
    
    // Copyright (C) 2003-2013 Free Software Foundation, Inc.
    //
    // This file is part of the GNU ISO C++ Library.  This library is free
    // software; you can redistribute it and/or modify it under the
    // terms of the GNU General Public License as published by the
    // Free Software Foundation; either version 3, or (at your option)
    // any later version.
    
    // This library is distributed in the hope that it will be useful,
    // but WITHOUT ANY WARRANTY; without even the implied warranty of
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    // GNU General Public License for more details.
    
    // Under Section 7 of GPL version 3, you are granted additional
    // permissions described in the GCC Runtime Library Exception, version
    // 3.1, as published by the Free Software Foundation.
    
    // You should have received a copy of the GNU General Public License and
    // a copy of the GCC Runtime Library Exception along with this program;
    // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
    // <http://www.gnu.org/licenses/>.
    
    /** @file stdc++.h
     *  This is an implementation file for a precompiled header.
     */
    
    // 17.4.1.2 Headers
    
    // C
    #ifndef _GLIBCXX_NO_ASSERT
    #include <cassert>
    #endif
    #include <cctype>
    #include <cerrno>
    #include <cfloat>
    #include <ciso646>
    #include <climits>
    #include <clocale>
    #include <cmath>
    #include <csetjmp>
    #include <csignal>
    #include <cstdarg>
    #include <cstddef>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <ctime>
    
    #if __cplusplus >= 201103L
    #include <ccomplex>
    #include <cfenv>
    #include <cinttypes>
    #include <cstdbool>
    #include <cstdint>
    #include <ctgmath>
    #include <cwchar>
    #include <cwctype>
    #endif
    
    // C++
    #include <algorithm>
    #include <bitset>
    #include <complex>
    #include <deque>
    #include <exception>
    #include <fstream>
    #include <functional>
    #include <iomanip>
    #include <ios>
    #include <iosfwd>
    #include <iostream>
    #include <istream>
    #include <iterator>
    #include <limits>
    #include <list>
    #include <locale>
    #include <map>
    #include <memory>
    #include <new>
    #include <numeric>
    #include <ostream>
    #include <queue>
    #include <set>
    #include <sstream>
    #include <stack>
    #include <stdexcept>
    #include <streambuf>
    #include <string>
    #include <typeinfo>
    #include <utility>
    #include <valarray>
    #include <vector>
    
    #if __cplusplus >= 201103L
    #include <array>
    #include <atomic>
    #include <chrono>
    #include <condition_variable>
    #include <forward_list>
    #include <future>
    #include <initializer_list>
    #include <mutex>
    #include <random>
    #include <ratio>
    #include <regex>
    #include <scoped_allocator>
    #include <system_error>
    #include <thread>
    #include <tuple>
    #include <typeindex>
    #include <type_traits>
    #include <unordered_map>
    #include <unordered_set>
    #endif

    방법 2:
    /Library/Developer/CommandLineTools/usr/include
    여기서 bits 폴더를 만들고 stdc++.h를 넣어둔다.

    터미널에서 g++을 실행해서 컴파일을 하려고 했지만 다음과 같은 에러들이 떴다.

    3059.cpp:4:17: error: no member named 'cin' in namespace 'std'
        int T; std::cin>>T;

    3059.cpp:6:21: error: implicit instantiation of undefined template 'std::vector<int>'
            vector<int> v(26);

    error: reference to overloaded function could not be resolved; did you mean to call it?
            cout << res << '\n';

    하나같이 명령어들을 인식을 못하고 있다. 헤더파일을 못읽는 것 같다.

    찾아보니 apple silicon(M1, M2 칩)으로 되어있는 환경에서 g++이 아닌 clang을 기본값으로 해주는 것 같다.
    그리고, clang으로 컴파일 하면 bits/stdc++.h를 제대로 불러오지 못한다고 한다.

    실험을 몇가지 해보았다. 그냥 터미널에 g++만 쳐보았더니 clang: error: no input files 오류가 나왔다. 분명 g++를 실행했는데 clang으로 바뀐다. brew install gcc 명령어로 최신 g++을 깔고, 터미널에 g++-12를 쳐보았다. g++-12: fatal error: no input files 오류가 나왔다. 이제 alias로 g++만 쳤을 때 g++-12를 실행하도록 바꿀 것이다. vi ~/.zshrc 명령어로 파일을 열고 맨 밑 줄에 alias g++="g++-12" 한 줄만 추가해준다. source ~/.zshrc로 적용 해준 다음 g++ -o 3059 3059.cpp -std=c++17 명령어를 실행했더니 이제 잘 된다. (실행은 ./3059, 3059.cpp 파일이 기존에 있어야 함)

     

    코드는 https://github.com/chongin12/Problem_Solving/blob/master/acmicpc.net/3059.cpp 여기에 있다.

    반응형

    댓글

Designed by Tistory.