orta1986 发表于 2023-3-6 10:52:02

如何修改make指令的参数(basename)

大家好,最近有一个关于在树莓派下做C开发的问题。
老外给了我一套程序,需要重新编译,其makefile 如下:

LIBS = -L . -lftd3xx
# Static link to D3XX library, please use Ubuntu 14.04 to compile
#LIBS = -L . -lftd3xx-static -lstdc++-static

ifneq ("$(wildcard ftd3xx.dll)","")
# === Windows ===
ifneq (,$(findstring PE32+,$(shell file ftd3xx.dll)))
        CROSS_COMPILE := x86_64-w64-mingw32-
else
        CROSS_COMPILE := i686-w64-mingw32-
endif
AS = $(CROSS_COMPILE)as
LD = $(CROSS_COMPILE)ld
CC = $(CROSS_COMPILE)gcc-posix
CXX = $(CROSS_COMPILE)g++-posix
OBJDUMP = $(CROSS_COMPILE)objdump

DEMO0=streamer.exe
DEMO1=rw.exe
DEMO2=file_transfer.exe
DEMO3=asyncstreamer.exe
DEMO4=async-loopback.exe
DEMO5=FTD3xx_Notification.exe
CXXLIBS = -static -lstdc++
# === End of Windows ===
else
# === Linux & macOS ===
DEMO0=streamer
DEMO1=rw
DEMO2=file_transfer
DEMO3=asyncstreamer
DEMO4=async-loopback
DEMO5=FTD3xx_Notification
ifneq ("$(wildcard libftd3xx.dylib)","")
# == macOS ==
ARCH=-m64
CXXLIBS =-lc++
# == End of macOS ==
else
# == Linux ==
ifneq (,$(findstring 64-bit,$(shell file libftd3xx.so)))
ARCH=-m64
else
ARCH=-m32
endif
LIBS += -pthread -lrt
CXXLIBS = -lstdc++
# == End of Linux ==
endif
# === End of Linux & macOS ===
endif

COMMON_FLAGS = -ffunction-sections -fmerge-all-constants $(ARCH)
COMMON_CFLAGS = -g -O3 -Wall -Wextra $(COMMON_FLAGS)
CFLAGS = -std=c99$(COMMON_CFLAGS) -D_POSIX_C_SOURCE
CXXFLAGS = -std=c++11 $(COMMON_CFLAGS)

all: $(DEMO0) $(DEMO1) $(DEMO2) $(DEMO3) $(DEMO4) $(DEMO5)
       
$(DEMO0): streamer.o
        $(CC) $(COMMON_FLAGS) -o $@ $^ $(CXXLIBS) $(LIBS)

$(DEMO1): rw.o
        $(CC) $(COMMON_FLAGS) -o $@ $^ $(LIBS)

$(DEMO2): file_transfer.o
        $(CC) $(COMMON_FLAGS) -o $@ $^ $(CXXLIBS) $(LIBS)

$(DEMO3): asyncstreamer.o
        $(CC) $(COMMON_FLAGS) -o $@ $^ $(CXXLIBS) $(LIBS)

$(DEMO4): async-loopback.o
        $(CC) $(COMMON_FLAGS) -o $@ $^ $(CXXLIBS) $(LIBS)

$(DEMO5): FTD3xx_Notification.o
        $(CC) $(COMMON_FLAGS) -o $@ $^ $(CXXLIBS) $(LIBS)

clean:
        -rm -f streamer.o rw.o file_transfer.o asyncstreamer.o async-loopback.o FTD3xx_Notification.o $(DEMO0) $(DEMO1) $(DEMO2) $(DEMO3) $(DEMO4) $(DEMO5)



当我运行make时,出现一个错误: g++: error: unrecognized command-line option '-m64'
我发邮件问老外,老外的答复是:
The same makefile is used for d2xx and d3xx for both Linux and Mac. To build d3xx, specify BASENAME=libftd3xx on the Make command line.

意思是说他们提供的 makefile是驱动d2xx和d3xx同时用在linux和mac系统,如果要编译d3xx,需要加入BASENAME=libftd3xx到make命令参数行。

可是我查了相关资料,BASENAME本身就是一个指令啊,好像不是从属于make下。 还是说BASENAME这个要加入到上述makefile中?如果要修改makefile的话,怎么改呢?
现在一头雾水,想请教一下大家

Himem 发表于 2023-3-6 11:22:56

本帖最后由 Himem 于 2023-3-6 11:25 编辑

把这段ifneq (,$(findstring 64-bit,$(shell file libftd3xx.so)))
ARCH=-m64
else
ARCH=-m32
endif删了就好了
当然我猜给的libftd3xx.so是x64架构不是arm的,去掉还有其他错

orta1986 发表于 2023-3-6 11:35:27

Himem 发表于 2023-3-6 11:22
把这段删了就好了
当然我猜给的libftd3xx.so是x64架构不是arm的,去掉还有其他错 ...
(引用自2楼)

谢谢大佬!!!!!!真的编译过了{:lol:}
页: [1]
查看完整版本: 如何修改make指令的参数(basename)