I want to use opemmp with clang compile in Windows and here is my compile command:
clang++ 1.cpp -o 1.exe -fopenmp=libomp -I=\"C:\\Program Files\\LLVM\\lib\\clang\\9.0.0\\include\" -L=\"C:\\Program Files\\LLVM\\bin\" -Wall -g -O2 -static-libgcc --target=x86_64-w64-mingw -std=c++17
and there is an error:
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\ld.exe: cannot find -lomp
clang: error: linker command failed with exit code 1 (use -v to see invocation)
but I have the "libomp.lib" file and write the link path in command argument. How to solve it?
Thanks!
Related
I prepare two very simple c files, main.c and test.c, and use the below command to compile them:
clang --target=aarch64 -c main.c
clang --target=aarch64 -c test.c
But when I use the command clang --target=aarch64 -fuse-ld=lld -v main.o test.o, it actually invoke "/usr/bin/gcc" -fuse-ld=lld
root#6ab3fca322b6:/home/example# clang --target=aarch64 -fuse-ld=lld -v main.o test.o
clang version 13.0.0
Target: aarch64
Thread model: posix
InstalledDir: /usr/local/bin
"/usr/bin/gcc" -fuse-ld=lld -o a.out main.o test.o
ld.lld: error: main.o is incompatible with elf64-x86-64
ld.lld: error: test.o is incompatible with elf64-x86-64
collect2: error: ld returned 1 exit status
clang-13: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)
But if I manually invoke ld.lld, everything there is no problem just a warning about "cannot find entry symbol _start;".
ld.lld main.o test.o
Also I try to remove the flag --target=aarch64, it still failed:
root#6ab3fca322b6:/home/example# clang -v main.o test.o
clang version 13.0.0
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Candidate multilib: .;#m64
Candidate multilib: 32;#m32
Candidate multilib: x32;#mx32
Selected multilib: .;#m64
"/usr/bin/ld" -z relro --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out /lib/x86_64-linux-gnu/crt1.o /lib/x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/9/crtbegin.o -L/usr/lib/gcc/x86_64-linux-gnu/9 -L/usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib64 -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib64 -L/usr/local/bin/../lib -L/lib -L/usr/lib main.o test.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-linux-gnu/9/crtend.o /lib/x86_64-linux-gnu/crtn.o
ld: error: main.o is incompatible with elf64-x86-64
ld: error: test.o is incompatible with elf64-x86-64
clang-13: error: linker command failed with exit code 1 (use -v to see invocation)
I have soft linked the /usr/bin/ld to /usr/bin/ld.lld, but I don't know why it adds some many flags which I don't specify, e.g., -z relro --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2
So my questions are:
why clang --target=aarch64 -fuse-ld=lld can't invoke ld.lld?
why clang can invoke /usr/bin/ld but add some many unspecified flags?
For aarch64, which is the correct way to make clang correctly invoke ld.lld?
I am using clang and lld 13.0.0.
Best Regards,
Simon
In macOS Sierra, installation for xgboost with openmp enabled always fails.
From https://xgboost.readthedocs.io/en/latest/build.html,
I've tried:
cp make/config.mk ./config.mk; make -j4
With,
export CC=/usr/local/Cellar/llvm/4.0.0_1/bin/clang
export CXX=/usr/local/Cellar/llvm/4.0.0_1/bin/clang++
export CXX1X=/usr/local/Cellar/llvm/4.0.0_1/bin/clang++
It fails with,
clang-4.0clang-4.0: : warning: argument unused during compilation: '-pthread' [-Wunused-command-line-argument]warning:
argument unused during compilation: '-pthread' [-Wunused-command-line-argument]
ld: library not found for -lomp
ld: library not found for -lomp
clang-4.0: error: linker command failed with exit code 1 (use -v to see invocation)
llvm support openmp, but it fails with ld: library not found for -lomp
related question
Install xgboost on Mac - ld: library not found
But, clang-omp goes to boneyard, and discontinue with llvm's OpenMP support.
I've drilled down to, (with -v option)
/usr/local/Cellar/llvm/4.0.0_1/bin/clang++ -std=c++11 -Wall -Wno-unknown-pragmas -Iinclude -Idmlc-core/include -Irabit/include -I/include -O3 -funroll-loops -msse2 -fPIC -fopenmp -shared -o lib/libxgboost.so build/learner.o build/logging.o build/c_api/c_api.o build/c_api/c_api_error.o build/common/common.o build/common/hist_util.o build/data/data.o build/data/simple_csr_source.o build/data/simple_dmatrix.o build/data/sparse_page_dmatrix.o build/data/sparse_page_raw_format.o build/data/sparse_page_source.o build/data/sparse_page_writer.o build/gbm/gblinear.o build/gbm/gbm.o build/gbm/gbtree.o build/metric/elementwise_metric.o build/metric/metric.o build/metric/multiclass_metric.o build/metric/rank_metric.o build/objective/multiclass_obj.o build/objective/objective.o build/objective/rank_obj.o build/objective/regression_obj.o build/tree/tree_model.o build/tree/tree_updater.o build/tree/updater_colmaker.o build/tree/updater_fast_hist.o build/tree/updater_histmaker.o build/tree/updater_prune.o build/tree/updater_refresh.o build/tree/updater_skmaker.o build/tree/updater_sync.o dmlc-core/libdmlc.a rabit/lib/librabit.a -pthread -lm -fopenmp
SOLVED
cd /usr/local/lib
ln -s /usr/local/Cellar/llvm/4.0.0_1/lib/libomp.dylib libomp.dylib
llvm installation miss its symbolic link.
In my case I solved adding the following linker flag in addition to -lomp:
-Lpath_to_libomp.dylib_folder
or something like:
-Llib/
In my case I used a version of clang that came with Homebrew's llvm instead of the one that came with the Laptop from the factory, and it worked.
I am trying to build lua-5.3.1 in Red Hat Enterprise Linux 6.6 platform. Following binaries will be build :
shared library : liblua.so
executable : lua
executable : luac
I have made the following changes in the provided Makefile :
Existing :
CC= gcc -std=gnu99
LUA_A= liblua.a
$(LUA_A): $(BASE_O)
$(AR) $# $(BASE_O)
$(RANLIB) $#
Modified :
CC= gcc -fPIC
LUA_A= liblua.so
$(LUA_A): $(BASE_O)
$(CC) -mthreads -shared -o $(LUA_A) $(BASE_O)
'liblua.so' and 'lua' have been built successfully using the modified Makefile. But during 'luac' build following linking error is coming :
gcc -fPIC -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_USE_LINUX -c -o luac.o luac.c
gcc -fPIC -o luac luac.o liblua.so -lm -Wl,-E -ldl -lreadline
luac.o: In function `PrintFunction':
luac.c:(.text+0x947): undefined reference to `luaP_opnames'
luac.c:(.text+0x963): undefined reference to `luaP_opmodes'
luac.o: In function `pmain':
luac.c:(.text+0x11db): undefined reference to `luaU_dump'
/usr/bin/ld: luac: hidden symbol `luaU_dump' isn't defined
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: ld returned 1 exit status
make[1]: *** [luac] Error 1
make[1]: Leaving directory `/disk1/u10rhel66/lua-5.3.1/src'
make: *** [linux] Error 2
Any help will be appreciated.
luac must be built statically linked with liblua.a.
If you really want luac linked dynamically, try this:
remove LUAI_DDEF and LUAI_DDEC from lopcodes.c and lopcodes.h
remove LUAI_FUNC from lundump.h
rebuild
I am trying to use llvm-lld to link an object that has been compiled with -flto.
I have the ld in the path call lld with all the arguments provided.
I created a simple C++ program, which I compile with clang++:
#include <stdio.h>
int main() {
printf("Goodbye cruel world\n");
return 0;
}
Without the -flto flag I get an executable, with the -flto I get this error:
warning: ignoring unknown argument: -plugin
warning: ignoring unknown argument: -plugin-opt=mcpu=x86-64
Cannot open /tmp/a-f1a2a7.o: Exec format error
clang-3.8: error: linker command failed with exit code 1 (use -v to see invocation)
Here are the arguments being passed to the linker, I see that with -flto the plugin arguments are provided include this plugin option, yet it seems to be unsupported.
--eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out /usr/lib64/gcc/x86_64-pc-linux-gnu/5.2.0/../../../../lib64/crt1.o /usr/lib64/gcc/x86_64-pc-linux-gnu/5.2.0/../../../../lib64/crti.o /usr/lib64/gcc/x86_64-pc-linux-gnu/5.2.0/crtbegin.o -L/usr/lib64/gcc/x86_64-pc-linux-gnu/5.2.0 -L/usr/lib64/gcc/x86_64-pc-linux-gnu/5.2.0/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib64/gcc/x86_64-pc-linux-gnu/5.2.0/../../../../x86_64-pc-linux-gnu/lib -L/usr/lib64/gcc/x86_64-pc-linux-gnu/5.2.0/../../.. -L/mnt/data/tmp/dev/llvm/prev/bin/../lib -L/lib -L/usr/lib -plugin /mnt/data/tmp/dev/llvm/prev/bin/../lib/LLVMgold.so -plugin-opt=mcpu=x86-64 /tmp/a-f1a2a7.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib64/gcc/x86_64-pc-linux-gnu/5.2.0/crtend.o /usr/lib64/gcc/x86_64-pc-linux-gnu/5.2.0/../../../../lib64/crtn.o
Is there a way for lld to link this code?
Yes, you can do it by using gold-linker which supports LTO via plugins:
Here is the instructions how to build and run it
I'm trying to compile GNU bash 4.3.30 on (and for) my iPad 2, iOS 8.4 using Clang, ld64, cctools, GNU make and the iOS 8.1 SDK. When processing bashversion, Clang is "unable to execute dsymutil", and reports that it "doesn't exist", exiting with error 1.
$ make
(...)
"/usr/bin/ld" -demangle -dynamic -arch armv7 -iphoneos_version_min 5.0.0 -syslibroot /var/mobile/iPhoneOS8.1.sdk -o bashversion -lcrt1.3.1.o -L./lib/termcap /var/tmp/bashversion-814fa1.o buildversion.o -lSystem
"dsymutil" -o bashversion.dSYM bashversion
clang: error: unable to execute command: Executable "dsymutil" doesn't exist!
clang: error: dsymutil command failed with exit code 1 (use -v to see invocation)
make: *** [bashversion] Error 1
$ echo $CC
clang --sysroot /var/mobile/iPhoneOS8.1.sdk -v
$ clang --version
clang version 3.5.0 (trunk)
Target: armv7-apple-darwin-14.0.0
Thread model: posix
$ ld -v
#(#)PROGRAM:ld PROJECT:ld64-
configured to support archs: i386 x86_64 armv4t armv5 armv6 armv7 armv7f armv7k armv8 arm64 arm64v8
$ which dsymutil
$ dsymutil
-sh: dsymutil: command not found
$ find / -name dsymutil
$
Apparently, my iPad has no dsymutil. So, where can I find one? Does it come with Xcode? Or is there any way to compile GNU bash 4.3.30 without it?
Dsymutil is a closed source tool, and is not available for iOS.
But that's not much of a problem, just create a symlink to /bin/true,
i.e.
ln -s /bin/true /usr/bin/dsymutil