Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting "nvcc fatal : redefinition of argument 'optimize'"?

I am trying to compile on MacBook Pro Retina with CUDA Driver Version: 7.0.36 and cuda toolkit 7.0 in a nVidia GT 750 M, the following code with its makefile but it gives me this error:

nvcc fatal : redefinition of argument 'optimize'.

Despite I have been able to compile and execute other programes with nvcc, with makefiles and so, now I am not.

Also, I have not been able to find something useful about this error so I ask it here if someone knows how to solve it. I am new with CUDA so if you need more information please ask for it.

Here is my Makefile.inc:

CXX             := nvcc
OPTIM           := -O3
DEBUG           := -g -DOLB_DEBUG
CXXFLAGS        := $(OPTIM)
ARPRG           := ar
LDFLAGS         := -O3
PARALLEL_MODE   := OFF
OMPFLAGS        := -fopenmp
BUILDTYPE       := precompiled
INPUTDIR        := ./input
OUTPUTDIR       := ./output
INCDIR          := ./inc
OBJDIR          := ./obj
SRCDIR          := ./HeatTransfer
BINDIR          := ./bin
###########################################################################
## defines shell
SHELL           := /bin/sh

and the Makefile:

###########################################################################
ROOT := .
include $(ROOT)/Makefile.inc
######################################################## Operational system
OS     = $(shell uname -s)
MACH   = $(shell uname -m)
HOST   = $(shell uname -n)
WHOAMI = $(shell whoami  )
###########################################################################
HeatTransfer := \
mesh\
stack
PROGRAM := $(BINDIR)/program
###########################################################################
OBJECTS := $(foreach file, $(HeatTransfer), $(OBJDIR)/$(file).o)
###########################################################################
all : compile link
###########################################################################
compile : $(OBJECTS)

$(OBJDIR)/%.o: $(SRCDIR)/%.cu
        @echo Compile $<
        $(CXX) $(CXXFLAGS) -I$(INCDIR) -c $< -o $@
###########################################################################
link: $(PROGRAM)

$(PROGRAM): $(OBJECTS)
        @echo Link $@
        $(CXX) $(LDFLAGS) -I$(INCDIR) $(foreach file, $(HeatTransfer), $(OBJDIR)/$(file).o) $(LDFLAGS) -I$(INCDIR) -o $@
###########################################################################
clean : cleanprog cleanobj

cleanprog: 
        @echo Clean rubbish files
        @rm -f *~ core .tmpfile $(PROGRAM)

cleanobj:
        @echo Clean object files
        @rm -f $(OBJECTS)
###########################################################################
###########################################################################

The complete messege when I try to compile is this:

...Heat_Transfer_CUDA$ make
Compile HeatTransfer/mesh.cu
nvcc -O3 -I./inc -c HeatTransfer/mesh.cu -o obj/mesh.o
Compile HeatTransfer/stack.cu
nvcc -O3 -I./inc -c HeatTransfer/stack.cu -o obj/stack.o
Link bin/program
nvcc -O3 -I./inc  ./obj/mesh.o  ./obj/stack.o -O3 -I./inc -o bin/program
nvcc fatal   : redefinition of argument 'optimize'
make: *** [bin/program] Error 1
like image 388
Alfonso Aguilar Avatar asked Apr 17 '15 18:04

Alfonso Aguilar


1 Answers

The problem is arising due to the fact that your link command is specifying the -O3 switch twice:

nvcc -O3 -I./inc  ./obj/mesh.o  ./obj/stack.o -O3 -I./inc -o bin/program
     ^^^                                      ^^^

And this is not allowed - it will produce that error.

The problem seems to occur due to the fact that your makefile specifies the use of LDFLAGS twice here:

    $(CXX) $(LDFLAGS) -I$(INCDIR) $(foreach file, $(HeatTransfer), $(OBJDIR)/$(file).o) $(LDFLAGS) -I$(INCDIR) -o $@

which should not be necessary. Something like this instead:

    $(CXX) $(LDFLAGS) -I$(INCDIR) $(foreach file, $(HeatTransfer), $(OBJDIR)/$(file).o) -o $@

should probably fix the issue.

like image 71
Robert Crovella Avatar answered Sep 20 '22 02:09

Robert Crovella