RISCV的交叉编译

时间:2015-02-16 00:46:58

标签: linux gcc makefile cross-compiling riscv

我有一个C程序,我想为RISCV ISA编译它。我按照他们的指示安装了这些工具。他们的工具正常工作,我可以编译一个#Hello; Hello world!" C程序并运行它。但是现在我想编译另一个包含多个文件的C程序。我试图更改makefile而不是使用gcc,我用它们的编译器名称riscv64-unknown-linux-gnu-gcc替换它,但我得到了:

Relocations in generic ELF (EM: 62)

错误,然后我尝试设置CC = riscv64-unknown-linux-gnu-gcc,但我收到了另一个关于pthread的错误

unrecognized command line option '-pthread'

我的问题是我应该更改make文件以使用他们的编译器吗?

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

DEBUG := 0
PROFILE := 0
MRSFAST_VERSION := "3.3.1"
BUILD_DATE := "$(shell date)"

all: OPTIMIZE_FLAGS build
debug: DEBUG_FLAGS build
profile: PROFILE_FLAGS build
build: clean-executable SSE_FLAGS compile mrsfast snp_indexer clean

LDFLAGS=#-static
LIBS=-lz -lm -pthread -lpthread
CFLAGS=-fno-pic -DMRSFAST_VERSION=\"$(MRSFAST_VERSION)\" -DBUILD_DATE=\"$(BUILD_DATE)\"

objects=baseFAST.o Sort.o MrsFAST.o Common.o CommandLineParser.o RefGenome.o HashTable.o Reads.o Output.o SNPReader.o  HELP.o

compile: $(objects)

mrsfast:
ifeq ($(shell uname -s),Linux)
    gcc -w $(objects) -o $@ ${LDFLAGS} ${LIBS}
else
    gcc -Wl,-no_pie -fno-pic -w $(objects) -o $@ ${LDFLAGS} ${LIBS}
endif

snp_indexer: SNPIndexer.o
    gcc $^ -o $@ ${LDFLAGS} ${LIBS}

clean:
    @rm -f $(objects)
    @rm -f SNPIndexer.o
    @rm -f HELPstub.c
    @rm -f HELPstub.o

clean-executable:
    @rm -f mrsfast

HELP.o:
    @groff -Tascii -man ./HELP.man > HELP
ifeq ($(shell uname -s),Linux)
    @ld -r -b binary -o HELP.o HELP
else
    @touch HELPstub.c
    gcc -o HELPstub.o -c HELPstub.c
    ld -r -o HELP.o -sectcreate binary HELP HELP HELPstub.o
endif

DEBUG_FLAGS:
    $(eval CFLAGS = $(CFLAGS) -ggdb)
    $(eval LIBS = $(LIBS) -ggdb)

OPTIMIZE_FLAGS:
    $(eval CFLAGS = $(CFLAGS) -O2)

PROFILE_FLAGS:
        $(eval CFLAGS = $(CFLAGS) -pg -g)
    $(eval LIBS = $(LIBS) -pg -g)

SSE_FLAGS:
ifeq ($(shell uname -s),Linux)
ifeq ($(with-sse4),no)
        $(shell echo "-DSSE4=0")
else
            $(eval CFLAGS = $(CFLAGS) \
            $(shell gv=`gcc -dumpversion`; \
                    sc=`grep -c "sse4" /proc/cpuinfo`; \
                    echo $$sc.$$gv | awk -F. '{if($$1>0 && $$2>=4 && $$3>=4) print "-DSSE4=1 -msse4.2"; else print "-DSSE4=0"}'))
endif
else
ifeq ($(with-sse4),no)
        $(shell echo "-DSSE4=0")
else
        $(eval CFLAGS = $(CFLAGS) \
        $(shell gv=`gcc -dumpversion`; \
                sc=`sysctl -n machdep.cpu.features | grep -c "SSE4"` ;\
                echo $$sc.$$gv | awk -F. '{if($$1>0 && $$2>=4 && $$3>=4) print "-DSSE4=1 -msse4.2"; else print "-DSSE4=0"}'))
endif
endif