gpt4 book ai didi

LLVM、-fprofile-instr-generate、对“__llvm_profile_register_function”的 undefined reference

转载 作者:行者123 更新时间:2023-12-02 11:56:12 28 4
gpt4 key购买 nike

我遇到以下错误“-fprofile-instr-generate”。感谢您为解决此错误而提供的意见

谢谢

错误:

clang++ -O2 -fprofile-instr-generate hello.cpp
/tmp/hello-58ef5f.o:hello.cpp:function __llvm_profile_init: error: undefined reference to '__llvm_profile_register_function'
/tmp/hello-58ef5f.o:hello.cpp:function __llvm_profile_init: error: undefined reference to '__llvm_profile_register_function'
/tmp/hello-58ef5f.o:hello.cpp:function __llvm_profile_init: error: undefined reference to '__llvm_profile_register_function'
/tmp/hello-58ef5f.o:hello.cpp:function __llvm_profile_init: error: undefined reference to '__llvm_profile_register_function'
/tmp/hello-58ef5f.o:hello.cpp:function __llvm_profile_runtime_user: error: undefined reference to '__llvm_profile_runtime'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Clang 版本: clang 版本 3.5.0

操作系统: Ubuntu 14.04

LD版本:GNU gold (GNU Binutils 2.24.51.20140522) 1.11

LLVM 配置选项: configure --enable-profiling --enable-optimized --enable-shared --disable-debug-runtime --enable-targets=all --prefix=/install --with-binutils-include=/gold_linker/binutils/include

以上错误显示“使用 -v”。 -v的输出如下

 "/usr/local/bin/ld" -z relro --hash-style=gnu --build-id --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.8/crtbegin.o -L/usr/lib/gcc/x86_64-linux-gnu/4.8 -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../.. -L/home/LLVM_install/bin/../lib -L/lib -L/usr/lib /tmp/hello-c8552f.o /home/LLVM_install/bin/../lib/clang/3.5.0/lib/linux/libclang_rt.profile-x86_64.a -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-linux-gnu/4.8/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crtn.o
/tmp/hello-c8552f.o:hello.cpp:function __llvm_profile_init: error: undefined reference to '__llvm_profile_register_function'
/tmp/hello-c8552f.o:hello.cpp:function __llvm_profile_init: error: undefined reference to '__llvm_profile_register_function'
/tmp/hello-c8552f.o:hello.cpp:function __llvm_profile_init: error: undefined reference to '__llvm_profile_register_function'
/tmp/hello-c8552f.o:hello.cpp:function __llvm_profile_init: error: undefined reference to '__llvm_profile_register_function'
/tmp/hello-c8552f.o:hello.cpp:function __llvm_profile_runtime_user: error: undefined reference to '__llvm_profile_runtime'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

最佳答案

如果您使用 cmake 构建 llvm 和编译器-rt,则不会出现此问题。但是,如果您在构建 llvm 和编译器-rt 时使用configure,则会出现此问题。

#Step-1) Build your LLVM compiler as follows
cd /home/user
git clone http://llvm.org/git/llvm.git
cd llvm/tools
git clone http://llvm.org/git/clang.git
cd ../../
mkdir build_folder
cd build_folder
cmake /home/user/llvm
cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=X86 -DCMAKE_INSTALL_PREFIX=/home/user/llvm_install /home/user/llvm
make
make install

#Step-2) Build compiler-rt as follows. Use llvm-config from your llvm installation from above step-1
git clone http://llvm.org/git/compiler-rt.git
mkdir comp_rt_build_dir
cd comp_rt_build_dir
cmake ../compiler-rt -DLLVM_CONFIG_PATH=/path/to/llvm-config
make
make install

关于LLVM、-fprofile-instr-generate、对“__llvm_profile_register_function”的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24606402/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com