Command Line Clang C++ Compilation Syntax?

Discussion in 'C++' started by haziz, Apr 9, 2012.

  1. haziz

    haziz Guest

    How do you use Clang from the command line to compile a C++ program?

    Both

    clang helloworld.cpp -o helloworld

    and

    clang++ helloworld.cpp -o helloworld

    produce errors and fail to compile. I use clang everyday as my standard C compiler but this is the first time I am experimenting with it for C++.

    This was tested and will be used on both a Linux system and Mac OsX (from the command line). I have perused the man pages (and Google) but no answer jumped out at me.

    For example on the Mac (Clang/LLVM installed from the apple devloper website):

    $> clang helloworld.cpp -o helloworld.cpp
    clang: warning: not using the clang compiler for C++ inputs
    /var/folders/Ey/EybKRC12G0eU3pFMvTGK9k+++TI/-Tmp-/cc-2hoOgm.s:43:suffix or operands invalid for `push'
    /var/folders/Ey/EybKRC12G0eU3pFMvTGK9k+++TI/-Tmp-/cc-2hoOgm.s:74:suffix or operands invalid for `push'
    /var/folders/Ey/EybKRC12G0eU3pFMvTGK9k+++TI/-Tmp-/cc-2hoOgm.s:78:suffix or operands invalid for `push'
    /var/folders/Ey/EybKRC12G0eU3pFMvTGK9k+++TI/-Tmp-/cc-2hoOgm.s:186:suffix or operands invalid for `pop'
    /var/folders/Ey/EybKRC12G0eU3pFMvTGK9k+++TI/-Tmp-/cc-2hoOgm.s:199:suffix or operands invalid for `push'
    /var/folders/Ey/EybKRC12G0eU3pFMvTGK9k+++TI/-Tmp-/cc-2hoOgm.s:203:suffix or operands invalid for `push'
    /var/folders/Ey/EybKRC12G0eU3pFMvTGK9k+++TI/-Tmp-/cc-2hoOgm.s:210:suffix or operands invalid for `pop'
    /var/folders/Ey/EybKRC12G0eU3pFMvTGK9k+++TI/-Tmp-/cc-2hoOgm.s:228:suffix or operands invalid for `pop'
    /var/folders/Ey/EybKRC12G0eU3pFMvTGK9k+++TI/-Tmp-/cc-2hoOgm.s:236:suffix or operands invalid for `push'
    /var/folders/Ey/EybKRC12G0eU3pFMvTGK9k+++TI/-Tmp-/cc-2hoOgm.s:240:suffix or operands invalid for `push'
    /var/folders/Ey/EybKRC12G0eU3pFMvTGK9k+++TI/-Tmp-/cc-2hoOgm.s:247:suffix or operands invalid for `pop'
    /var/folders/Ey/EybKRC12G0eU3pFMvTGK9k+++TI/-Tmp-/cc-2hoOgm.s:268:suffix or operands invalid for `pop'
    /var/folders/Ey/EybKRC12G0eU3pFMvTGK9k+++TI/-Tmp-/cc-2hoOgm.s:275:suffix or operands invalid for `push'
    /var/folders/Ey/EybKRC12G0eU3pFMvTGK9k+++TI/-Tmp-/cc-2hoOgm.s:292:suffix or operands invalid for `push'
    /var/folders/Ey/EybKRC12G0eU3pFMvTGK9k+++TI/-Tmp-/cc-2hoOgm.s:296:suffix or operands invalid for `push'
    /var/folders/Ey/EybKRC12G0eU3pFMvTGK9k+++TI/-Tmp-/cc-2hoOgm.s:303:suffix or operands invalid for `pop'
    /var/folders/Ey/EybKRC12G0eU3pFMvTGK9k+++TI/-Tmp-/cc-2hoOgm.s:309:suffix or operands invalid for `pop'
    /var/folders/Ey/EybKRC12G0eU3pFMvTGK9k+++TI/-Tmp-/cc-2hoOgm.s:20606:unknown section type: non_lazy_symbol_pointers
    /var/folders/Ey/EybKRC12G0eU3pFMvTGK9k+++TI/-Tmp-/cc-2hoOgm.s:20606:Rest of line ignored. 1st junk character valued 76 (L).
    /var/folders/Ey/EybKRC12G0eU3pFMvTGK9k+++TI/-Tmp-/cc-2hoOgm.s:20607:Unknown pseudo-op: .indirect_symbol
    /var/folders/Ey/EybKRC12G0eU3pFMvTGK9k+++TI/-Tmp-/cc-2hoOgm.s:20607:Rest of line ignored. 1st junk character valued 95 (_).
    /var/folders/Ey/EybKRC12G0eU3pFMvTGK9k+++TI/-Tmp-/cc-2hoOgm.s:20610:Unknown pseudo-op: .indirect_symbol
    /var/folders/Ey/EybKRC12G0eU3pFMvTGK9k+++TI/-Tmp-/cc-2hoOgm.s:20610:Rest of line ignored. 1st junk character valued 95 (_).
    /var/folders/Ey/EybKRC12G0eU3pFMvTGK9k+++TI/-Tmp-/cc-2hoOgm.s:20613:Unknown pseudo-op: .indirect_symbol
    /var/folders/Ey/EybKRC12G0eU3pFMvTGK9k+++TI/-Tmp-/cc-2hoOgm.s:20613:Rest of line ignored. 1st junk character valued 95 (_).
    /var/folders/Ey/EybKRC12G0eU3pFMvTGK9k+++TI/-Tmp-/cc-2hoOgm.s:20616:Unknown pseudo-op: .indirect_symbol
    /var/folders/Ey/EybKRC12G0eU3pFMvTGK9k+++TI/-Tmp-/cc-2hoOgm.s:20616:Rest of line ignored. 1st junk character valued 95 (_).
    clang: error: assembler command failed with exit code 1 (use -v to see invocation)
    Retested with clang++ again on the Mac:

    $> clang++ helloworld.cpp -o helloworld
    zsh: command not found: clang++
    $> clang++ --help
    zsh: command not found: clang++
     
    haziz, Apr 9, 2012
    #1
    1. Advertising

  2. On 4/9/2012 3:43 PM, haziz wrote:
    > How do you use Clang from the command line to compile a C++ program?


    I don't.

    > [...]


    On a serious note, tools and their command lines are off-topic here.
    Try asking in the newsgroup dedicated to the tool or to the OS on which
    that tool runs. Often reading the documentation helps, or plain ol'
    googling.

    V
    --
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Apr 9, 2012
    #2
    1. Advertising

  3. haziz <> wrote:
    > $> clang helloworld.cpp -o helloworld.cpp
    > clang: warning: not using the clang compiler for C++ inputs


    What's unclear about that?

    > $> clang++ helloworld.cpp -o helloworld
    > zsh: command not found: clang++


    Likewise I fail to see what's unclear about that.

    If you want to use clang++, you have to install it first (duh).

    If you are using a Mac and have Xcode installed, the current version
    has an option to download and install the command-line utilities
    (under Xcode > Preferences > Downloads).
     
    Juha Nieminen, Apr 10, 2012
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Johannes Schaub (litb)

    Weird difference between comeau and gcc/clang

    Johannes Schaub (litb), Oct 13, 2010, in forum: C++
    Replies:
    15
    Views:
    624
    James Kanze
    Oct 18, 2010
  2. anonimo
    Replies:
    0
    Views:
    347
    anonimo
    Oct 31, 2010
  3. Seung Soo, Ha

    Run clang static analyzer on Python 3.30a

    Seung Soo, Ha, Aug 10, 2011, in forum: Python
    Replies:
    0
    Views:
    220
    Seung Soo, Ha
    Aug 10, 2011
  4. Ollivier Robert

    1.9.2dev compilation with clang 1.1

    Ollivier Robert, Feb 26, 2010, in forum: Ruby
    Replies:
    0
    Views:
    121
    Ollivier Robert
    Feb 26, 2010
  5. haziz

    Clang vs. GCC: Compare & Contrast?

    haziz, Mar 23, 2012, in forum: C Programming
    Replies:
    3
    Views:
    1,240
    Jens Gustedt
    Mar 23, 2012
Loading...

Share This Page