![](/img/trans.png)
[英]Is it possible to compile the source with Clang using Clang C++ API in memory?
[英]Error using clang to compile c++
我一直在嘗試使用clang在c ++中編譯一個簡單的hello world程序。 現在,我已經能夠使用以下命令執行此操作:
鐺-lc ++ hello.cpp -o你好
當我嘗試這個我得到錯誤:
/usr/bin/ld: cannot find -lc++
Clang:錯誤:鏈接器命令失敗,退出代碼為1
如果我使用g ++,則編譯不會出錯。 為什么用lang發生此問題?
您需要安裝libc ++庫。
嘗試使用ubuntu:
sudo bash -c "cat >> /etc/apt/sources.list" << LLVMAPT
# LLVM
deb http://llvm.org/apt/trusty/ llvm-toolchain-trusty main
deb-src http://llvm.org/apt/trusty/ llvm-toolchain-trusty main
# 3.5
deb http://llvm.org/apt/trusty/ llvm-toolchain-trusty-3.5 main
deb-src http://llvm.org/apt/trusty/ llvm-toolchain-trusty-3.5 main
# 3.6
deb http://llvm.org/apt/trusty/ llvm-toolchain-trusty-3.6 main
deb-src http://llvm.org/apt/trusty/ llvm-toolchain-trusty-3.6 main
LLVMAPT
wget -O - http://llvm.org/apt/llvm-snapshot.gpg.key|sudo apt-key add -
sudo apt-get update -y
sudo apt-get install -y clang-3.6 lldb-3.6 libc++-dev libc++abi-dev
如果上面的腳本不起作用,或者您不使用ubuntu,請訪問以下網站下載該庫:
Clang編譯C語言,而Clang ++編譯C ++。 這些是不同的語言 ,因此每種語言都需要一個單獨的編譯器。
前一段時間,我也遇到了麻煩。 我嘗試鏈接庫的負載( -lstdc++
等),從源代碼構建stdlib等,但是沒有任何效果。 在我意識到必須使用clang++
之前,這是一個法官問題。
因此,您也需要clang++
而不是 clang
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.