无法在Mac OS X El Capitan

时间:2016-06-11 13:44:02

标签: linux macos opengl makefile cuda

我正在大学写一个包含OpenGL和CUDA代码的程序,我可以用Ubuntu Linux运行它。该程序有很多依赖项,所以我使用makefile,当我在Linux大学时我没有问题。昨天我试着在家里的MacBook上运行它并没有运行。我正确地设置了库路径,但是当我尝试使用makefile进行编译时,我得到以下几行:

MBP-di-Nicolo:MATRIX_TEST Nico$ make
/Developer/NVIDIA/CUDA-7.5/bin/nvcc -ccbin g++   -m64  -Xcompiler -g -Xcompiler -arch -Xcompiler x86_64   -g -G -Xlinker -rpath -Xlinker /Developer/NVIDIA/CUDA-7.5/lib   -Xlinker -framework -Xlinker GLUT -o Matrix_test my_utils2.o Matrix_test.o Matrix.o -L/System/Library  -L/System/Library/Frameworks/OpenGL.framework/Libraries  -lGL -lGLU ../../common/lib/darwin/libGLEW.a -L. -lrt
nvlink fatal   : Could not find fatbin in 'my_utils2.o'
nvlink fatal   : elfLink internal error
make: *** [Matrix_test] Error 1
MBP-di-Nicolo:MATRIX_TEST Nico$ 

这是makefile:

PROGNAME = Matrix_test
#PROGNAME2 = read_file

CC = g++

include ./findcudalib.mk

# Location of the CUDA Toolkit
CUDA_PATH ?= /Developer/NVIDIA/CUDA-7.5


#DEK_SRC = ../pure-dek/src
#DEK_INCLUDE = -I../pure-dek/include

# internal flags
NVCCFLAGS   := -m${OS_SIZE} 
#NVCCFLAGS   := -m${OS_SIZE} --keep
CCFLAGS     := -g 
NVCCLDFLAGS := -g -G
LDFLAGS     :=

# Extra user flags
EXTRA_NVCCFLAGS   ?=
EXTRA_NVCCLDFLAGS ?=
EXTRA_LDFLAGS     ?=
EXTRA_CCFLAGS     ?=

# OS-specific build flags
ifneq ($(DARWIN),) 
 LDFLAGS += -rpath $(CUDA_PATH)/lib
 CCFLAGS += -arch $(OS_ARCH) $(STDLIB)  
else
 ifeq ($(OS_ARCH),armv7l)
 ifeq ($(abi),gnueabi)
  CCFLAGS += -mfloat-abi=softfp
else
  # default to gnueabihf
  override abi := gnueabihf
  LDFLAGS += --dynamic-linker=/lib/ld-linux-armhf.so.3
  CCFLAGS += -mfloat-abi=hard
endif
endif
endif

ifeq ($(ARMv7),1)
NVCCFLAGS += -target-cpu-arch ARM
ifneq ($(TARGET_FS),) 
CCFLAGS += --sysroot=$(TARGET_FS)
LDFLAGS += --sysroot=$(TARGET_FS)
LDFLAGS += -rpath-link=$(TARGET_FS)/lib
LDFLAGS += -rpath-link=$(TARGET_FS)/usr/lib
LDFLAGS += -rpath-link=$(TARGET_FS)/usr/lib/arm-linux-$(abi)
endif
endif

# Debug build flags 
ifeq ($(dbg),1)
  NVCCFLAGS += -g -G
  TARGET := debug
else
  TARGET := release
endif

ALL_CCFLAGS :=
ALL_CCFLAGS += $(NVCCFLAGS)
ALL_CCFLAGS += $(addprefix -Xcompiler ,$(CCFLAGS))
ALL_CCFLAGS += $(EXTRA_NVCCFLAGS)
ALL_CCFLAGS += $(addprefix -Xcompiler ,$(EXTRA_CCFLAGS))

ALL_LDFLAGS :=
ALL_LDFLAGS += $(ALL_CCFLAGS)
ALL_LDFLAGS += $(NVCCLDFLAGS)
ALL_LDFLAGS += $(addprefix -Xlinker ,$(LDFLAGS))
ALL_LDFLAGS += $(EXTRA_NVCCLDFLAGS)
ALL_LDFLAGS += $(addprefix -Xlinker ,$(EXTRA_LDFLAGS))

# Common includes and paths for CUDA
EXT_LIB = /System/Library
INCLUDES  := 
LIBRARIES := -L$(EXT_LIB) 

# Makefile include to help find GL Libraries
EXEC            ?=
include ./findgllib.mk

# OpenGL specific libraries 
ifneq ($(DARWIN),)
# Mac OSX specific libraries and paths to include
 LIBRARIES += -L/System/Library/Frameworks/OpenGL.framework/Libraries 
 LIBRARIES += -lGL -lGLU ../../common/lib/darwin/libGLEW.a
 ALL_LDFLAGS += -Xlinker -framework -Xlinker GLUT
else
 LIBRARIES += -L../../common/lib/$(OSLOWER)/$(OS_ARCH) $(GLLINK)
 #LIBRARIES += -lglfw3 -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor -lGL -lpthread -ldl -lGLEW -lglut -lGLU
 LIBRARIES += -lglui -lglut -lGLU -lGL -lX11 -lXi -lXmu -lGLEW
endif

  ################################################################################

 # CUDA code generation flags
ifneq ($(OS_ARCH),armv7l)
GENCODE_SM10    := -gencode arch=compute_11,code=sm_11
endif
GENCODE_SM10    := -gencode arch=compute_11,code=sm_11
GENCODE_SM20    := -gencode arch=compute_20,code=sm_20
GENCODE_SM30    := -gencode arch=compute_30,code=sm_30 -gencode          arch=compute_35,code=\"sm_35,compute_35\"
GENCODE_FLAGS   := $(GENCODE_SM11) $(GENCODE_SM20) $(GENCODE_SM30) 

################################################################################

# Target rules
all: build

build: $(PROGNAME) 


my_utils2.o: my_utils2.cu my_utils2.h
$(NVCC) $(INCLUDES) $(ALL_CCFLAGS) $(GENCODE_FLAGS) -o $@ -c $<

Matrix.o: Matrix.cu Matrix.h my_utils2.h
$(NVCC) $(INCLUDES) $(ALL_CCFLAGS) $(GENCODE_FLAGS) -o $@ -c $<

Matrix_test.o: Matrix_test.cu my_utils2.h
$(NVCC) $(INCLUDES) $(ALL_CCFLAGS) $(GENCODE_FLAGS) -o $@ -c $<


$(PROGNAME): my_utils2.o Matrix_test.o Matrix.o  
$(NVCC) $(ALL_LDFLAGS) -o $@ $+ $(LIBRARIES) -L. -lrt
mkdir -p ./bin/$(OS_ARCH)/$(OSLOWER)/$(TARGET)$(if $(abi),/$(abi))
cp $@ ./bin/$(OS_ARCH)/$(OSLOWER)/$(TARGET)$(if $(abi),/$(abi))

run: build
./$(PROGNAME)

clean:
rm -f *.o
#   rm -rf ./bin/$(OS_ARCH)/$(OSLOWER)/$(TARGET)$(if $(abi),/$(abi))/mergeSort

clobber: clean

我没有修改用于Linux的makefile,除了两行(以下是旧行):

# Location of the CUDA Toolkit
CUDA_PATH ?= "/usr/local/cuda-7.5"

# Common includes and paths for CUDA
EXT_LIB = /usr/local/lib

你能帮我吗?

非常感谢!!

1 个答案:

答案 0 :(得分:2)

您不必使用nvcc链接最终程序。事实上,我强烈反对。 nvcc应仅用于编译.cu文件,其余文件留给gcc / g ++ / clang。

一般来说,迫使nvcc使用特定的编译器是个坏主意。只是让它选择它的默认值。我没有在你发布的Makefile中看到(可能在findcuda.mk中)变量NVCC的定义,我怀疑是否配置了--ccbin标志。

此外,在MacOS X中,OpenGL框架涵盖了OpenGL。库libGL / libGLU用于通过X11服务器(可在MacOS X中使用)运行的支持程序,但MacOS X的X11 / GLX / OpenGL支持是兼容层,不支持CUDA。

因此我建议你改变如下:

LIBRARIES += ../../common/lib/darwin/libGLEW.a
LDFLAGS += -framework GLUT -framework OpenGL

all: build install

$(PROGNAME): my_utils2.o Matrix_test.o Matrix.o  
    $(LD) $(LDFLAGS) -o $@ $+ $(LIBRARIES) -L.

install: $(PROGNAME)
    mkdir -p ./bin/$(OS_ARCH)/$(OSLOWER)/$(TARGET)$(if $(abi),/$(abi))
    cp $@ ./bin/$(OS_ARCH)/$(OSLOWER)/$(TARGET)$(if $(abi),/$(abi))