I am trying to set up the fastHOG codebase in my linux server, but unable to finish it as i am getting heap of link errors. I am giving here a sample portion of the link errors
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0x910): undefined reference to 'cudaGetErrorString'
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0x944): undefined reference to 'cudaGetErrorString'
/home/n8385106/bin/contrib/qut/qutanomaly/matlab/person- detector/fasthog/obj/release/HOG/HOGHistogram.cu.o: In function 'InitHistograms(int, int, int, int, int, float)':
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0xac0): undefined reference to 'cudaCreateChannelDesc'
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0xafe): undefined reference to 'cudaMallocArray'
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0xb46): undefined reference to 'cudaMemcpyToArray'
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0xc3d): undefined reference to 'cudaMemcpyToSymbol'
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0xc63): undefined reference to 'cudaMemcpyToSymbol'
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0xc89): undefined reference to 'cudaMemcpyToSymbol'
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0xcae): undefined reference to 'cudaMemcpyToSymbol'
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0xccd): undefined reference to 'cudaGetErrorString'
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0xd01): undefined reference to 'cudaGetErrorString'
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0xd15): undefined reference to 'cudaGetErrorString'
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0xd29): undefined reference to 'cudaGetErrorString'
tmpxft_00006d91_00000000-1_HOGHistogram.cudafe1.cpp:(.text+0xd3d): undefined reference to 'cudaGetErrorString'
It seems the linker didn't realize any of the linker libraries provided in the make file. It did not say anything like "was unable to find this library" but it avoided all the information provided about the libraries to be linked such as
# Libs
LIB := -L$(CUDA_INSTALL_PATH)/cuda/lib64 -L$(LIBDIR) - L$(COMMONDIR)/lib/$(OSLOWER)
# If dynamically linking to CUDA and CUDART, we exclude the libraries from the LIB
ifeq ($(USECUDADYNLIB),1)
LIB += ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) $(CUDPPLIB) ${LIB}
else
# static linking, we will statically link against CUDA and CUDART
ifeq ($(USEDRVAPI),1)
LIB += -lcuda ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) $(CUDPPLIB) ${LIB}
else
LIB += -lcudart ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) $(CUDPPLIB) ${LIB}
endif
endif
ifeq ($(USECUFFT),1)
ifeq ($(emu),1)
LIB += -lcufftemu
else
LIB += -lcufft
endif
endif
ifeq ($(USECUBLAS),1)
ifeq ($(emu),1)
LIB += -lcublasemu
else
LIB += -lcublas
endif
endif
I was able to create all the object files but problem is comming during the linking process, I am a newbie to CUDA, Can anyone please help me to sort this out?
My OS is 64 bit linux
Edited : My MakeFile
# Add source files here
EXECUTABLE := fastHOG
# C/C++ source files (compiled with gcc / c++)
CCFILES := \
fastHOG.cpp \
# HOG UTILS
CCUTILS := \
ImageWindow.cpp \
# CC HOG
CCHOG := \
HOGImage.cpp \
HOGEngine.cpp \
HOGNMS.cpp \
# CUDA HOG
CUFILES := \
HOGEngineDevice.cu \
HOGConvolution.cu \
HOGHistogram.cu \
HOGPadding.cu \
HOGScale.cu \
HOGSVMSlider.cu \
HOGUtils.cu \
################################################################################
# Rules and targets
include common.mk
Contents of the common.mk file
################################################################################
#
# Copyright 1993-2006 NVIDIA Corporation. All rights reserved.
#
################################################################################
#
# Common build script
#
################################################################################
.SUFFIXES : .cu .cu_dbg.o .c_dbg.o .cpp_dbg.o .cu_rel.o .c_rel.o .cpp_rel.o .cubin
#Add new SM Versions here as devices with new Compute Capability are released
SM_VERSIONS := sm_10 sm_11 sm_12 sm_13
CUDA_INSTALL_PATH ?= fasthoglib/cuda/cuda
ifdef cuda-install
CUDA_INSTALL_PATH := $(cuda-install)
endif
# detect OS
OSUPPER = $(shell uname -s 2>/dev/null | tr [:lower:] [:upper:])
OSLOWER = $(shell uname -s 2>/dev/null | tr [:upper:] [:lower:])
# 'linux' is output for Linux system, 'darwin' for OS X
DARWIN = $(strip $(findstring DARWIN, $(OSUPPER)))
# Basic directory setup for SDK
# (override directories only if they are not already defined)
SRCDIR ?=
SRCDIRUTILS ?= Utils
SRCDIRHOG ?= HOG
ROOTDIR ?= /home/n8385106/src/saivt-vxl/contrib/qut/qutanomaly/matlab/pedestrian-detector/fasthoglib/cuda/sdk
ROOTBINDIR ?= /home/n8385106/bin/contrib/qut/qutanomaly/matlab/person-detector/fasthog/bin
BINDIR ?= $(ROOTBINDIR)
ROOTOBJDIR ?= /home/n8385106/bin/contrib/qut/qutanomaly/matlab/person-detector/fasthog/obj
LIBDIR := $(ROOTDIR)/C/lib
COMMONDIR := $(ROOTDIR)/C/common
# Compilers
NVCC := $(CUDA_INSTALL_PATH)/bin/nvcc
CXX := g++
CC := gcc
LINK := g++ -fPIC
# Includes
INCLUDES += -I. -I$(CUDA_INSTALL_PATH)/cuda/include -I$(COMMONDIR)/inc
# architecture flag for cubin build
CUBIN_ARCH_FLAG := -m32
# Warning flags
CXXWARN_FLAGS := \
-W -Wall \
-Wimplicit \
-Wswitch \
-Wformat \
-Wchar-subscripts \
-Wparentheses \
-Wmultichar \
-Wtrigraphs \
-Wpointer-arith \
-Wcast-align \
-Wreturn-type \
-Wno-unused-function \
$(SPACE)
CWARN_FLAGS := $(CXXWARN_FLAGS) \
-Wstrict-prototypes \
-Wmissing-prototypes \
-Wmissing-declarations \
-Wnested-externs \
-Wmain \
# Compiler-specific flags
NVCCFLAGS :=
CXXFLAGS := $(CXXWARN_FLAGS)
CFLAGS := $(CWARN_FLAGS)
# Common flags
COMMONFLAGS += $(INCLUDES) -DUNIX
# Debug/release configuration
ifeq ($(dbg),1)
COMMONFLAGS += -g
NVCCFLAGS += -D_DEBUG
BINSUBDIR := debug
LIBSUFFIX := D
else
COMMONFLAGS += -O3
BINSUBDIR := release
LIBSUFFIX :=
NVCCFLAGS += --compiler-options -fno-strict-aliasing
CXXFLAGS += -fno-strict-aliasing
CFLAGS += -fno-strict-aliasing
endif
# append optional arch/SM version flags (such as -arch sm_11)
#NVCCFLAGS += $(SMVERSIONFLAGS)
# architecture flag for cubin build
CUBIN_ARCH_FLAG := -m32
# detect if 32 bit or 64 bit system
HP_64 = $(shell uname -m | grep 64)
# OpenGL is used or not (if it is used, then it is necessary to include GLEW)
ifeq ($(USEGLLIB),1)
ifneq ($(DARWIN),)
OPENGLLIB := -L/System/Library/Frameworks/OpenGL.framework/Libraries -lGL -lGLU $(COMMONDIR)/lib/$(OSLOWER)/libGLEW.a
else
OPENGLLIB := -lGL -lGLU -lX11 -lXi -lXmu
ifeq "$(strip $(HP_64))" ""
OPENGLLIB += -lGLEW -L/usr/X11R6/lib
else
OPENGLLIB += -lGLEW_x86_64 -L/usr/X11R6/lib64
endif
endif
CUBIN_ARCH_FLAG := -m64
endif
ifeq ($(USEGLUT),1)
ifneq ($(DARWIN),)
OPENGLLIB += -framework GLUT
else
OPENGLLIB += -lglut
endif
endif
ifeq ($(USEPARAMGL),1)
PARAMGLLIB := -lparamgl$(LIBSUFFIX)
endif
ifeq ($(USERENDERCHECKGL),1)
RENDERCHECKGLLIB := -lrendercheckgl$(LIBSUFFIX)
endif
USECUDPP := 1;
ifeq ($(USECUDPP), 1)
ifeq "$(strip $(HP_64))" ""
CUDPPLIB := -lcudpp
else
CUDPPLIB := -lcudpp64
endif
CUDPPLIB := $(CUDPPLIB)$(LIBSUFFIX)
ifeq ($(emu), 1)
CUDPPLIB := $(CUDPPLIB)_emu
endif
endif
# Libs
LIB := -L$(CUDA_INSTALL_PATH)/cuda/lib64 -L$(LIBDIR) -L$(COMMONDIR)/lib/$(OSLOWER)
# If dynamically linking to CUDA and CUDART, we exclude the libraries from the LIB
ifeq ($(USECUDADYNLIB),1)
LIB += ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) $(CUDPPLIB) ${LIB}
else
# static linking, we will statically link against CUDA and CUDART
ifeq ($(USEDRVAPI),1)
LIB += -lcuda ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) $(CUDPPLIB) ${LIB}
else
LIB += -lcudart ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) $(CUDPPLIB) ${LIB}
endif
endif
ifeq ($(USECUFFT),1)
ifeq ($(emu),1)
LIB += -lcufftemu
else
LIB += -lcufft
endif
endif
ifeq ($(USECUBLAS),1)
ifeq ($(emu),1)
LIB += -lcublasemu
else
LIB += -lcublas
endif
endif
# Lib/exe configuration
ifneq ($(STATIC_LIB),)
TARGETDIR := $(LIBDIR)
TARGET := $(subst .a,$(LIBSUFFIX).a,$(LIBDIR)/$(STATIC_LIB))
LINKLINE = ar rucv $(TARGET) $(OBJS)
else
LIB += -lcutil$(LIBSUFFIX)
# Device emulation configuration
ifeq ($(emu), 1)
NVCCFLAGS += -deviceemu
CUDACCFLAGS +=
BINSUBDIR := emu$(BINSUBDIR)
# consistency, makes developing easier
CXXFLAGS += -D__DEVICE_EMULATION__
CFLAGS += -D__DEVICE_EMULATION__
endif
TARGETDIR := $(BINDIR)/$(BINSUBDIR)
TARGET := $(TARGETDIR)/$(EXECUTABLE)
#fltk
LIB += -lfltk2 -lXft -lfltk2_images -lXext -lXinerama -lXi
#boost thread for interface
LIB += -lboost_thread
#read images in HOGImage from file
LIB := /pkg/suse11/cuda/4.2/sdk/CUDALibraries/common/FreeImage/lib/linux/libfreeimage64.a
LINKLINE = $(LINK) -o $(TARGET) $(OBJS) $(LIB)
endif
# check if verbose
ifeq ($(verbose), 1)
VERBOSE :=
else
VERBOSE := #
endif
################################################################################
# Check for input flags and set compiler flags appropriately
################################################################################
ifeq ($(fastmath), 1)
NVCCFLAGS += -use_fast_math
endif
ifeq ($(keep), 1)
NVCCFLAGS += -keep
NVCC_KEEP_CLEAN := *.i* *.cubin *.cu.c *.cudafe* *.fatbin.c *.ptx
endif
ifdef maxregisters
NVCCFLAGS += -maxrregcount $(maxregisters)
endif
# Add cudacc flags
NVCCFLAGS += $(CUDACCFLAGS)
# workaround for mac os x cuda 1.1 compiler issues
ifneq ($(DARWIN),)
NVCCFLAGS += --host-compilation C
endif
# Add common flags
NVCCFLAGS += $(COMMONFLAGS)
CXXFLAGS += $(COMMONFLAGS)
CFLAGS += $(COMMONFLAGS)
ifeq ($(nvcc_warn_verbose),1)
NVCCFLAGS += $(addprefix --compiler-options ,$(CXXWARN_FLAGS))
NVCCFLAGS += --compiler-options -fno-strict-aliasing
endif
################################################################################
# Set up object files
################################################################################
OBJDIR := $(ROOTOBJDIR)/$(BINSUBDIR)
OBJS += $(patsubst %.cpp,$(OBJDIR)/%.cpp.o,$(notdir $(CCFILES)))
OBJDIRUTILS := $(ROOTOBJDIR)/$(BINSUBDIR)/$(SRCDIRUTILS)
OBJS += $(patsubst %.cpp,$(OBJDIRUTILS)/%.cpp.o,$(notdir $(CCUTILS)))
OBJDIRHOG := $(ROOTOBJDIR)/$(BINSUBDIR)/$(SRCDIRHOG)
OBJS += $(patsubst %.cu,$(OBJDIRHOG)/%.cu.o,$(notdir $(CUFILES)))
OBJS += $(patsubst %.cpp,$(OBJDIRHOG)/%.cpp.o,$(notdir $(CCHOG)))
################################################################################
# Set up cubin files
################################################################################
CUBINDIR := $(SRCDIR)data
CUBINS += $(patsubst %.cu,$(CUBINDIR)/%.cubin,$(notdir $(CUBINFILES)))
################################################################################
# Rules
################################################################################
$(OBJDIR)/%.c.o : $(SRCDIR)%.c $(C_DEPS)
$(VERBOSE)$(CC) $(CFLAGS) -o $# -c $<
$(OBJDIRUTILS)/%.cpp.o : $(SRCDIRUTILS)%.cpp $(C_DEPS)
$(VERBOSE)$(CXX) $(CXXFLAGS) -o $# -c $<
$(OBJDIR)/%.cpp.o : $(SRCDIR)%.cpp $(C_DEPS)
$(VERBOSE)$(CXX) $(CXXFLAGS) -o $# -c $<
$(OBJDIRHOG)/%.cpp.o : $(SRCDIRHOG)%.cpp $(C_DEPS)
$(VERBOSE)$(CXX) $(CXXFLAGS) -o $# -c $<
$(OBJDIR)/%.cu.o : $(SRCDIR)%.cu $(CU_DEPS)
$(VERBOSE)$(NVCC) $(NVCCFLAGS) $(SMVERSIONFLAGS) -o $# -c $<
$(OBJDIRHOG)/%.cu.o : $(SRCDIRHOG)%.cu $(CU_DEPS)
$(VERBOSE)$(NVCC) $(NVCCFLAGS) $(SMVERSIONFLAGS) -o $# -c $<
$(CUBINDIR)/%.cubin : $(SRCDIR)%.cu cubindirectory
$(VERBOSE)$(NVCC) $(CUBIN_ARCH_FLAG) $(NVCCFLAGS) $(SMVERSIONFLAGS) -o $# -cubin $<
#
# The following definition is a template that gets instantiated for each SM
# version (sm_10, sm_13, etc.) stored in SMVERSIONS. It does 2 things:
# 1. It adds to OBJS a .cu_sm_XX.o for each .cu file it finds in CUFILES_sm_XX.
# 2. It generates a rule for building .cu_sm_XX.o files from the corresponding
# .cu file.
#
# The intended use for this is to allow Makefiles that use common.mk to compile
# files to different Compute Capability targets (aka SM arch version). To do
# so, in the Makefile, list files for each SM arch separately, like so:
#
# CUFILES_sm_10 := mycudakernel_sm10.cu app.cu
# CUFILES_sm_12 := anothercudakernel_sm12.cu
#
define SMVERSION_template
OBJS += $(patsubst %.cu,$(OBJDIR)/%.cu_$(1).o,$(notdir $(CUFILES_$(1))))
$(OBJDIR)/%.cu_$(1).o : $(SRCDIR)%.cu $(CU_DEPS)
$(VERBOSE)$(NVCC) -o $$# -c $$< $(NVCCFLAGS) -arch $(1)
endef
# This line invokes the above template for each arch version stored in
# SM_VERSIONS. The call function invokes the template, and the eval
# function interprets it as make commands.
$(foreach smver,$(SM_VERSIONS),$(eval $(call SMVERSION_template,$(smver))))
$(TARGET): makedirectories $(OBJS) $(CUBINS) Makefile
$(VERBOSE)$(LINKLINE)
cubindirectory:
$(VERBOSE)mkdir -p $(CUBINDIR)
makedirectories:
$(VERBOSE)mkdir -p $(LIBDIR)
$(VERBOSE)mkdir -p $(OBJDIR)
$(VERBOSE)mkdir -p $(OBJDIRUTILS)
$(VERBOSE)mkdir -p $(OBJDIRHOG)
$(VERBOSE)mkdir -p $(TARGETDIR)
tidy :-lboost_thread
$(VERBOSE)find . | egrep "#" | xargs rm -f
$(VERBOSE)find . | egrep "\~" | xargs rm -f
clean : tidy
$(VERBOSE)rm -f $(OBJS)
$(VERBOSE)rm -f $(CUBINS)
$(VERBOSE)rm -f $(TARGET)
$(VERBOSE)rm -f $(NVCC_KEEP_CLEAN)
clobber : clean
$(VERBOSE)rm -rf $(ROOTOBJDIR)
The common.mk has been broken (presumably by a modification you made to it) here:
LIB := /pkg/suse11/cuda/4.2/sdk/CUDALibraries/common/FreeImage/lib/linux/libfreeimage64.a
This is undoubtedly not what you want, it is destroying all of the carefully crafted library dependencies assigned above it. I guess you intended something like
LIB += /pkg/suse11/cuda/4.2/sdk/CUDALibraries/common/FreeImage/lib/linux/libfreeimage64.a
Related
I've noticed a lot of questions about people having the message "make: Nothing to be done for 'all'.", however my problem is the opposite.
Here is my makefile:
#################
## VARIABLES ##
#################
# Environment
OS := $(shell uname)
# Output
NAME := libft.a
DYNAMIC_NAME := ${NAME:a=so}
# Compiler
CC := gcc
ifneq ($(OS), Linux)
FLAGS += -Wall -Wextra -Werror
endif
DYN_FLAG := -shared
HEADERS := -I ./includes/
O_FLAG := -O2
# Directories
ADDITIONAL_FUNCTIONS = $(addprefix ./additional_functions/, $(ADDITIONAL))
BONUS_FUNCTIONS = $(addprefix ./bonus_functions/, $(BONUS))
LIBC_FUNCTIONS = $(addprefix ./libc_functions/, $(LIBC))
PERSONAL_FUNCTIONS = $(addprefix ./personal_functions/, $(PERSONAL))
DYN_OBJDIR = dyn_build/
OBJDIR := build/
# Sources
ADDITIONAL += ft_itoa.c
ADDITIONAL += ft_memalloc.c ft_memdel.c
ADDITIONAL += ft_putchar.c ft_putchar_fd.c
ADDITIONAL += ft_putendl.c ft_putendl_fd.c
ADDITIONAL += ft_putnbr.c ft_putnbr_fd.c
ADDITIONAL += ft_putstr.c ft_putstr_fd.c
ADDITIONAL += ft_strclr.c ft_strdel.c
ADDITIONAL += ft_strnew.c ft_strjoin.c
ADDITIONAL += ft_strequ.c ft_strnequ.c
ADDITIONAL += ft_striter.c ft_striteri.c
ADDITIONAL += ft_strmap.c ft_strmapi.c
ADDITIONAL += ft_strsplit.c ft_strsub.c ft_strtrim.c
BONUS += ft_lstadd.c ft_lstnew.c
BONUS += ft_lstdel.c ft_lstdelone.c
BONUS += ft_lstiter.c ft_lstmap.c
LIBC += ft_atoi.c
LIBC += ft_isalnum.c ft_isalpha.c ft_isascii.c
LIBC += ft_isdigit.c ft_isprint.c
LIBC += ft_memcpy.c ft_memccpy.c ft_memchr.c ft_memcmp.c
LIBC += ft_bzero.c ft_memmove.c ft_memset.c
LIBC += ft_strcat.c ft_strlcat.c ft_strncat.c
LIBC += ft_strchr.c ft_strrchr.c
LIBC += ft_strcmp.c ft_strncmp.c
LIBC += ft_strcpy.c ft_strncpy.c ft_strdup.c
LIBC += ft_strlen.c
LIBC += ft_strstr.c ft_strnstr.c
LIBC += ft_tolower.c ft_toupper.c
PERSONAL += ft_intlen.c
PERSONAL += ft_invert.c ft_islower.c ft_isupper.c
PERSONAL += ft_lstgetnode.c ft_lstsize.c
PERSONAL += ft_kill.c ft_putuchar.c ft_putuchar_fd.c
PERSONAL += ft_strrev.c ft_strrevcpy.c
PERSONAL += get_next_line.c
DYN_OBJECTS = $(patsubst %.c,$(DYN_OBJDIR)%.o,$(SRCS))
OBJECTS = $(patsubst %.c,$(OBJDIR)%.o,$(SRCS))
SRCS += $(ADDITIONAL_FUNCTIONS)
SRCS += $(BONUS_FUNCTIONS)
SRCS += $(LIBC_FUNCTIONS)
SRCS += $(PERSONAL_FUNCTIONS)
#################
## RULES ##
#################
all: $(NAME)
$(NAME): $(OBJECTS)
#ar rcs $# $(patsubst %.c,$(OBJDIR)%.o,$(notdir $(SRCS)))
ranlib $#
#echo "Static library created."
$(OBJECTS): | $(OBJDIR)
$(OBJDIR):
#mkdir -p $#
$(OBJDIR)%.o: %.c
$(CC) $(FLAGS) $(O_FLAG) -c $< $(HEADERS) -o $(OBJDIR)$(notdir $#)
$(DYN_OBJECTS): | $(DYN_OBJDIR)
$(DYN_OBJDIR):
#mkdir -p $#
$(DYN_OBJDIR)%.o: %.c
$(CC) $(FLAGS) $(O_FLAG) -c $< $(HEADERS) -fpic -o $(DYN_OBJDIR)$(notdir $#)
clean:
#/bin/rm -rfv $(OBJDIR)
#/bin/rm -rfv $(DYN_OBJDIR)
fclean: clean
#/bin/rm -fv $(NAME)
#/bin/rm -fv $(DYNAMIC_NAME)
re: fclean all
so: $(DYN_OBJECTS)
#$(CC) $(DYN_FLAG) -o $(DYNAMIC_NAME) $(patsubst %.c,$(DYN_OBJDIR)%.o,$(notdir $(SRCS)))
#echo "Dynamic library created."
.PHONY: all build clean dynbuild fclean re so
The makefile works perfectly fine. It takes every .c in the different directories, creates an object directory, build/ if the library is static and dyn_build/ if it is dynamic, put the object files inside said directory and compile the library from them.
My issue is that if I run make twice in a row, nothing should be done the second time as the object files and the library are still there and up to date. But, somehow doing make twice in a row results in the second make repeating the operation.
What is causing this and is there a way to fix it?
Your problem can be reduced to this:
ADDITIONAL += ft_strsplit.c
BONUS += ft_lstadd.c
ADDITIONAL_FUNCTIONS = $(addprefix ./add/, $(ADDITIONAL))
BONUS_FUNCTIONS = $(addprefix ./bonus/, $(BONUS))
SRCS += $(ADDITIONAL_FUNCTIONS)
SRCS += $(BONUS_FUNCTIONS)
OBJECTS = $(patsubst %.c,./build/%.o,$(SRCS))
# OBJECTS contains ./build/./add/ft_strsplit.o and ./build/./bonus/ft_lstadd.o
all: $(OBJECTS)
$(OBJDIR)%.o: %.c
$(CC) ...
So Make runs the last rule with e.g. build/./add/ft_strsplit.o as the target, and add/ft_strsplit.c as the prerequisite. The question is how to write the recipe so as to build build/ft_strsplit.o.
As #user657267 has pointed out, it is a mistake to have a (non-PHONY) rule that does not build a file whose name is the target of the rule. So let's first ask Make for the files we actually want:
ADDITIONAL += ft_strsplit.c
BONUS += ft_lstadd.c
SRCS += $(ADDITIONAL)
SRCS += $(BONUS)
OBJECTS = $(patsubst %.c,./build/%.o,$(SRCS))
# OBJECTS contains ./build/ft_strsplit.o and ./build/ft_lstadd.o
So far so good, but now how can Make find the sources? When we ask Make to build ./build/ft_strsplit.o, how can it know where ft_strsplit.c is?
We use vpath:
vpath %.c add bonus
Now the makefile works correctly. And to write that vpath line automatically, we can just pull the directory names out of the assignments:
# Directories
ADDITIONAL_DIR := ./additional_functions
BONUS_DIR := ./bonus_functions
...
ADDITIONAL_FUNCTIONS = $(addprefix $(ADDITIONAL_DIR)/, $(ADDITIONAL))
BONUS_FUNCTIONS = $(addprefix $(BONUS_DIR)/, $(BONUS))
...
vpath %.c $(ADDITIONAL_DIR)
vpath %.c $(BONUS_DIR)
...
I know this issue has been discussed several times here, but I cannot find help from the previous threads.
Here's the deal. I use a code written in fortran and I link it to my code in C by my makefile. The fortran makefile is ready to handle the compatibility, in fact, I got the command
CDEFS: -DAdd_
On my work machine everything seems fine. I do the link and run my own code.
However, I just tried to use the same code on my laptop and I got the classical linker error like:
undefined reference to 'dtrsm_' or
undefined reference to 'dcopy_'
refering to the fortran program. Nevertheless, the compilers are the same gcc and f95 for both machines and I didn't touch anything from the makefile.
How come I got this error?
thanks for help me.
EDIT1: sure, this is my makefile and MUMPS is the fortran code that uses a own makefile.
ROOT = $(addprefix $(PWD), /)
BUILDS_DIR = $(addprefix $(ROOT), builds/)
SRCS_DIR = $(addprefix $(ROOT), src/)
INCS_DIR = $(addprefix $(ROOT), src/)
OBJS_DIR = $(addprefix $(SRCS_DIR), objects/)
LIBS_DIR = ./
MUMPS_DIR = $(MUMPS_ROOT)
MUMPS_INCS_DIR = $(addprefix $(MUMPS_DIR), /include)
MUMPS_LIB_DIR = $(addprefix $(MUMPS_DIR), /lib)
MUMPS_MPI_DIR = $(addprefix $(MUMPS_DIR), /libseq)
SRCS = $(wildcard $(SRCS_DIR)*.c)
OBJS = $(SRCS:$(SRCS_DIR)%.c=$(OBJS_DIR)%.o)
MUMPS = MUMPS
TARGET = APOGEE
EXES = $(addprefix $(BUILDS_DIR), $(TARGET))
CC = gcc
CFLAGS = -O3 -MD -DTRILIBRARY
INCLUDES = -I$(INCS_DIR) -I$(MUMPS_INCS_DIR)
# CL = gcc
FL = f95
LFLAGS = -O
LIBS = -L$(LIBS_DIR) -lm -lblas -lpthread
LIBS += -L$(MUMPS_LIB_DIR) -ldmumps -lmumps_common -lpord -L$(MUMPS_MPI_DIR) -lmpiseq
RM = rm -f
.PHONY: all $(MUMPS) $(TARGET) distclean clean
default: $(MUMPS) $(TARGET)
$(TARGET): $(OBJS)
#echo -e "\n\n\t\t*** Compiled $(TARGET) successfully! ***\n" ;
$(FL) $(LFLAGS) -o $(BUILDS_DIR)$# \
$(OBJS) \
$(LIBS)
#echo -e "\n\n\t\t*** Linking $(TARGET) completed! ***\n"
$(OBJS): $(OBJS_DIR)%.o : $(SRCS_DIR)%.c
$(CC) $(CFLAGS) $(INCLUDES) \
-c $<\
-o $#
$(MUMPS):
(cd $(MUMPS_DIR) ; $(MAKE) ; cd $(ROOT)) ;
#echo -e "\n\n\t\t*** Compiled $(MUMPS) successfully! ***\n" ;
distclean: clean
$(RM) $(EXES)
(cd $(MUMPS_DIR) ; $(MAKE) clean ; cd $(ROOT)) ;
#echo -e "\n\n\t\t*** Purge $(MUMPS) and $(TARGET) completed! ***\n"
clean:
$(RM) $(OBJS_DIR)*.o \
$(SRCS_DIR)*~
#echo -e "\n\n\t\t*** Cleanup $(TARGET) completed! ***\n"
depend: $(SRCS)
makedepend $(INCLUDES) $^
EDIT2: chunks of the MUMPS makefile is here
include Makefile.inc
mumps_lib: requiredobj
(cd src ; $(MAKE) $(ARITH))
requiredobj: Makefile.inc $(LIBSEQNEEDED) $(libdir)/libpord$(PLAT)$(LIBEXT)
# dummy MPI library (sequential version)
libseqneeded:
(cd libseq; $(MAKE))
# Build the libpord.a library and copy it into $(topdir)/lib
$(libdir)/libpord$(PLAT)$(LIBEXT):
if [ "$(LPORDDIR)" != "" ] ; then \
cd $(LPORDDIR); \
$(MAKE) CC="$(CC)" CFLAGS="$(OPTC)" AR="$(AR)" RANLIB="$(RANLIB)" OUTC=$(OUTC) LIBEXT=$(LIBEXT); \
fi;
if [ "$(LPORDDIR)" != "" ] ; then \
cp $(LPORDDIR)/libpord$(LIBEXT) $#; \
fi;
and in Makefile.inc we got:
PLAT =
LIBEXT = .a
OUTC = -o
OUTF = -o
RM = /bin/rm -f
CC = cc
FC = f95
FL = f95
AR = ar vr
RANLIB = ranlib
INCSEQ = -I$(topdir)/libseq
LIBSEQ = -L$(topdir)/libseq -lmpiseq
LIBBLAS = -lblas
LIBOTHERS = -lpthread
CDEFS = -DAdd_
OPTF = -O
OPTC = -O -I.
OPTL = -O
INCS = $(INCSEQ)
LIBS = $(LIBSEQ)
LIBSEQNEEDED = libseqneeded
I have some problems with double! Through terminal there is some query, that I should give some number (For example how much delay in per hour). If I give through terminal a number such as 1.1 h then it prints about -1173000! It should print only 1.1.
I think, maybe there is some problem with the Makefile from FreeRTOS. (because it doesn't compile through FreeRTOS to STM32F407 processor!)
I believe something on this line should be fixed!
CPU = -mcpu=cortex-m4 -mthumb -mfloat-abi=softfp -mfpu=fpv4-sp-d16
Here is the complete code of Makefile:
# Optimization level, can be [0, 1, 2, 3, s].
# 0 = turn off optimization. s = optimize for size.
#
OPT = 0
# Object files directory
# Warning: this will be removed by make clean!
#
OBJDIR = obj
# Target file name (without extension)
#TARGET = $(OBJDIR)/main
TARGET = $(OBJDIR)/STM32F4_Test
# Define all C source files (dependencies are generated automatically)
#
SOURCES += src/uart.c
SOURCES += src/ustime.c
SOURCES += src/main.c
SOURCES += src/startup_stm32f4xx.S
SOURCES += src/system_stm32f4xx.c
SOURCES += src/syscalls.c
SOURCES += src/modbus.c
SOURCES += src/test.c
SOURCES += src/get.c
SOURCES += src/heap_2.c
SOURCES += FreeRTOS/Source/tasks.c
SOURCES += FreeRTOS/Source/queue.c
SOURCES += FreeRTOS/Source/list.c
SOURCES += FreeRTOS/Source/croutine.c
SOURCES += FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/misc.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_adc.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_can.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_crc.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_cryp.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_cryp_aes.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_cryp_des.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_cryp_tdes.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_dac.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_dbgmcu.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_dcmi.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_dma.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_exti.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_flash.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_fsmc.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_gpio.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_hash.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_hash_md5.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_hash_sha1.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_i2c.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_iwdg.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_pwr.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_rcc.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_rng.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_rtc.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_sdio.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_spi.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_syscfg.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_tim.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_usart.c
SOURCES += libs/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_wwdg.c
OBJECTS = $(addprefix $(OBJDIR)/,$(addsuffix .o,$(basename $(SOURCES))))
# Place -D, -U or -I options here for C and C++ sources
CPPFLAGS += -Isrc
CPPFLAGS += -IFreeRTOS/Source/include
CPPFLAGS += -Ilibs/CMSIS/Include
CPPFLAGS += -Ilibs/Device/STM32F4xx/Include
CPPFLAGS += -Ilibs/STM32F4xx_StdPeriph_Driver/inc
#---------------- Compiler Options C ----------------
# -g*: generate debugging information
# -O*: optimization level
# -f...: tuning, see GCC documentation
# -Wall...: warning level
# -Wa,...: tell GCC to pass this to the assembler.
# -adhlns...: create assembler listing
CFLAGS = -O$(OPT)
CFLAGS += -std=gnu99
CFLAGS += -gdwarf-2
CFLAGS += -ffunction-sections
CFLAGS += -fdata-sections
CFLAGS += -Wall
#CFLAGS += -Wextra
#CFLAGS += -Wpointer-arith
#CFLAGS += -Wstrict-prototypes
#CFLAGS += -Winline
#CFLAGS += -Wunreachable-code
#CFLAGS += -Wundef
CFLAGS += -Wa,-adhlns=$(OBJDIR)/$(*F).lst
# Optimize use of the single-precision FPU
#
# CFLAGS += -fsingle-precision-constant
# This will not work without recompiling libs
#
# CFLAGS += -fshort-double
#---------------- Compiler Options C++ ----------------
#
CXXFLAGS = $(CFLAGS)
#---------------- Assembler Options ----------------
# -Wa,...: tell GCC to pass this to the assembler
# -adhlns: create listing
#
ASFLAGS = -Wa,-adhlns=$(OBJDIR)/$(*F).lst
#---------------- Linker Options ----------------
# -Wl,...: tell GCC to pass this to linker
# -Map: create map file
# --cref: add cross reference to map file
LDFLAGS += -lm
LDFLAGS += -Wl,-Map=$(TARGET).map,--cref
LDFLAGS += -Wl,--gc-sections
LDFLAGS += -Tsrc/stm32_flash.ld
#============================================================================
# Define programs and commands
TOOLCHAIN = d:/Programme/CodeSourcery/Sourcery_2011_09_ARM_EABI/bin/arm-none-eabi
CC = $(TOOLCHAIN)-gcc
OBJCOPY = $(TOOLCHAIN)-objcopy
OBJDUMP = $(TOOLCHAIN)-objdump
SIZE = $(TOOLCHAIN)-size
NM = $(TOOLCHAIN)-nm
OPENOCD = D:\Tools\openocd-0.7.0\bin\openocd-0.7.0.exe
DOXYGEN = doxygen
STLINK = tools/ST-LINK_CLI.exe
MKDIR = d:\tools\unxutils\bin\mkdir.exe
ifeq (AMD64, $(PROCESSOR_ARCHITEW6432))
SUBWCREV = tools/SubWCRev64.exe
else
SUBWCREV = tools/SubWCRev.exe
endif
# Compiler flags to generate dependency files
GENDEPFLAGS = -MMD -MP -MF $(OBJDIR)/$(*F).d
# Combine all necessary flags and optional flags
# Add target processor to flags.
#
#CPU = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
#CPU = -mcpu=cortex-m4 -mthumb
#
// kannst du mal nach dem problem suchen? Und dich ueber floating point probleme informieren?
// auf der ARM cpu oder spezielle dieser F407 cpu
CPU = -mcpu=cortex-m4 -mthumb -mfloat-abi=softfp -mfpu=fpv4-sp-d16
#CPU = -mcpu=cortex-m4 -mthumb
CFLAGS += $(CPU)
CXXFLAGS += $(CPU)
ASFLAGS += $(CPU)
LDFLAGS += $(CPU)
# Default target.
all: setup gccversion build showsize
setup:
$(MKDIR) -p $(OBJDIR)
$(MKDIR) -p $(OBJDIR)\src
$(MKDIR) -p $(OBJDIR)\FreeRTOS\Source
$(MKDIR) -p $(OBJDIR)\FreeRTOS\Source\portable\GCC\ARM_CM4F
$(MKDIR) -p $(OBJDIR)\libs\STM32F4xx_StdPeriph_Driver\src
build: elf hex lss sym bin
elf: $(TARGET).elf
hex: $(TARGET).hex
bin: $(TARGET).bin
lss: $(TARGET).lss
sym: $(TARGET).sym
doxygen:
#echo
#echo Creating Doxygen documentation
#$(DOXYGEN)
# Display compiler version information
gccversion:
#$(CC) --version
# Show the final program size
showsize: elf
#echo
#$(SIZE) $(TARGET).elf
# debug level
OOCD_CL=-d2
#OOCD_CL=-d3
# interface and board/target settings (using the OOCD target-library here)
## OOCD_CL+=-c "fast enable"
OOCD_CL+=-f interface/signalyzer.cfg -f openocd/stm32f4x.cfg
OOCD_CL+=-f openocd/config.cfg
OOCD_CL+=-c init -c targets
# commands to prepare flash-write
OOCD_CL+=-c "halt"
# flash-write and -verify
OOCD_CL+=-c "flash write_image erase $(TARGET).elf" -c "verify_image $(TARGET).elf"
# reset target
OOCD_CL+=-c "reset run"
# terminate OOCD after programming
# OOCD_CL+=-c shutdown
# Flash the device
flash: hex
# $(OPENOCD) -f "interface/signalyzer.cfg" -f "openocd/stm32f4x.cfg" -f "openocd/config.cfg" -c "flash_image $(TARGET).elf; shutdown"
$(OPENOCD) $(OOCD_CL)
# $(STLINK) -c SWD -P $(TARGET).hex -Run
# Target: clean project
clean:
#echo Cleaning project:
rm -rf $(OBJDIR)
rm -rf docs/html
# Create extended listing file from ELF output file
%.lss: %.elf
#echo
#echo Creating Extended Listing: $#
$(OBJDUMP) -h -S -z $< > $#
# Create a symbol table from ELF output file
%.sym: %.elf
#echo
#echo Creating Symbol Table: $#
$(NM) -n $< > $#
# Link: create ELF output file from object files
.SECONDARY: $(TARGET).elf
.PRECIOUS: $(OBJECTS)
$(TARGET).elf: $(OBJECTS)
#echo
#echo Linking: $#
$(CC) $^ $(LDFLAGS) --output $#
# Create final output files (.hex, .eep) from ELF output file.
%.hex: %.elf
#echo
#echo Creating hex file: $#
$(OBJCOPY) -O ihex $< $#
# Create bin file :
%.bin: %.elf
#echo
#echo Creating bin file: $#
$(OBJCOPY) -O binary $< $#
# Compile: create object files from C source files
$(OBJDIR)/%.o : %.c
#echo
#echo Compiling C: $<
$(CC) -c $(CPPFLAGS) $(CFLAGS) $(GENDEPFLAGS) $< -o $#
# Compile: create object files from C++ source files
$(OBJDIR)/%.o : %.cpp
#echo
#echo Compiling CPP: $<
$(CC) -c $(CPPFLAGS) $(CXXFLAGS) $(GENDEPFLAGS) $< -o $#
# Assemble: create object files from assembler source files
$(OBJDIR)/%.o : %.s
#echo
#echo Assembling: $<
$(CC) -c $(CPPFLAGS) $(ASFLAGS) $< -o $#
# Include the dependency files
-include $(wildcard $(OBJDIR)/*.d)
# Listing of phony targets
.PHONY: all build flash clean \
doxygen elf lss sym \
showsize gccversion \
build elf hex bin lss sym clean clean_list setup program
I don't believe the Sourcery CodeBench 2011.09 ARM EABI compiler supports that configuration. In particular, your FPU setting appears to use single-precision, and I'm pretty sure all the libraries included with that toolchain expect a double-precision FPU.
It's not that the compiler can't produce the code you ask for. The problem is that the toolchain doesn't include compatible libraries.
It's possible that I'm mistaken and the FreeRTOS folks have already built and bundled the missing pieces, but suspect not.
This is my first program using Dynamic Parallelism and I am unable to compile the code. I need to be able to run this for my research project at college and any help will be most appreciated:
I get the following error:
/cm/shared/apps/cuda50/toolkit/5.0.35/bin/nvcc -m64 -dc -gencode arch=compute_35,code=sm_35 -rdc=true -dlink -po maxrregcount=16 -I/cm/shared/apps/cuda50/toolkit/5.0.35 -I. -I.. -I../../common/inc -o BlackScholes.o -c BlackScholes.cu
g++ -m64 -I/cm/shared/apps/cuda50/toolkit/5.0.35 -I. -I.. -I../../common/inc -o BlackScholes_gold.o -c BlackScholes_gold.cpp
g++ -m64 -o BlackScholes BlackScholes.o BlackScholes_gold.o -L/cm/shared/apps/cuda50/toolkit/5.0.35/lib64 -lcudart -lcudadevrt
BlackScholes.o: In function `__sti____cudaRegisterAll_47_tmpxft_000059cb_00000000_6_BlackScholes_cpp1_ii_c58990ec()':
tmpxft_000059cb_00000000-3_BlackScholes.cudafe1.cpp:(.text+0x1354): undefined reference to `__cudaRegisterLinkedBinary_47_tmpxft_000059cb_00000000_6_BlackScholes_cpp1_ii_c58990ec'
collect2: ld returned 1 exit status
make: *** [BlackScholes] Error 1
I have one cpp file, one cu file and one cuh file. Important portions of my makefile are below:
# CUDA code generation flags
#GENCODE_SM10 := -gencode arch=compute_10,code=sm_10
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
GENCODE_SM35 := -gencode arch=compute_35,code=sm_35
#GENCODE_FLAGS := $(GENCODE_SM10) $(GENCODE_SM20) $(GENCODE_SM30)
GENCODE_FLAGS := $(GENCODE_SM35)
# OS-specific build flags
ifneq ($(DARWIN),)
LDFLAGS := -Xlinker -rpath $(CUDA_LIB_PATH) -L$(CUDA_LIB_PATH) -lcudart -lcudadevrt
CCFLAGS := -arch $(OS_ARCH)
else
ifeq ($(OS_SIZE),32)
LDFLAGS := -L$(CUDA_LIB_PATH) -lcudart -lcudadevrt
CCFLAGS := -m32
else
LDFLAGS := -L$(CUDA_LIB_PATH) -lcudart -lcudadevrt
CCFLAGS := -m64
endif
endif
# OS-architecture specific flags
ifeq ($(OS_SIZE),32)
NVCCFLAGS := -m32 -dc
else
NVCCFLAGS := -m64 -dc
endif
# Debug build flags
ifeq ($(dbg),1)
CCFLAGS += -g
NVCCFLAGS += -g -G
TARGET := debug
else
TARGET := release
endif
# Common includes and paths for CUDA
INCLUDES := -I$(CUDA_INC_PATH) -I. -I.. -I../../common/inc
# Additional parameters
MAXRREGCOUNT := -po maxrregcount=16
# Target rules
all: build
build: BlackScholes
BlackScholes.o: BlackScholes.cu
$(NVCC) $(NVCCFLAGS) $(EXTRA_NVCCFLAGS) $(GENCODE_FLAGS) -rdc=true -dlink $(MAXRREGCOUNT) $(INCLUDES) -o $# -c $<
BlackScholes_gold.o: BlackScholes_gold.cpp
$(GCC) $(CCFLAGS) $(INCLUDES) -o $# -c $<
BlackScholes: BlackScholes.o BlackScholes_gold.o
$(GCC) $(CCFLAGS) -o $# $+ $(LDFLAGS) $(EXTRA_LDFLAGS)
mkdir -p ../../bin/$(OSLOWER)/$(TARGET)
cp $# ../../bin/$(OSLOWER)/$(TARGET)
enter code here
run: build
./BlackScholes
When using the host linker (g++) for final linking of your executable, and when using relocatable device code (nvcc -dc), it's necessary to do an intermediate device code link step.
From the documentation:
If you want to invoke the device and host linker separately, you can do:
nvcc –arch=sm_20 –dc a.cu b.cu
nvcc –arch=sm_20 –dlink a.o b.o –o link.o
g++ a.o b.o link.o –L<path> -lcudart
Since you are specifying -dc on the compile line, you are getting a compile-only operation (just as if you had specified -c to g++).
Here's a modified/condensed Makefile that should show you what is involved:
GENCODE_SM35 := -gencode arch=compute_35,code=sm_35
GENCODE_FLAGS := $(GENCODE_SM35)
LDFLAGS := -L/usr/local/cuda/lib64 -lcudart -lcudadevrt
CCFLAGS := -m64
NVCCFLAGS := -m64 -dc
NVCC := nvcc
GCC := g++
# Debug build flags
ifeq ($(dbg),1)
CCFLAGS += -g
NVCCFLAGS += -g -G
TARGET := debug
else
TARGET := release
endif
# Common includes and paths for CUDA
INCLUDES := -I/usr/local/cuda/include -I. -I..
# Additional parameters
MAXRREGCOUNT := -po maxrregcount=16
# Target rules
all: build
build: BlackScholes
BlackScholes.o: BlackScholes.cu
$(NVCC) $(NVCCFLAGS) $(EXTRA_NVCCFLAGS) $(GENCODE_FLAGS) $(MAXRREGCOUNT) $(INCLUDES) -o $# $<
$(NVCC) -dlink $(GENCODE_FLAGS) $(MAXRREGCOUNT) -o bs_link.o $#
BlackScholes_gold.o: BlackScholes_gold.cpp
$(GCC) $(CCFLAGS) $(INCLUDES) -o $# -c $<
BlackScholes: BlackScholes.o BlackScholes_gold.o bs_link.o
$(GCC) $(CCFLAGS) -o $# $+ $(LDFLAGS) $(EXTRA_LDFLAGS)
run: build
./BlackScholes
I have the following makefile. If I do make USE_44=1 USE_O=1 for example, I receive the following error.
makefile:21: *** missing separator, where line 21 is elif ($(USE_S), 1).
Note that if I do make USE_44=1, it compiles fine.
Can someone tell me what is the problem here and how can I fix it?
USE_44 = 0
USE_IO = 0
USE_O = 0
USE_S = 0
USE_F = 0
USE_I = 0
USE_WL = 0
ifeq ($(USE_44), 0)
CXX = g++
else
CXX = g++44
endif
CXXFILES = main.cpp jacobcalc.cpp linkup.cpp slave1.cpp jacobcalc2.cpp slave2.cpp laplacalc.cpp multi.cpp subblock.cpp replication.cpp hash.cpp
CXXFLAGS := -std=c++0x -O3 -o
ifeq ($(USE_O), 1)
CXXFLAGS += progo -DWITHOUT_LOCKS -DWITHOUT_BARRIERS -DWITHOUT_MPROTECT
elif ($(USE_S), 1)
CXXFLAGS += progs -DWITHOUT_LOCKS -DWITHOUT_BARRIERS -DWITHOUT_MPROTECT -DSINGLE
elif ($(USE_F), 1)
CXXFLAGS += progf -DNEGLECT_DET_LOCKS
elif ($(USE_I), 1)
CXXFLAGS += progi -DWITH_INSTR
elif ($(USE_WL), 1)
CXXFLAGS += progwl -DWITHOUT_LOCKS
else
CXXFLAGS += prog
endif
ifeq ($(USE_IO), 1)
CXXFLAGS += -DWITHOUT_IO
endif
#CFLAGS := $(CFLAGS) -Wall -W -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wdisabled-optimization
#CFLAGS := $(CFLAGS) -Wpadded -Winline -Wpointer-arith -Wsign-compare -Wendif-labels prog
LIBS := -lm -lpthread
all:
$(CXX) $(CXXFILES) $(LIBS) $(CXXFLAGS)
clean:
rm -f prog* *.o
The correct way to use conditionals is outlined in the make documentation.
conditional-directive
text-if-one-is-true
else conditional-directive
text-if-true
else
text-if-false
endif
elif is unrecognized. If you'd instead typed else ifeq(...) it should all be good.
Try with:
ifeq ($(USE_O), 1)
...
else ifeq ($(USE_S), 1)
...
endif
That's the correct syntax according the the conditional syntax docs for GNU Make.