clang에서 bits/stdc++.h 사용

9338 단어 C++macosclang++MacOSX

소개



나란히 잊기 때문에 메모입니다.

하고 싶은 일



clang++ 에서 bits/stdc++.h 사용하고 싶어요!

할 수있는 일



/usr/local/include/bits 에 stdc++.h 를 만들면

환경


  • macOS Catalina 10.15.5

  • 했던 일



    우선



    main.cpp
    #include <bits/stdc++.h>
    using namespace std;
    
    int main(){
        cout << "HOGE HOGE パラダイス" << endl;
    }
    
    

    준비하자!
    hoge@foo % clang++ main.cpp
    main.cpp:1:10: fatal error: 'bits/stdc++.h' file not found
    #include <bits/stdc++.h>
             ^~~~~~~~~~~~~~~
    1 error generated.
    

    화가 났어 🥺

    clang 짱 어디 찾고 있어?



    clang 찬 에 bits/stdc++.h 찾아내고 싶은 것은 산들입니다만
    bits/stdc++.h를 어디에 만들어야할지 모르겠습니다

    평소와 같이 잡은 워드를 나란히 건간 검색으로 건속 ぅ↑(???????)하고 있으면...
    OS X clang include lib search path에 도착했습니다!
    $ clang -x c -v -E /dev/null
    

    그렇다고 하는 것이 표시되고 있지만 무슨 일···?

    그러므로
    clang - the Clang C, C++, and Objective-C compiler
    옵션 설명을 보러 갔다.

    ーx



    -x
    Treat subsequent input files as having type language.

    그건 이번에는 c++입니다!

    ーv



    -v
    Show commands to run and use verbose output.

    이것으로 상세를 출력해 주네요!

    - 그림



    -E
    Run the preprocessor stage.

    프리프로세서만 달려라···!
    지금 핀 때 없기 때문에 (치명적) 아래 페이지에서 확인.
    C/C++ 빌드 메커니즘 및 라이브러리
    이해하기 쉬웠다

    /dev/null



    입력 파일로 전달 /dev/null wikipedia 교사에 따르면

    /dev/null 는 통상, 프로세스의 불필요한 출력 스트림을 버리는데 사용하는지, 입력 스트림을 위한 빈 파일로서 사용한다.

    과연 빈 파일로 사용하는군요. 그런 것이 있었다 ... 뭐? (닭뇌)

    Include Lib Search Path



    이상을 정리하면
    clang++ -x c++ -v -E /dev/null
    

    갈 수 있다는 것입니다! (clang++ 는 clang 에서도 가능)

    조속히 실행하면
    hoge@foo % clang++ -x c++ -v -E /dev/null
    Apple clang version 11.0.3 (clang-1103.0.32.62)
    Target: x86_64-apple-darwin19.5.0
    Thread model: posix
    InstalledDir: /Library/Developer/CommandLineTools/usr/bin
     "/Library/Developer/CommandLineTools/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.15.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -E -disable-free -disable-llvm-verifier -discard-value-names -main-file-name null -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=all -fno-strict-return -masm-verbose -munwind-tables -target-sdk-version=10.15.4 -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -target-linker-version 556.6 -v -resource-dir /Library/Developer/CommandLineTools/usr/lib/clang/11.0.3 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -stdlib=libc++ -internal-isystem /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1 -internal-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1 -internal-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /Library/Developer/CommandLineTools/usr/lib/clang/11.0.3/include -internal-externc-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -internal-externc-isystem /Library/Developer/CommandLineTools/usr/include -Wno-objc-signed-char-bool-implicit-int-conversion -Wno-extra-semi-stmt -Wno-quoted-include-in-framework-header -fdeprecated-macro -fdebug-compilation-dir /Users/hoge/pcon/test/clangtest -ferror-limit 19 -fmessage-length 73 -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fobjc-runtime=macosx-10.15.0 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o - -x c++ /dev/null
    clang -cc1 version 11.0.3 (clang-1103.0.32.62) default target x86_64-apple-darwin19.5.0
    ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1"
    ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include"
    ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/Library/Frameworks"
    #include "..." search starts here:
    #include <...> search starts here:
     /usr/local/include
     /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1
     /Library/Developer/CommandLineTools/usr/lib/clang/11.0.3/include
     /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
     /Library/Developer/CommandLineTools/usr/include
     /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
    End of search list.
    # 1 "/dev/null"
    # 1 "<built-in>" 1
    # 1 "<built-in>" 3
    # 376 "<built-in>" 3
    # 1 "<command line>" 1
    # 1 "<built-in>" 2
    # 1 "/dev/null" 2
    

    있었다! 보고 싶었던 것은 여기!
    #include <...> search starts here:
     /usr/local/include
     /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1
     /Library/Developer/CommandLineTools/usr/lib/clang/11.0.3/include
     /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
     /Library/Developer/CommandLineTools/usr/include
     /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks 
    

    따라서 이번에는/usr/local/include 에 bits/stdc++.h를 만듭니다.
    (위의 장소라면 어디서나 좋겠지만)

    bits/stdc++.h 만들기



    /usr/local/include에 bits 디렉토리 만들기
    cd /usr/local/include
    mkdir bits
    

    나머지는
    여기
    stdc++.h를 데려와 bits에 흠뻑 빠져나가~! !
    hoge@foo % clang++ main.cpp -o hoge    
    hoge@foo % ./hoge                     
    HOGE HOGE パラダイス
    

    무사히 clang 너도 bits/stdc++.h 찾아낸 거야.
    죄송합니다.

    마지막으로



    먼저
    clang++ -v main.cpp
    

    하지만 확인할 수 있다는 거잖아・・・
    뭐 여러가지 공부가 되었기 때문에 좋다고 합니다. 제대로 man하자!

    참고문헌



    OS X clang include lib search path
    How can I include <bits/stdc++> in Xcode
    clang - the Clang C, C++, and Objective-C compiler
    C/C++ 빌드 메커니즘 및 라이브러리
    /dev/null

    좋은 웹페이지 즐겨찾기