H
haziz
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++
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++