Command Line Clang C++ Compilation Syntax?

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++
 
V

Victor Bazarov

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
 
J

Juha Nieminen

haziz said:
$> 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).
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top