6

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
einpoklum
  • 118,144
  • 57
  • 340
  • 684
  • 2
    The posted code doesn't seem to be complete, that is, buildable. The issue is likely in code not shown. I would suggest using `grep` to find all instances of the symbol `optimize` in the source code, and setting that in relationship to the line number on which the compiler reports this error. – njuffa Apr 17 '15 at 18:50
  • 3
    Can you copy and paste the exact compile command and error message that occurred from the makefile into your question? Also which cuda version? And if it's not too much trouble, the contents of `mesh.h` ? Are you able to compile other programs or cuda sample codes correctly on your Mac ? – Robert Crovella Apr 17 '15 at 19:09
  • See my edit @RobertCrovella I hope there is everything you ask, but if I miss something or didn't get it right, ask me for it. The answer to your questions briefly, yes I can compile other programes with nvcc directly and through makefiles with nvcc. I have cudatoolkit 7.0 just updated from 6.5; but it seems to work fine, that's the version of cuda you meant? Thanks a lot. – Alfonso Aguilar Apr 18 '15 at 08:34
  • Sorry I forgot to mention you @njuffa , and I don't know if you read it. I did a simpler version of the code, but with the same error in order to simplify it. The thing is that I did use in the code nothing that stands for optimize, that's what you meant right? – Alfonso Aguilar Apr 18 '15 at 08:35

1 Answers1

10

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.

Yun
  • 3,056
  • 6
  • 9
  • 28
Robert Crovella
  • 143,785
  • 11
  • 213
  • 257
  • 3
    Good catch! It sure would be nice if the compiler gave a clearer error message. It is also not clear why this should be a fatal error, most compilers simply *ignore* redundant optimization flags and *warn* about conflicting ones. – njuffa Apr 18 '15 at 17:37