我有一个脚本,可以从源代码构建llvm / clang 3.42 (使用configure + make)。 在ubuntu 14.04.5 LTS 上顺利运行。 当我升级到 ubuntu 17.04 时,构建失败。
以下是构建脚本:
svn co https://llvm.org/svn/llvm-project/llvm/tags/RELEASE_342/final llvm
svn co https://llvm.org/svn/llvm-project/cfe/tags/RELEASE_342/final llvm/tools/clang
svn co https://llvm.org/svn/llvm-project/compiler-rt/tags/RELEASE_342/final llvm/projects/compiler-rt
svn co https://llvm.org/svn/llvm-project/libcxx/tags/RELEASE_342/final llvm/projects/libcxx
rm -rf llvm/.svn
rm -rf llvm/tools/clang/.svn
rm -rf llvm/projects/compiler-rt/.svn
rm -rf llvm/projects/libcxx/.svn
cd llvm
./configure \
--enable-optimized \
--disable-assertions \
--enable-targets=host \
--with-python="/usr/bin/python2"
make -j `nproc`
以下是我得到的错误(TLDR: malloc 的定义问题, calloc , realloc 和免费)
/usr/include/malloc.h:38:14: error: declaration conflicts with target of using declaration already in scope
extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur;
^
/usr/include/stdlib.h:427:14: note: target of using declaration
extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur;
^
/usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3./stdlib.h:65:12: note: using declaration
using std::malloc;
^
In file included from /home/oren/GIT/LatestKlee/llvm/projects/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc:47:
/usr/include/malloc.h:41:14: error: declaration conflicts with target of using declaration already in
scope
extern void *calloc (size_t __nmemb, size_t __size)
^
/usr/include/stdlib.h:429:14: note: target of using declaration
extern void *calloc (size_t __nmemb, size_t __size)
^
/usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/stdlib.h:59:12: note: using declaration
using std::calloc;
^
In file included from /home/oren/GIT/LatestKlee/llvm/projects/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc:47:
/usr/include/malloc.h:49:14: error: declaration conflicts with target of using declaration already in
scope
extern void *realloc (void *__ptr, size_t __size)
^
/usr/include/stdlib.h:441:14: note: target of using declaration
extern void *realloc (void *__ptr, size_t __size)
^
/usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/stdlib.h:73:12: note: using declaration
using std::realloc;
^
In file included from /home/oren/GIT/LatestKlee/llvm/projects/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc:47:
/usr/include/malloc.h:53:13: error: declaration conflicts with target of using declaration already in
scope
extern void free (void *__ptr) __THROW;
^
/usr/include/stdlib.h:444:13: note: target of using declaration
extern void free (void *__ptr) __THROW;
^
/usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/stdlib.h:61:12: note: using declaration
using std::free;
^
COMPILE: clang_linux/tsan-x86_64/x86_64: /home/oren/GIT/LatestKlee/llvm/projects/compiler-rt/lib/tsan/rtl/tsan_rtl_mutex.cc
4 errors generated.
Makefile:267: recipe for target '/home/oren/GIT/LatestKlee/llvm/tools/clang/runtime/compiler-rt/clang_linux/tsan-x86_64/x86_64/SubDir.lib__tsan__rtl/tsan_platform_linux.o' failed
make[5]: *** [/home/oren/GIT/LatestKlee/llvm/tools/clang/runtime/compiler-rt/clang_linux/tsan-x86_64/x86_64/SubDir.lib__tsan__rtl/tsan_platform_linux.o] Error 1
ubuntu 17.04附带的默认gcc版本是6.3。 也许这是gcc 6.3使用的默认C ++方言的问题? 非常感谢任何帮助,谢谢!
答案 0 :(得分:1)
这似乎是LLVM 3.4.2 tsan
(Thread Sanitizer)无法使用GCC 6.x构建的问题,如先前在此处报道的那样:
https://aur.archlinux.org/packages/clang34-analyzer-split
似乎包含stdlib.h
和malloc.h
是冲突的,因为它们都定义了malloc
和朋友。
这个问题可能仅出现在tsan
中,所以如果tsan
对你的LLVM构建没有帮助(很可能),并且你希望坚持使用系统用于构建LLVM的gcc,您可以考虑完全禁用tsan
。
如果您正在运行CMake构建(如here中所述),则可以通过评论llvm/projects/compiler-rt/lib/CMakeLists.txt
的第29行来执行此操作:
if (CMAKE_SYSTEM_NAME MATCHES "Linux" AND NOT ANDROID)
add_subdirectory(tsan) # comment out this line
如果您被迫坚持使用configure
版本,我最好的猜测是删除tsan-x86_64
第63行中的llvm/projects/compiler-rt/make/clang_linux.mk
目标:
Configs += full-x86_64 profile-x86_64 san-x86_64 asan-x86_64 --> tsan-x86_64 <--
答案 1 :(得分:0)
我在Ubuntu 16.10上面临同样的问题。 它有默认的gcc 6.2。您需要指示LLVM构建系统使用gcc 4.9。另外,我建议你完全删除GCC6。
$ sudo apt-get remove g++-6 gcc-6 cpp
$ sudo apt-get install gcc-4.9 g++4.9
$ export CC=/usr/bin/gcc-4.9
$ export CXX=/usr/bin/g++-4.9
$ export CPP=/usr/bin/cpp-4.9
$ ./configure
$ make
也许你需要:
$ sudo ln -s /usr/bin/cpp-4.9 /usr/bin/cpp