我正在尝试使用 OpenMP for ARM Linux 交叉编译一个程序。 当我将 -fopenmp 标志添加到编译链时,出现以下错误:
arm-xilinx-linux-gnueabi-gcc: error: libgomp.spec: No such file or directory
我不确定编译器应该在哪里寻找这个文件。在 libgomp.spec 上使用 locate 显示:
locate libgomp.spec
/home/Xilinx/Vivado_HLS/2014.4/lnx32/tools/gcc/lib/libgomp.spec
/usr/lib/gcc/i686-linux-gnu/4.7/libgomp.spec
/usr/lib/gcc/i686-linux-gnu/4.8/libgomp.spec
/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/libgomp.spec
我应该将此文件移动到其他预期路径吗?它应该在哪里?
最佳答案
我也在研究这个。查看 arm-xilinx-linux-gnueabi-gcc
本身的配置选项,似乎使用 --disable-libgomp
禁用了 libgomp
:
$ arm-xilinx-linux-gnueabi-gcc -v
- Using built-in specs.
- COLLECT_GCC=arm-xilinx-linux-gnueabi-gcc
- COLLECT_LTO_WRAPPER=/opt/Xilinx/SDK/2015.2/gnu/arm/lin/bin/../libexec/gcc/arm-xilinx-linux-gnueabi/4.9.1/lto-wrapper
- Target: arm-xilinx-linux-gnueabi
- Configured with:
/scratch/cltang/xilinx/linux/src/gcc-4.9-2014.11/configure
--build=i686-pc-linux-gnu --host=i686-pc-linux-gnu
--target=arm-xilinx-linux-gnueabi --enable-threads
...
--disable-libgomp --disable-libitm --enable-libatomic
--disable-libssp --enable-poison-system-directories
- Thread model: posix
- gcc version 4.9.1 (Sourcery CodeBench Lite 2014.11-30)
我们需要一个启用此配置的 arm-linux-gnueabi
编译器,或者自己交叉编译。
[编辑]
从您的发行版存储库安装 arm-linux-gnueabi-gcc
。就我而言,XUbuntu 14.04:
sudo apt-get install gcc-arm-linux-gnueabi
libgomp
在查看其规范 (arm-linux-gnueabi-gcc -v
) 时未显示为禁用。
在 PetaLinux 中使用的 Makefile 中需要进行以下更改以生成示例 hello.c
应用程序。注意使用 -static
来避免与 libgopt
共享对象的动态链接,仅在您的主机中可用。
# <petalinux_project>/components/apps/hello/Makefile
ifndef PETALINUX
$(error "Error: PETALINUX environment variable not set. Change to the root of your PetaLinux install, and source the settings.sh file")
endif
include apps.common.mk
APP = hello
# Add any other object files to this list below
APP_OBJS = hello.o
all: build install
build: $(APP)
## -> + Replaced: $(CC) with arm-linux-gnueabi-gcc
## -> + Added: -fopenmp -static
$(APP): $(APP_OBJS)
arm-linux-gnueabi-gcc $(LDFLAGS) -fopenmp -static -o $@ $(APP_OBJS) $(LDLIBS)
clean:
-rm -f $(APP) *.elf *.gdb *.o
.PHONY: install image
install: $(APP)
$(TARGETINST) -d $(APP) /bin/$(APP)
## -> + Replaced: $(CC) with arm-linux-gnueabi-gcc
## -> + Added: -fopenmp
%.o: %.c
arm-linux-gnueabi-gcc -c $(CFLAGS) -fopenmp -o $@ $<
help:
@echo ""
@echo "Quick reference for various supported build targets for $(INSTANCE)."
@echo "----------------------------------------------------"
@echo " clean clean out build objects"
@echo " all build $(INSTANCE) and install to rootfs host copy"
@echo " build build subsystem"
@echo " install install built objects to rootfs host copy"
为完整起见,以下是hello.c
示例代码:
/*
* Placeholder PetaLinux user application.
*
* Replace this with your application code
*/
#include <stdio.h>
#include <omp.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("Hello, PetaLinux World!\n");
printf("cmdline args:\n");
while(argc--)
printf("%s\n",*argv++);
#pragma omp parallel
printf("Hello from thread %d, nthreads %d\n",
omp_get_thread_num(),
omp_get_num_threads());
return 0;
}
最后,从 PetaLinux 框架构建和 jtag 传输:
<petalinux_project>$ petalinux-build -v -c rootfs/hello
<petalinux_project>$ petalinux-build -x package
<petalinux_project>$ petalinux-boot --jtag --fpga --bitstream pre-built/linux/implementation/download.bit --u-boot --kernel
关于linux - 使用 openMP 交叉编译到 ARM-linux 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34549130/