简体   繁体   English

如何正确配置Clang?

[英]How to properly configure Clang?

I've just compiled latest reps of LLVM, Clang and libc++. 我刚刚编译了LLVM,Clang和libc ++的最新代表。 Now however I have no idea how to configure the environment to use them. 但是现在我不知道如何配置环境以使用它们。 I've added in $PATH the one to compiled binaries and have set the 我在$ PATH中添加了一个到已编译的二进制文件中,并设置了

$D_LIBRARY_PATH=$(llvm-config --libdir) $ D_LIBRARY_PATH = $(llvm-config --libdir)

but anyway when I test run 'clang' with example file it uses some '/usr/bin/ld' linker which I have no idea what is it (as I've uninstalled 'g++' because thought it was the problem (before 'clang' used some linker from it) and I don't have any other C++ compilers). 但是无论如何,当我用示例文件测试运行'clang'时,它使用了一些'/ usr / bin / ld'链接程序,我不知道它是什么(因为我已经卸载了'g ++',因为以为是问题所在(在“ clang'使用了一些链接程序,而我没有其他C ++编译器)。

So now how do I point out the right 'llvm-ld', libc++ include and library paths? 那么,现在如何指出正确的“ llvm-ld”,libc ++包含和库路径? I don't want to pass some complex arguments every-time. 我不想每次都传递一些复杂的论点。 Perhaps I should set some environment variables. 也许我应该设置一些环境变量。

I'm also using KDevelop with the same effect. 我也在使用具有相同效果的KDevelop。

Don't judge me if this sounds stupid but it's my first time with Linux (have always used Windows before). 如果这听起来很愚蠢,请不要判断我,但这是我第一次使用Linux(以前一直使用Windows)。 I'm using latest 'OpenSUSE' dist. 我正在使用最新的“ OpenSUSE”发行版。

Update - here is the output window of CodeLite using clang compiler: 更新-这是使用clang编译器的CodeLite的输出窗口:

/bin/sh -c 'make -j 2 -e -f Makefile' ----------Building project:[ ClangTest - Debug ]---------- make[1]: Entering directory '/run/media/bs_ld/8688602a-296d-40e1-bd37-c90e69f45769/Workspace/CL_C++_WP/ClangTest' clang++ -c "/run/media/bs_ld/8688602a-296d-40e1-bd37-c90e69f45769/Workspace/CL_C++_WP/ClangTest/main.cpp" -stdlib=libc++ -o ./Debug/main.cpp.o -I. / bin / sh -c'make -j 2 -e -f Makefile'----------构建项目:[ClangTest-Debug] ---------- make [1]:输入目录'/ run / media / bs_ld / 8688602a-296d-40e1-bd37-c90e69f45769 / Workspace / CL_C ++ _ WP / ClangTest'clang ++ -c“ / run / media / bs_ld / 8688602a-296d-40e1-bd37-c90e69f45769 /工作区/CL_C++_WP/ClangTest/main.cpp“ -stdlib = libc ++ -o ./Debug/main.cpp.o -I。 -I/run/media/bs_ld/8688602a-296d-40e1-bd37-c90e69f45769/Build/include/c++/v1/ clang++ -o ./Debug/ClangTest @"ClangTest.txt" -L. -I / run / media / bs_ld / 8688602a-296d-40e1-bd37-c90e69f45769 / Build / include / c ++ / v1 / clang ++ -o ./Debug/ClangTest @“ ClangTest.txt” -L。 -L/run/media/bs_ld/8688602a-296d-40e1-bd37-c90e69f45769/Build/lib/ /usr/bin/ld: cannot find crtbegin.o: No such file or directory /usr/bin/ld: cannot find -lstdc++ /usr/bin/ld: cannot find -lgcc_s /usr/bin/ld: cannot find -lgcc clang-3.7: error: linker command failed with exit code 1 (use -v to see invocation) ClangTest.mk:76: recipe for target 'Debug/ClangTest' failed make[1]: * [Debug/ClangTest] Error 1 make[1]: Leaving directory '/run/media/bs_ld/8688602a-296d-40e1-bd37-c90e69f45769/Workspace/CL_C++_WP/ClangTest' Makefile:4: recipe for target 'All' failed make: * [All] Error 2 0 errors, 0 warnings -L / run / media / bs_ld / 8688602a-296d-40e1-bd37-c90e69f45769 / Build / lib / / usr / bin / ld:找不到crtbegin.o:找不到这样的文件或目录/ usr / bin / ld:找不到-lstdc ++ / usr / bin / ld:找不到-lgcc_s / usr / bin / ld:找不到-lgcc clang-3.7:错误:链接器命令失败,退出代码为1(使用-v查看调用)ClangTest.mk:76 :目标'Debug / ClangTest'的配方失败make [1]: * [Debug / ClangTest]错误1 make [1]:离开目录'/ run / media / bs_ld / 8688602a-296d-40e1-bd37-c90e69f45769 / Workspace / CL_C ++ _ WP / ClangTest'Makefile:4:目标“ All”的配方失败:* [All]错误2 0错误,0警告

You should be able to run make install with perhaps an optional DESTDIR=/...... so that it doesn't clobber your system files. 您应该可以使用可选的DESTDIR=/......运行make install ,以免破坏系统文件。

Since you're on OpenSUSE, you might as well use your distribution's build services, and install the SVN version of LLVM-Clang from here . 由于您使用的是OpenSUSE,因此不妨使用发行版的构建服务,并从此处安装SVN版本的LLVM-Clang。 You should be able to find libc++ and LLVM itself as well. 您还应该能够找到libc ++和LLVM本身。

Otherwise, make install DESTDIR=/opt/llvm should work, and then you can add /opt/llvm/bin/ to PATH and use libc++ by adding this compile and link option: -stdlib=libc++ . 否则,请执行make install DESTDIR=/opt/llvm ,然后将/opt/llvm/bin/PATH并通过添加以下编译和链接选项使用libc ++:- -stdlib=libc++ You'll need something like /opt/llvm/lib in LD_LIBRARY_PATH as well to find the libc++ so. 您还需要LD_LIBRARY_PATH /opt/llvm/lib类的东西才能找到libc++

This should work pretty much out of the box, but I have only ever used my distribution's packages, not a self-built Clang to do this. 这应该可以立即使用,但是我只用过发行版的软件包,而不是用自建的Clang来完成的。

Note that Clang still uses your system linker, ld , and this is fine. 请注意,Clang仍然使用系统链接器ld ,这很好。 Currently, LLVM does not yet provide a fully functional alternative to this program, but they are working on it . 目前,LLVM尚未提供此程序的功能齐全的替代方案,但他们正在研究该方案。

EDIT : It seems you uninstalled too much: Clang also uses the GCC crtbegin and crtend object files. 编辑 :似乎您卸载了太多:Clang还使用了GCC crtbegin和crtend对象文件。 So just install GCC again along with glibc and its dev package. 因此,只需再次安装GCC以及glibc及其开发包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM