Why can't CUDA's examples makefile find the CUDA libraries? - linux

I'm running Arch Linux and have installed the cuda-sdk and cuda-toolkit from the repositories. I've compiled the libraries inside /opt/cuda-sdk/CUDALibraries fine.
No I go to compile the sdk examples by running make in /opt/cuda-sdk/C and get the following error:
# make
make[1]: Entering directory `/opt/cuda-sdk/C/common'
make[1]: Leaving directory `/opt/cuda-sdk/C/common'
make[1]: Entering directory `/opt/cuda-sdk/C/common'
make[1]: Leaving directory `/opt/cuda-sdk/C/common'
make[1]: Entering directory `/opt/cuda-sdk/C/common'
make[1]: Leaving directory `/opt/cuda-sdk/C/common'
make[1]: Entering directory `/opt/cuda-sdk/shared'
make[1]: Leaving directory `/opt/cuda-sdk/shared'
make[1]: Entering directory `/opt/cuda-sdk/C/src/newdelete'
make[1]: Leaving directory `/opt/cuda-sdk/C/src/newdelete'
make[1]: Entering directory `/opt/cuda-sdk/C/src/simpleTextureDrv'
/usr/bin/ld: cannot find -lcuda
collect2: error: ld returned 1 exit status
make[1]: *** [../../bin/linux/release/simpleTextureDrv] Error 1
make[1]: Leaving directory `/opt/cuda-sdk/C/src/simpleTextureDrv'
make: *** [src/simpleTextureDrv/Makefile.ph_build] Error 2
The Makefile itself essentially seems to just include the file /opt/cuda-sdk/C/common/common.mk, which is:
################################################################################
#
# Copyright 1993-2011 NVIDIA Corporation. All rights reserved.
#
# NVIDIA Corporation and its licensors retain all intellectual property and
# proprietary rights in and to this software and related documentation.
# Any use, reproduction, disclosure, or distribution of this software
# and related documentation without an express license agreement from
# NVIDIA Corporation is strictly prohibited.
#
# Please refer to the applicable NVIDIA end user license agreement (EULA)
# associated with this source code for terms and conditions that govern
# your use of this NVIDIA software.
#
################################################################################
#
# Common build script for CUDA source projects for Linux and Mac platforms
#
################################################################################
.SUFFIXES : .cu .cu_dbg.o .c_dbg.o .cpp_dbg.o .cu_rel.o .c_rel.o .cpp_rel.o .cubin .ptx
# Add new SM Versions here as devices with new Compute Capability are released
SM_VERSIONS := 10 11 12 13 20 21 30
CUDA_INSTALL_PATH ?= /opt/cuda-toolkit
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)))
ifneq ($(DARWIN),)
SNOWLEOPARD = $(strip $(findstring 10.6, $(shell egrep "<string>10\.6" /System/Library/CoreServices/SystemVersion.plist)))
LION = $(strip $(findstring 10.7, $(shell egrep "<string>10\.7" /System/Library/CoreServices/SystemVersion.plist)))
endif
# detect 32-bit or 64-bit platform
HP_64 = $(shell uname -m | grep 64)
OSARCH= $(shell uname -m)
# Basic directory setup for SDK
# (override directories only if they are not already defined)
SRCDIR ?=
ROOTDIR ?= ..
ROOTBINDIR ?= $(ROOTDIR)/../bin
BINDIR ?= $(ROOTBINDIR)/$(OSLOWER)
ROOTOBJDIR ?= obj
LIBDIR := $(ROOTDIR)/../lib
COMMONDIR := $(ROOTDIR)/../common
SHAREDDIR := $(ROOTDIR)/../../shared/
# Compilers
NVCC := $(CUDA_INSTALL_PATH)/bin/nvcc
CXX := g++ -fPIC
CC := gcc -fPIC
LINK := g++ -fPIC
# Includes
INCLUDES += -I. -I$(CUDA_INSTALL_PATH)/include -I$(COMMONDIR)/inc -I$(SHAREDDIR)/inc
# 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 \
# architecture flag for nvcc and gcc compilers build
CUBIN_ARCH_FLAG :=
CXX_ARCH_FLAGS :=
NVCCFLAGS :=
LIB_ARCH := $(OSARCH)
# Determining the necessary Cross-Compilation Flags
# 32-bit OS, but we target 64-bit cross compilation
ifeq ($(x86_64),1)
NVCCFLAGS += -m64
LIB_ARCH = x86_64
ifneq ($(DARWIN),)
CXX_ARCH_FLAGS += -arch x86_64
else
CXX_ARCH_FLAGS += -m64
endif
else
# 64-bit OS, and we target 32-bit cross compilation
ifeq ($(i386),1)
NVCCFLAGS += -m32
LIB_ARCH = i386
ifneq ($(DARWIN),)
CXX_ARCH_FLAGS += -arch i386
else
CXX_ARCH_FLAGS += -m32
endif
else
ifeq "$(strip $(HP_64))" ""
LIB_ARCH = i386
NVCCFLAGS += -m32
ifneq ($(DARWIN),)
CXX_ARCH_FLAGS += -arch i386
else
CXX_ARCH_FLAGS += -m32
endif
else
LIB_ARCH = x86_64
NVCCFLAGS += -m64
ifneq ($(DARWIN),)
CXX_ARCH_FLAGS += -arch x86_64
else
CXX_ARCH_FLAGS += -m64
endif
endif
endif
endif
# Compiler-specific flags (by default, we always use sm_10, sm_20, and sm_30), unless we use the SMVERSION template
GENCODE_SM10 := -gencode=arch=compute_10,code=\"sm_10,compute_10\"
GENCODE_SM20 := -gencode=arch=compute_20,code=\"sm_20,compute_20\"
GENCODE_SM30 := -gencode=arch=compute_30,code=\"sm_30,compute_30\"
CXXFLAGS += $(CXXWARN_FLAGS) $(CXX_ARCH_FLAGS)
CFLAGS += $(CWARN_FLAGS) $(CXX_ARCH_FLAGS)
LINKFLAGS +=
LINK += $(LINKFLAGS) $(CXX_ARCH_FLAGS)
# This option for Mac allows CUDA applications to work without requiring to set DYLD_LIBRARY_PATH
ifneq ($(DARWIN),)
LINK += -Xlinker -rpath $(CUDA_INSTALL_PATH)/lib
endif
# Common flags
COMMONFLAGS += $(INCLUDES) -DUNIX
# If we are enabling GPU based debugging, then we want to use -G, warning that this
# May have a significant impact on GPU device code, since optimizations are turned off
ifeq ($(gpudbg),1)
NVCCFLAGS += -G
dbg = $(gpudbg)
endif
# Debug/release configuration
ifeq ($(dbg),1)
COMMONFLAGS += -g
NVCCFLAGS += -D_DEBUG
CXXFLAGS += -D_DEBUG
CFLAGS += -D_DEBUG
BINSUBDIR := debug
LIBSUFFIX := D
else
COMMONFLAGS += -O2
BINSUBDIR := release
LIBSUFFIX :=
NVCCFLAGS += --compiler-options -fno-strict-aliasing
CXXFLAGS += -fno-strict-aliasing
CFLAGS += -fno-strict-aliasing
endif
# architecture flag for cubin build
CUBIN_ARCH_FLAG :=
# 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
OPENGLLIB += -lGL -lGLU $(COMMONDIR)/lib/$(OSLOWER)/libGLEW.a
else
# this case for linux platforms
OPENGLLIB := -lGL -lGLU -lX11 -lXi -lXmu
# check if x86_64 flag has been set, otherwise, check HP_64 is i386/x86_64
ifeq ($(x86_64),1)
OPENGLLIB += -lGLEW_x86_64 -L/usr/X11R6/lib64
else
ifeq ($(i386),)
ifeq "$(strip $(HP_64))" ""
OPENGLLIB += -lGLEW -L/usr/X11R6/lib
else
OPENGLLIB += -lGLEW_x86_64 -L/usr/X11R6/lib64
endif
endif
endif
# check if i386 flag has been set, otehrwise check HP_64 is i386/x86_64
ifeq ($(i386),1)
OPENGLLIB += -lGLEW -L/usr/X11R6/lib
else
ifeq ($(x86_64),)
ifeq "$(strip $(HP_64))" ""
OPENGLLIB += -lGLEW -L/usr/X11R6/lib
else
OPENGLLIB += -lGLEW_x86_64 -L/usr/X11R6/lib64
endif
endif
endif
endif
endif
ifeq ($(USEGLUT),1)
ifneq ($(DARWIN),)
OPENGLLIB += -framework GLUT
else
ifeq ($(x86_64),1)
OPENGLLIB += -lglut -L/usr/lib64
endif
ifeq ($(i386),1)
OPENGLLIB += -lglut -L/usr/lib
endif
ifeq ($(x86_64),)
ifeq ($(i386),)
OPENGLLIB += -lglut
endif
endif
endif
endif
ifeq ($(USEPARAMGL),1)
PARAMGLLIB := -lparamgl_$(LIB_ARCH)$(LIBSUFFIX)
endif
ifeq ($(USERENDERCHECKGL),1)
RENDERCHECKGLLIB := -lrendercheckgl_$(LIB_ARCH)$(LIBSUFFIX)
endif
ifeq ($(USENVCUVID), 1)
ifneq ($(DARWIN),)
NVCUVIDLIB := -L../../common/lib/darwin -lnvcuvid
endif
endif
# Libs
ifneq ($(DARWIN),)
LIB := -L$(CUDA_INSTALL_PATH)/lib -L$(LIBDIR) -L$(COMMONDIR)/lib/$(OSLOWER) -L$(SHAREDDIR)/lib $(NVCUVIDLIB)
else
ifeq "$(strip $(HP_64))" ""
ifeq ($(x86_64),1)
LIB := -L$(CUDA_INSTALL_PATH)/lib64 -L$(LIBDIR) -L$(COMMONDIR)/lib/$(OSLOWER) -L$(SHAREDDIR)/lib
else
LIB := -L$(CUDA_INSTALL_PATH)/lib -L$(LIBDIR) -L$(COMMONDIR)/lib/$(OSLOWER) -L$(SHAREDDIR)/lib
endif
else
ifeq ($(i386),1)
LIB := -L$(CUDA_INSTALL_PATH)/lib -L$(LIBDIR) -L$(COMMONDIR)/lib/$(OSLOWER) -L$(SHAREDDIR)/lib
else
LIB := -L$(CUDA_INSTALL_PATH)/lib64 -L$(LIBDIR) -L$(COMMONDIR)/lib/$(OSLOWER) -L$(SHAREDDIR)/lib
endif
endif
endif
# If dynamically linking to CUDA and CUDART, we exclude the libraries from the LIB
ifeq ($(USECUDADYNLIB),1)
LIB += ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) ${LIB} -ldl -rdynamic
else
# static linking, we will statically link against CUDA and CUDART
ifeq ($(USEDRVAPI),1)
LIB += -lcuda ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) ${LIB}
else
ifeq ($(emu),1)
LIB += -lcudartemu
else
LIB += -lcudart
endif
LIB += ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) ${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
ifeq ($(USECURAND),1)
LIB += -lcurand
endif
ifeq ($(USECUSPARSE),1)
LIB += -lcusparse
endif
# Lib/exe configuration
# Lib/exe configuration
# Lib/exe configuration
ifneq ($(STATIC_LIB),)
TARGETDIR := $(LIBDIR)
TARGET := $(subst .a,_$(LIB_ARCH)$(LIBSUFFIX).a,$(LIBDIR)/$(STATIC_LIB))
LINKLINE = ar rucv $(TARGET) $(OBJS)
else
ifneq ($(OMIT_CUTIL_LIB),1)
LIB += -lcutil_$(LIB_ARCH)$(LIBSUFFIX)
endif
ifneq ($(OMIT_SHRUTIL_LIB),1)
LIB += -lshrutil_$(LIB_ARCH)$(LIBSUFFIX)
endif
# 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)
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
ifeq ($(ptxas), 1)
NVCCFLAGS += --ptxas-options=-v
endif
# Add cudacc flags
NVCCFLAGS += $(CUDACCFLAGS)
# 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)/$(LIB_ARCH)/$(BINSUBDIR)
OBJS += $(patsubst %.cpp,$(OBJDIR)/%.cpp.o,$(notdir $(CCFILES)))
OBJS += $(patsubst %.c,$(OBJDIR)/%.c.o,$(notdir $(CFILES)))
OBJS += $(patsubst %.cu,$(OBJDIR)/%.cu.o,$(notdir $(CUFILES)))
################################################################################
# Set up cubin output files
################################################################################
CUBINDIR := $(SRCDIR)data
CUBINS += $(patsubst %.cu,$(CUBINDIR)/%.cubin,$(notdir $(CUBINFILES)))
################################################################################
# Set up PTX output files
################################################################################
PTXDIR := $(SRCDIR)data
PTXBINS += $(patsubst %.cu,$(PTXDIR)/%.ptx,$(notdir $(PTXFILES)))
################################################################################
# Rules
################################################################################
$(OBJDIR)/%.c.o : $(SRCDIR)%.c $(C_DEPS)
$(VERBOSE)$(CC) $(CFLAGS) -o $# -c $<
$(OBJDIR)/%.cpp.o : $(SRCDIR)%.cpp $(C_DEPS)
$(VERBOSE)$(CXX) $(CXXFLAGS) -o $# -c $<
# Default arch includes gencode for sm_10, sm_20, sm_30, and other archs from GENCODE_ARCH declared in the makefile
$(OBJDIR)/%.cu.o : $(SRCDIR)%.cu $(CU_DEPS)
$(VERBOSE)$(NVCC) $(GENCODE_SM10) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(NVCCFLAGS) $(SMVERSIONFLAGS) -o $# -c $<
# Default arch includes gencode for sm_10, sm_20, sm_30, and other archs from GENCODE_ARCH declared in the makefile
$(CUBINDIR)/%.cubin : $(SRCDIR)%.cu cubindirectory
$(VERBOSE)$(NVCC) $(GENCODE_SM10) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(CUBIN_ARCH_FLAG) $(NVCCFLAGS) $(SMVERSIONFLAGS) -o $# -cubin $<
$(PTXDIR)/%.ptx : $(SRCDIR)%.cu ptxdirectory
$(VERBOSE)$(NVCC) $(CUBIN_ARCH_FLAG) $(NVCCFLAGS) $(SMVERSIONFLAGS) -o $# -ptx $<
#
# 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:
# This will be used over the default rule abov
#
# 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))))
OBJS += $(patsubst %.cu,$(OBJDIR)/%.cu_$(1).o,$(notdir $(CUFILES_sm_$(1))))
$(OBJDIR)/%.cu_$(1).o : $(SRCDIR)%.cu $(CU_DEPS)
# $(VERBOSE)$(NVCC) -o $$# -c $$< $(NVCCFLAGS) $(1)
$(VERBOSE)$(NVCC) -gencode=arch=compute_$(1),code=\"sm_$(1),compute_$(1)\" $(GENCODE_SM20) $(GENCODE_SM30) -o $$# -c $$< $(NVCCFLAGS)
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) $(PTXBINS) Makefile
$(VERBOSE)$(LINKLINE)
cubindirectory:
$(VERBOSE)mkdir -p $(CUBINDIR)
ptxdirectory:
$(VERBOSE)mkdir -p $(PTXDIR)
makedirectories:
$(VERBOSE)mkdir -p $(LIBDIR)
$(VERBOSE)mkdir -p $(OBJDIR)
$(VERBOSE)mkdir -p $(TARGETDIR)
tidy :
$(VERBOSE)find . | egrep "#" | xargs rm -f
$(VERBOSE)find . | egrep "\~" | xargs rm -f
clean : tidy
$(VERBOSE)rm -f *.stub.c *.gpu *.cu.cpp *.i *.ii
$(VERBOSE)rm -f *.cubin *.ptx *.fatbin.c *.hash
$(VERBOSE)rm -f *.cudafe1.c *.cudafe2.c *.cudafe1.cpp *.cudafe2.cpp
$(VERBOSE)rm -f $(OBJS)
$(VERBOSE)rm -f $(CUBINS)
$(VERBOSE)rm -f $(PTXBINS)
$(VERBOSE)rm -f $(TARGET)
$(VERBOSE)rm -f $(NVCC_KEEP_CLEAN)
$(VERBOSE)rm -f $(ROOTBINDIR)/$(OSLOWER)/$(BINSUBDIR)/*.ppm
$(VERBOSE)rm -f $(ROOTBINDIR)/$(OSLOWER)/$(BINSUBDIR)/*.pgm
$(VERBOSE)rm -f $(ROOTBINDIR)/$(OSLOWER)/$(BINSUBDIR)/*.bin
$(VERBOSE)rm -f $(ROOTBINDIR)/$(OSLOWER)/$(BINSUBDIR)/*.bmp
$(VERBOSE)rm -f $(ROOTBINDIR)/$(OSLOWER)/$(BINSUBDIR)/*.txt
$(VERBOSE)rm -f $(CUBINDIR)/*.cubin $(PTXDIR)/*.ptx
$(VERBOSE)rm -rf $(ROOTOBJDIR)
$(VERBOSE)rm -rf $(LIBDIR)
$(VERBOSE)rm -rf $(OBJDIR)
$(VERBOSE)rm -rf $(TARGETDIR)
clobber : clean
$(VERBOSE)rm -rf $(COMMONDIR)/lib/*.a
$(VERBOSE)rm -rf $(SHAREDDIR)/lib/*.a
$(VERBOSE)rm -rf $(COMMONDIR)/obj
$(VERBOSE)rm -rf $(SHAREDDIR)/obj
The output of echo $LD_LIBRARY_PATH is blank.
I have checked for libcuda and can find it where I think it should be:
# ls /usr/lib | grep libcuda
libcuda.so.1
libcuda.so.304.32
Is there something obvious I need to do to get these to compile? Is this a problem with the CUDA makefile or with my system?

The answer was suggested in comments, and the OP found the solution:
I added a symlink:
ln -s /usr/lib/libcuda.so.1 /usr/lib/libcuda.so
and it compiled fine.

Related

Module verification failed when insmod a module

On Ubuntu 14.04, Kernel 3.13.0, When I insert below simple module, I got error message from kernel log:
"module verification failed: signature and/or required key missing - tainting kernel"
Did I made any mistake or missed anything?
Here is module source code in a file named ts2.c.
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
#include <linux/init.h>
MODULE_LICENSE("GPL");
MODULE_ALIAS("hello2");
static int __init hello1_init(void)
{
printk(KERN_INFO "Hello world 2.\n");
return 0;
}
static void __exit hello1_exit(void)
{
printk(KERN_INFO "Goodbye world 2.\n");
}
module_init(hello1_init);
module_exit(hello1_exit);
Here is the Makefile:
ifeq ($(DEBUG),y)
DEBFLAGS = -O -g -DPCI_INFO_DEBUG # "-O" is needed to expand inlines
else
DEBFLAGS = -O2
endif
EXTRA_CFLAGS += $(DEBFLAGS) -I$(LDDINC)
ifneq ($(KERNELRELEASE),)
obj-m := ts2.o
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
modules:
$(MAKE) -C $(KERNELDIR) M=$(PWD) LDDINC=$(PWD) modules
clean:
$(MAKE) -C $(KERNELDIR) M=$(PWD) LDDINC=$(PWD) clean
endif
depend .depend dep:
$(CC) $(EXTRA_CFLAGS) -M *.c > .depend
ifeq (.depend,$(wildcard .depend))
include .depend
endif
You have a problem in your make file...
ifeq ($(DEBUG),y)
DEBFLAGS = -O -g -DPCI_INFO_DEBUG # "-O" is needed to expand inlines
else
DEBFLAGS = -O2
endif
EXTRA_CFLAGS += $(DEBFLAGS) -I$(LDDINC)
ifneq ($(KERNELRELEASE),)
obj-m := ts2.o
Rather it should be as below:
ifeq ($(DEBUG),y)
DEBFLAGS = -O -g -DPCI_INFO_DEBUG # "-O" is needed to expand inlines
else
DEBFLAGS = -O2
endif
EXTRA_CFLAGS += $(DEBFLAGS) -I$(LDDINC)
ifneq ($(KERNELRELEASE),)
obj-m := hello1.o
Now your issues should be solved

OS detection Makefile

Here is my makefile, until today I never try to use OS detection in it. Mine looks like this :
CC = gcc
CFLAGS = -Wall -Wextra -O1 -Wuninitialized
OUT = project.exe
ifeq ($(UNAME),Darwin) #Mac OS
echo "Darwin"
SRC = sdl_gui.c libSDLextra.c libImageProcessing.c SDLmain.m
OBJ = sdl_gui.o libSDLextra.o libImageProcessing.o SDLmain.o
LIBS = -I /Library/Frameworks/SDL.framework/Headers -framework SDL -I /Library/Frameworks/SDL_ttf.framework/Versions/A/Headers -framework SDL_ttf -framework Cocoa
endif
ifeq ($(UNAME),Linux) #Linux based systems
SRC = sdl_gui.c libSDLextra.c libImageProcessing.c
OBJ = sdl_gui.o libSDLextra.o libImageProcessing.o
LIBS = -lSDL -lSDL_ttf
endif
all : $(OUT)
$(OUT) : $(OBJ)
$(CC) $(CFLAGS) $(OBJ) -o $(OUT)
$(OBJ) : $(SRC)
$(CC) $(CFLAGS) -c $(SRC)
clean :
rm -f $(OBJ) $(OUT)
When I do make I've got this error :
gcc -Wall -Wextra -O1 -Wuninitialized -o projet.exe
clang: error: no input files
make: *** [projet.exe] Error 1
I understand the error but I don't know how to fix it.
It looks like you are missing this from (near) the top of the file:
UNAME := $(shell uname)

Makefile command on mac OS shows incorrect output

I am new to Mac OS, and want to execute following makefile program.
GCCBASE = $(GCMDIR)/where/cplusplus/gcc
SRCS:=$(wildcard *.cpp) program.cpp
OBJS:=$(SRCS:.cpp=$(OBJDIR).o)
INCLUDES:=-I. -I$(ADD_INCLUDES)/Auto*.h -I$(ADD_INCLUDES)/program.h
OUTBASE =$(OUTBASE_EX)
OUT_ARTIFACT=Program
ifeq ($(OSNAME),Linux)
ifeq ($(GFLIB_MODEL),64bit)
CXXEXTRA_FLAGS = -m64
GCCDIR = $(GCCBASE)/linux64/4.5.3
GCCLIBDIR_W = $(GCCBASE)/linux64/4.5.3/lib64
GCCLIBDIR = $(GCCLIBDIR_W)
CFLAGS_common += -I$(GCCBASE)/linux64/4.5.3/include
OUTDIR = $(OUTBASE)/64
CFLAGS_link_libs = -L$(GCCLIBDIR) -lmyLib
else
CXXEXTRA_FLAGS = -m32
GCCDIR = $(GCCBASE)/linux/4.5.3
GCCLIBDIR_W = $(GCCBASE)/linux/4.5.3/lib
GCCLIBDIR = $(GCCLIBDIR_W)
CFLAGS_common += -I$(GCCBASE)/linux/4.5.3/include
OUTDIR = $(OUTBASE)/32
CFLAGS_link_libs = -L$(GCCLIBDIR) -lmyLib
endif
endif
ifeq ($(OSNAME),Darwin)
echo "Mac OS"
ifeq ($(GFLIB_MODEL),64bit)
CXXEXTRA_FLAGS = -m64
GCCDIR = $(GCCBASE)/macosx/4.8.1
GCCLIBDIR_W = $(GCCBASE)/macosx/4.8.1/lib
GCCLIBDIR = $(GCCLIBDIR_W)
CFLAGS_common += -I$(GCCBASE)/macosx/4.8.1/include
OUTDIR = $(OUTBASE)/64
CFLAGS_link_libs = -L$(GCCLIBDIR) -lmyLib
else
CXXEXTRA_FLAGS = -m32
GCCDIR = $(GCCBASE)/macosx/4.8.1
GCCLIBDIR_W = $(GCCBASE)/macosx/4.8.1/lib/i386
GCCLIBDIR = $(GCCLIBDIR_W)
CFLAGS_common += -I$(GCCBASE)/macosx/4.8.1/include
OUTDIR = $(OUTBASE)/32
CFLAGS_link_libs = -L$(GCCLIBDIR) -lmyLib
endif
endif
all: $(SRCS)
echo "Building Program application..."
$(CXX) $(CXXEXTRA_FLAGS) $(CFLAGS_common) $(INCLUDES) $^ -o $(OUTDIR)/$(OUT_ARTIFACT) $(CFLAGS_link_libs)
rm -f *.[o] *.log core
Command that gets executed on mac OS looks like this with linker errors since myLib was not found:
[exec] c++ -I. -IAuto*.h -IProgram.h Program.cpp -o /Program
While I am expecting my command to be like this:
[exec] c++ -m32 -I. -IAuto*.h -IProgram.h Program.cpp -o /Program -LmyPath -lmyLib
Why is my command not including -m32 and Linking library path?
I also tried printing CXXEXTRA_FLAGS and CFLAGS_link_libs, but they are empty.
You never set the variables OSNAME or GFLIB_MODEL to any value in this makefile, so they're both empty. Thus neither of the tests for OSNAME are true, and those values are never set in CXXEXTRA_FLAGS etc.
ETA: Here's an example based on your comments:
$ cat Makefile
ifeq ($(OSTYPE),Mac OS X)
$(info got mac)
endif
all: ; #:
$ make
$ make OSTYPE=Mac
$ make OSTYPE='Mac OS X'
got mac

make issue on Linux

I'm trying to debug an issue with a makefile I am working on.. What is confusing is that the target works when I run it from the command line, but does not work in my makefile..
Here is the makefile:
DDS_OUT_DIR = $(PWD)
IDL_DIR=/opt/idl/dds
IDL_TYPES=common.idl
GENERATED_SOURCES = $(IDL_TYPES:%.idl=%Support.cxx) $(IDL_TYPES:%.idl=%Plugin.cxx) $(IDL_TYPES:%.idl=%.cxx)
GENERATED_HEADERS = $(IDL_TYPES:%.idl=%Support.h) $(IDL_TYPES:%.idl=%Plugin.h) $(IDL_TYPES:%.idl=%.h)
OBJS_DIR = obj.$(CPUTYPE)
GENERATED_OBJS = $(GENERATED_SOURCES:%.cxx=$(OBJS_DIR)/%.o)
LIBDIR = ../../lib.$(CPUTYPE)
BINDIR = ../../../../bin.$(CPUTYPE)
CC = $(C_COMPILER)
CXX = $(CPP_COMPILER)
OS = $(shell uname)
DDSCOMMON = ../../Common/src
CFLAGS = -m32 -g
CXXFLAGS = -m32 -g
LDFLAGS = -m32 -static-libgcc
SYSLIBS = -ldl -lnsl -lpthread -lm -lc
DEFINES_ARCH_SPECIFIC = -DRTI_UNIX
DEFINES = $(DEFINES_ARCH_SPECIFIC) $(cxx_DEFINES_ARCH_SPECIFIC)
INCLUDES = -I. -I$(NDDSHOME)/include -I$(NDDSHOME)/include/ndds
INCLUDES += -I$(DDSCOMMON)
LIBS = -L$(NDDSLIBDIR) -L$(LIBDIR) -lrt \
-lnddscppz -lnddscz -lnddscorez $(SYSLIBS) $(OS_SPECIFIC_LIBS)
COMMONLIBSRC = $(DDSCOMMON)/dds_common.cxx
COMMONLIBOBJS = $(DDSCOMMON)/obj.$(CPUTYPE)/%.o
$(shell mkdir -p $(OBJS_DIR) $(DDSCOMMON)/obj.$(CPUTYPE))
default: ${IDL_TYPES} $(GENERATED_OBJS)
$(OBJS_DIR)/%.o : %.cxx %.h $(DDSCOMMON)/dds_common.h
$(CPP_COMPILER) -o $# $(DEFINES) $(INCLUDES) $(CXXFLAGS) -c $<
%.idl:
#echo "Generating CXX from $# ..." $(GENERATED_OBJS); \
$(NDDSHOME)/scripts/rtiddsgen ${IDL_DIR}/$# -d $(DDS_OUT_DIR) -I ${IDL_DIR} -replace -language C++;
if I just do this:
make
The %.idl target is called fine, when that finishes I get this output:
Generating CXX from common.idl ... obj.Linux-i686/commonSupport.o obj.Linux-i686/commonPlugin.o obj.Linux-i686/common.o
Running rtiddsgen version 4.5d, please wait ...
Done
make: *** No rule to make target `obj.Linux-i686/commonSupport.o', needed by `default'. Stop.
But then when I re-run it and everything compiles, so it works fine...
Why is this not working in one step?
commonSupport.cxx seems to depend on common.idl. Tell this to make.
commonSupport.cxx: common.idl
#echo "Generating CXX from $# ..." $(GENERATED_OBJS); \
$(NDDSHOME)/scripts/rtiddsgen ${IDL_DIR}/$# -d $(DDS_OUT_DIR) -I ${IDL_DIR} -replace -language C++;
Or, to ensure all dependencies are right:
$(GENERATED_SOURCES): common.idl
.... steps to make GENERATED_SOURCES from common.idl

make uses "cc" instead of "arm-none-eabi-as"

I have a problem when building a program with makefile. There is only a problem when make tries to compile assembly file named "startup.S". It looks like make uses compiler "cc" even if i specify "arm-none-eabi-as" in a makefile (take a look at variable AS).
Here is my makefile:
SHELL := /bin/bash
ROOT := $(shell pwd)
INC := $(ROOT)/inc
SRC := $(ROOT)/src
STR := $(ROOT)/str
EXE := exe
AS := arm-none-eabi-as -mcpu=arm926ej-s -c -Wall -I $(INC) -I$(SRC) -I $(STR)
GCC := arm-none-eabi-gcc -mcpu=arm926ej-s -c -Wall -I $(INC) -I$(SRC) -I $(STR)
LDSCRIPT := test.ld
LD := arm-none-eabi-ld -T $(LDSCRIPT)
HEADERS := $(notdir $(wildcard $(INC)/*.h))
SOURCES_GCC := $(notdir $(wildcard $(SRC)/*.c))
SOURCES_AS := $(notdir $(wildcard $(STR)/*.S))
OBJECTS_GCC := $(SOURCES_GCC:.c=.o)
OBJECTS_AS := $(SOURCES_AS:.S=.o)
VPATH := $(STR):$(SRC):$(INC)
all : $(EXE)
#echo konec postopka: izvrsljiv program po imenu $(EXE) se nahaja v mapi $(ROOT)
$(EXE) : $(OBJECTS_AS) $(OBJECTS_GCC)
#echo objekti so: $(OBJECTS_AS) $(OBJECTS_GCC)
#echo headerji so: $(HEADERS)
#echo linkanje objektov v izvrsljiv program...
$(LD) -o $# $^
%.o : %.S %h
#echo prevajanje ASSEMBLY izvornih datotek...
$(AS) -o $# $<
%.o : %.c %h
#echo prevajanje C izvornih datotek...
$(GCC) -o $# $<
.PHONY : clean
clean :
#echo brisanje objektov
rm *.o
#echo brisanje izvrsljivega programa
rm $(EXE)
Here is the error i get when typing comand make in a terminal. It clearly tells that "cc" doesnt understand assembly language, and this error is somewhat expected.
cc -c -o startup.o /home/ziga/Dropbox/diploma/86x_linux/IDE_eclipse/eclipse_projects/makefile_8/str/startup.S
/home/ziga/Dropbox/diploma/86x_linux/IDE_eclipse/eclipse_projects/makefile_8/str/startup.S: Assembler messages:
/home/ziga/Dropbox/diploma/86x_linux/IDE_eclipse/eclipse_projects/makefile_8/str/startup.S:4: Error: no such instruction: `b Reset_Handler'
/home/ziga/Dropbox/diploma/86x_linux/IDE_eclipse/eclipse_projects/makefile_8/str/startup.S:5: Error: no such instruction: `b .'
/home/ziga/Dropbox/diploma/86x_linux/IDE_eclipse/eclipse_projects/makefile_8/str/startup.S:6: Error: no such instruction: `b .'
/home/ziga/Dropbox/diploma/86x_linux/IDE_eclipse/eclipse_projects/makefile_8/str/startup.S:7: Error: no such instruction: `b .'
/home/ziga/Dropbox/diploma/86x_linux/IDE_eclipse/eclipse_projects/makefile_8/str/startup.S:8: Error: no such instruction: `b .'
/home/ziga/Dropbox/diploma/86x_linux/IDE_eclipse/eclipse_projects/makefile_8/str/startup.S:9: Error: no such instruction: `b .'
/home/ziga/Dropbox/diploma/86x_linux/IDE_eclipse/eclipse_projects/makefile_8/str/startup.S:10: Error: no such instruction: `b .'
/home/ziga/Dropbox/diploma/86x_linux/IDE_eclipse/eclipse_projects/makefile_8/str/startup.S:11: Error: no such instruction: `b .'
/home/ziga/Dropbox/diploma/86x_linux/IDE_eclipse/eclipse_projects/makefile_8/str/startup.S:14: Error: no such instruction: `ldr sp,=stack_top'
/home/ziga/Dropbox/diploma/86x_linux/IDE_eclipse/eclipse_projects/makefile_8/str/startup.S:15: Error: no such instruction: `bl c_entry'
/home/ziga/Dropbox/diploma/86x_linux/IDE_eclipse/eclipse_projects/makefile_8/str/startup.S:16: Error: no such instruction: `b .'
If i try to compile it manualy using "arm-none-eabi-as startup.S" it compiles fine...
My question would be, why does make uses cc instead arm-none-eabi-as? What am i missing here?
After all of your proposal i managed to make a makefile, that looks like this and it is working:
SHELL := /bin/bash
ROOT := $(shell pwd)
INC := $(ROOT)/inc
SRC := $(ROOT)/src
STR := $(ROOT)/str
EXE := exe
AS := arm-none-eabi-as -mcpu=arm926ej-s -c -Wall -I $(INC) -I$(SRC) -I $(STR)
CC := arm-none-eabi-gcc -mcpu=arm926ej-s -c -Wall -I $(INC) -I$(SRC) -I $(STR)
LDSCRIPT := ldscript_iram_gnu.ld
LD := arm-none-eabi-ld -T $(LDSCRIPT)
HEADERS := $(notdir $(wildcard $(INC)/*.h))
SOURCES_CC := $(notdir $(wildcard $(SRC)/*.c))
SOURCES_AS := $(notdir $(wildcard $(STR)/*.S))
OBJECTS_CC := $(SOURCES_CC:.c=.o)
OBJECTS_AS := $(SOURCES_AS:.S=.o)
VPATH := $(STR):$(SRC):$(INC)
all : $(EXE)
#echo konec postopka: izvrsljiv program po imenu $(EXE) se nahaja v mapi $(ROOT)
$(EXE) : $(OBJECTS_AS) $(OBJECTS_CC)
#echo objekti so: $(OBJECTS_AS) $(OBJECTS_CC)
#echo headerji so: $(HEADERS)
#echo linkanje objektov v izvrsljiv program...
$(LD) -o $# $^
%.o : %.S
#echo prevajanje ASSEMBLY izvornih datotek...
$(AS) -o $# $<
%.o : %.h
%.o : %.c
#echo prevajanje C izvornih datotek...
$(CC) -o $# $<
%.o : %.h
.PHONY : clean
clean :
#echo brisanje objektov
rm *.So
rm *.o
#echo brisanje izvrsljivega programa
rm $(EXE)
When i tried to use same makefile in other project (project for which my makefile has been built from the beginning) which also has same tree structure i get some errors:
make all
objekti so: timer_example.o
headerji so: ea3131_board.h ffconf.h ff.h integer.h lpc313x_cgu_driver.h lpc313x_cgu.h lpc313x_cgu_switchbox.h lpc313x_chip.h lpc313x_crc_driver.h lpc313x_dmac.h lpc313x_dma_driver.h lpc313x_evt_driver.h lpc313x_evt_router.h lpc313x_i2c_driver.h lpc313x_i2c.h lpc313x_intc_driver.h lpc313x_intc.h lpc313x_ioconf_driver.h lpc313x_ioconf.h lpc313x_mci_driver.h lpc313x_mci.h lpc313x_nandc.h lpc313x_nand_driver.h lpc313x_spi_driver.h lpc313x_spi.h lpc313x_sysreg.h lpc313x_timer_driver.h lpc313x_timer.h lpc313x_uart_driver.h lpc313x_uart.h lpc313x_wdt_driver.h lpc313x_wdt.h lpc31xx_vmem_driver.h lpc_api.h lpc_arm922t_arch.h lpc_arm922t_cp15_driver.h lpc_arm_arch.h lpc_bmp.h lpc_colors.h lpc_fat16.h lpc_fat16_private.h lpc_fonts.h lpc_heap.h lpc_helvr10.h lpc_irq_fiq.h lpc_lbecc.h lpc_lcd_params.h lpc_line_parser.h lpc_nandflash_params.h lpc_params.h lpc_rom8x16.h lpc_rom8x8.h lpc_sdmmc.h lpc_string.h lpc_swim_font.h lpc_swim.h lpc_swim_image.h lpc_types.h lpc_winfreesystem14x16.h lpc_x5x7.h lpc_x6x13.h
linkanje objektov v izvrsljiv program...
arm-none-eabi-ld -T ldscript_iram_gnu.ld -o exe timer_example.o
ea3131_startup_entry.o: In function `clearzi_exit':
(.text+0x170): undefined reference to `ea3131_init'
timer_example.o: In function `timer0_user_interrupt':
timer_example.c:(.text+0x15c): undefined reference to `timer_ioctl'
timer_example.o: In function `uart_string_write':
timer_example.c:(.text+0x1dc): undefined reference to `strlen'
timer_example.c:(.text+0x208): undefined reference to `uart_write'
timer_example.o: In function `c_entry':
timer_example.c:(.text+0x258): undefined reference to `ea3131_board_init'
timer_example.c:(.text+0x260): undefined reference to `cp15_set_vmmu_addr'
timer_example.c:(.text+0x268): undefined reference to `int_initialize'
timer_example.c:(.text+0x274): undefined reference to `int_install_irq_handler'
timer_example.c:(.text+0x280): undefined reference to `timer_open'
timer_example.c:(.text+0x2a4): undefined reference to `timer_ioctl'
timer_example.c:(.text+0x2bc): undefined reference to `timer_ioctl'
timer_example.c:(.text+0x2d4): undefined reference to `timer_ioctl'
timer_example.c:(.text+0x2e0): undefined reference to `uart_open'
timer_example.c:(.text+0x2f8): undefined reference to `memcpy'
timer_example.c:(.text+0x32c): undefined reference to `timer_ioctl'
timer_example.c:(.text+0x334): undefined reference to `int_enable'
timer_example.c:(.text+0x38c): undefined reference to `sprintf'
make: *** [exe] Error 1
It looks to me that my makefile is doing OK now, but there are some unresolved references within my project which have nothing to do with my makefile. Still i need your conformation that my makefile is doing OK. Thank you all.
Regards.
Try using CC instead of GCC (which is the variable used in the default make rules), but in this case, it uncovered another issue: your rules were ignored.
what's the "%h" supposed to do?
Also note that your "echo" command isn't executed - another hint that your rules aren't considered by make
Your .o file for assembly is overwrittent by the .o rule for .c file. You don't have to end your object file in .o Try this instead :
OBJECTS_AS := $(SOURCES_AS:.S=.os)
And your assembly rule becomes :
%.os : %.S %h
#echo prevajanje ASSEMBLY izvornih datotek...
$(AS) -o $# $<
Of course you could us .o_assembly or whatever. Object file have to end with .o only if you use implicit rules.

Resources