how to get all the headerfiles which are used in compiling? - c

I am compiling my SW using Clang (android30) and as my SW is really big, I want to extract only the files which are necessary to compile, so that I can have a smaller SW.
is there anyway to have a list of all the dependencies (header-files and .c file)?
I am using make framework to compie which looks like this:
P
PRJ_ANDROID_COMPILE := $(XXX)/aarch64-linux-android30-clang
PRJ_ANDROID_COMPILE_COMMAND = $(X) \
$(addprefix -D,$(XX)) \
$(addprefix -I ,$(XXXX) $(XXXXX)) \
$(addprefix -isystem ,$(PRJ_ANDROID_SYSTEM_INCLUDES)) \
$(addprefix -include ,$(PRJ_ANDROID_HEADER_INCLUDES)) \
-c $(abspath $<) \
-o $(XXXXX)/$(notdir$*)$(FRW_PROCESSOR_OBJ_EXT);

Related

fatal error: json-c/json.h: No such file or directory Cross compiling on ubuntu x64 for raspberry pi arm

I am trying to compile my code on my Ubuntu x64 laptop for the Raspberry Pi.
I am able to compile and run the code on Ubuntu laptop without any issue. However when I try to compile it for Raspberry Pi I get the following error:
$make
/home/nmohan/Development/arm-bcm2708-linux-gnueabi/bin/arm-bcm2708-linux-gnueabi-gcc -g -Wall -Wextra -I /home/nmohan/github/NiRobot/inc -fPIC -shared -L/home/nmohan/github/NiRobot/Obj_arm -Wl,-rpath=/home/nmohan/github/NiRobot/Obj -o /home/nmohan/github/NiRobot/Obj_arm/libRSXA.so /home/nmohan/github/NiRobot/lib/RSXA.c -lNMT_stdlib -lNMT_log -ljson-c -lc -Ljson-c
/home/nmohan/github/NiRobot/lib/RSXA.c:11:25: fatal error: json-c/json.h: No such file or directory
compilation terminated.
Makefile:101: recipe for target '/home/nmohan/github/NiRobot/Obj_arm/libRSXA.so' failed
make: *** [/home/nmohan/github/NiRobot/Obj_arm/libRSXA.so] Error 1
#---------------------------------------#
# #
# Global Varibles #
# #
#---------------------------------------#
PROJ_DIR = /home/nmohan/github/NiRobot
BIN_DIR = $(PROJ_DIR)/bin
OBJ_DIR = $(PROJ_DIR)/Obj
OBJ_DIR_ARM = $(PROJ_DIR)/Obj_arm
INC_DIR = $(PROJ_DIR)/inc
LIB_DIR = $(PROJ_DIR)/lib
OUT_DIR = $(PROJ_DIR)/bld
OUT_DIR_ARM = $(PROJ_DIR)/bld_arm
CFLAGS = -g -Wall -Wextra -I $(INC_DIR)
SFLAGS = -fPIC -shared
RPATH = -L$(OBJ_DIR) -Wl,-rpath=$(OBJ_DIR)
RPATH_ARM = -L$(OBJ_DIR_ARM) -Wl,-rpath=$(OBJ_DIR)
GCC_DIR = /home/nmohan/Development/arm-bcm2708-linux-gnueabi/bin/arm-bcm2708-linux-gnueabi-gcc
#---------------------------------------#
# #
# Targets #
# #
#---------------------------------------#
OBJS = NMT_stdlib.so \
NMT_log.so \
RSXA.so \
PCA9685.so \
MTDR.so \
CAM_MOTOR_CTRL.so \
HCxSR04.so
#---------------------------------------#
# #
# Dependancies #
# #
#---------------------------------------#
NMT_STDLIB_LIBS = -lc
NMT_LOG_LIBS = -lc \
-lNMT_stdlib \
RSXA_LIBS = -lNMT_stdlib \
-lNMT_log \
-ljson-c \
-lc
PCA9685_LIBS = -lNMT_stdlib \
-lNMT_log \
-lc \
-lwiringPi \
-lcrypt \
-lm \
-lrt \
-lRSXA
MTDR_LIBS = -lNMT_stdlib \
-lNMT_log \
-lwiringPi \
-lPCA9685 \
-lcrypt \
-lm \
-lrt \
-lRSXA
CAM_MOTOR_CTRL_LIBS = -lNMT_stdlib \
-lNMT_log \
-lwiringPi \
-lMTDR \
-lPCA9685 \
-lcrypt \
-lm \
-lrt \
-lRSXA
HCxSR04_LIBS = -lNMT_log \
-lNMT_stdlib \
-lRSXA \
-lwiringPi \
-lcrypt \
-lm \
-lrt
TARGET_OBJS := $(foreach OBJ,$(OBJS),$(OBJ_DIR)/lib$(OBJ))
TARGET_OBJS_ARM := $(foreach OBJ,$(OBJS),$(OBJ_DIR_ARM)/lib$(OBJ))
all: $(TARGET_OBJS) \
$(TARGET_OBJS_ARM)
.PHONY: all
$(OBJ_DIR)/lib%.so: $(LIB_DIR)/%.c $(INC_DIR)/%.h
gcc $(CFLAGS) $(SFLAGS) $(RPATH) -o $# $< $($(*)_LIBS)
$(OBJ_DIR_ARM)/lib%.so: $(LIB_DIR)/%.c $(INC_DIR)/%.h
$(GCC_DIR) $(CFLAGS) $(SFLAGS) $(RPATH_ARM) -o $# $< $($(*)_LIBS)
$(OBJ_DIR)/lib%.so: $(LIB_DIR)/%.cpp $(INC_DIR)/%.hpp
g++ $(CFLAGS) $(SFLAGS) $(RPATH) -o $# $< $($(*)_LIBS)
It depends on json-c/json.h. You need to include these files that were not found.
Installing libjson-c-dev package.
sudo apt install libjson-c-dev
I've had a similar problem. It's because of the json.h which is not part of the, in my case, gcc-arm-10-3-2017.07...-aarch64-none-linux-gnu.
I simply cloned json-c git and compiled it with the cross-compiler, too. Then you can reference to the output, or you can inlcude the whole git into your project and compile it all in one.

Makefile path issues

I've .c files in different subfolders within main src directory, I've the problem with running Makefile, I'm new to Makefile, need hands on the Makefile to work and to create a static library.
src/math/addition/add.c (+add.h)
int add(int a, int b) {return a + b;}
src/math/subtraction/sub.c (+sub.h)
int sub(int a, int b) {return a - b;}
src/math/math.c
#include "addition/add.h"
#include "subtraction/sub.h"
Makefile (at the root of the project)
SRC=src/math/Math.c src/math/Math.h src/math/addition/add.c src/math/addition/add.h src/math/subtraction/sub.c src/math/subtraction/sub.h
INCLUDE_PATH=src/
Math: bin
ar rcs libMath.a Math.o
bin:
mkdir bin/
for dir in $(SRC); do \
cd $$dir; \
gcc -c *.c -I../; \
mv *.o ../../../bin; \
cd -; \
done
If you believe there's a better way or any lateral thinking, I'm not fixated on anything.
Makefile is good at two things: building dependency graphs and executing steps between each node in the dependency graphs.
If you have access to GNUMake (most of us do; it's pretty much the only one anyone uses), you can use VPATH to tidy up a bit. VPATH is used to tell make where it can find source files. Be careful with it, if you have multiple files with the same name under different directories.
I suggest you use something akin to the following
VPATH := src src/math src/math/addition src/math/subtraction
CFLAGS += -Isrc -Isrc/math -Isrc/mathaddition -Isrc/math/subtraction
all: libMath
libMath: bin/Math.o bin/add.o bin/sub.o
ar rcs libMath bin/Math.o bin/add.o bin/sub.o
bin/%.o: %.c %.h
Make contains a default .c -> .o rule which you can use; the %.o: %.c %.hdoes this, but also declares that all .o files, by default, depend on a .c and a .h file with the same prefix (the % part) as the object file.
I suspect your Math.o target will also depend on the addition.h and subtraction.h files; you can declare Math.o as dependent on those files using the rule Math.o: Math.c Math.h addition.h subtraction.h.
Remember to substitute the space before ar, with a tab.
You may want to change how you organize your source files and/or header files.
Usually ar produces archive files that end in .a. You may want to change that as well.
If you use make right, you can use parallel builds (make -J) to really speed up compilation time; if you use it wrong, everything is going to get slower and we'll have yet another person who starts to hate make because they don't understand it.
Makefile:
#
# Boilerplate.
#
all:
define add_target
$(info add_target($1))
$(eval $(eval_args))
$(eval $(call eval_args,$1,\
OBJDIR := $(firstword $($1.OBJDIR) ./objs/$1),\
))
$(eval $(call eval_args,$1,\
TYPE := $(firstword $($1.TYPE) binary),\
))
$(eval $(call eval_args,$1,\
objs := $(obj_from_source),
))
$(eval $1 := $($1.TARGET))
TARGETS += $($1)
PHONY_TARGETS += $1
CLEAN_TARGETS += clean_$1
.PHONY: clean_$1
clean_$1:; rm -rf $($1.OBJDIR) $($1)
.PHONY: $1
$1: $($1)
$($1): target:=$1
$($1): $($1.objs); $$(if $$(wildcard $$(#D)),,mkdir -p $$(#D) && )$$(add_target.link)
$($1.objs):; $$(if $$(wildcard $$(#D)),,mkdir -p $$(#D) && )$$(add_target.compile)
$(foreach $1.SOURCES,$($1.SOURCES),$(eval $(obj_from_source): $($1.SOURCES)))
$(info end)
endef
void :=
space := $(void) $(void)
obj_from_source = $(addprefix $($1.OBJDIR)/,$(addsuffix .o,$(basename $(notdir $($1.SOURCES)))))
eval_args = $(foreach i,2 3 4 5 6 7 8 9,$(call eval_arg,$1,$(strip $($i))))
eval_arg = $(if $2,$(info $(space)$(space)$1.$2)$(eval $1.$2))
# Link command line
add_target.link_binary = $(CC) $($(target).LDFLAGS) -o $# $^
add_target.link_lib = $(AR) rcs $# $^
add_target.link = $(add_target.link_$($(target).TYPE))
# Compile command line
add_target.compile = $(CC) -c -o $# $($(target).CFLAGS) $<
# -- Directories --
SRC_ROOT := ./src
BIN := ./bin
# Add 'math' target to the project
$(eval $(call add_target,math,\
TYPE := lib,\
TARGET := $(BIN)/math.a,\
SOURCES += ${SRC_ROOT}/math/addition/add.c\
${SRC_ROOT}/math/subtraction/sub.c\
${SRC_ROOT}/math/math.c,\
CFLAGS := -Wall -I./$(SRC_ROOT)/math,\
))
all: ${PHONY_TARGETS}
.PHONY: all
clean: | $(CLEAN_TARGETS)
.PHONY: clean
Directory structure:
$ find
.
./Makefile
./src
./src/math
./src/math/addition
./src/math/addition/add.c
./src/math/addition/add.h
./src/math/math.c
./src/math/subtraction
./src/math/subtraction/sub.c
./src/math/subtraction/sub.h
File contents:
$ find src/ -type f -exec sh -c "echo Contents of {} file:; cat {}; echo" \;
Contents of src/math/addition/add.c file:
int add(int a, int b) {return a + b;}
Contents of src/math/addition/add.h file:
int add(int a, int b);
Contents of src/math/math.c file:
#include "addition/add.h"
#include "subtraction/sub.h"
Contents of src/math/subtraction/sub.c file:
int add(int a, int b) {return a - b;}
Contents of src/math/subtraction/sub.h file:
int add(int a, int b);
Running Makefile:
$ make
add_target(math)
math.TYPE := lib
math.TARGET := ./bin/math.a
math.SOURCES += ./src/math/addition/add.c ./src/math/subtraction/sub.c ./src/math/math.c
math.CFLAGS := -Wall -I././src/math
math.OBJDIR := ./objs/math
math.TYPE := lib
math.objs := ./objs/math/add.o ./objs/math/sub.o ./objs/math/math.o
end
mkdir -p objs/math && cc -c -o objs/math/add.o -Wall -I././src/math src/math/addition/add.c
cc -c -o objs/math/sub.o -Wall -I././src/math src/math/subtraction/sub.c
cc -c -o objs/math/math.o -Wall -I././src/math src/math/math.c
mkdir -p bin && ar rcs bin/math.a objs/math/add.o objs/math/sub.o objs/math/math.o
This general purpose makefile is missing some important features, like tracking .h file dependencies, linking with static/dynamic libraries, etc. Extend it with the features you need yourself.

How can I give the sourcefilepaths to gcc?

How can I give my sourcepaths to gcc?
I have my .c files in source and test directory.
How can I give gcc the path to it? Im compiling with amakefile` and always get the message
"no such file or directory test.c"
My directory structure:
make-directory|
|
|--source
|
|--Header
|
|--test
|
|--out
|
as asked:
# makefile to generate UNIT-tests
# define any directories containing header files other than /usr/include
# TODO
HEADERS = :../CUnit/headers \
CUnit/sources/Automated \
CUnit/sources/Basic \
CUnit/sources/Console \
CUnit/sources/Curses \
CUnit/sources/Framework \
CUnit/sources/Test \
CUnit/sources/Win \
CUnit/sources/wxWidget \
stub \
../source \
test
SOURCES = CUnit/headers \
CUnit/sources/Automated \
CUnit/sources/Basic \
CUnit/sources/Console \
CUnit/sources/Curses \
CUnit/sources/Framework \
CUnit/sources/Test \
CUnit/sources/Win \
CUnit/sources/wxWidget \
stub \
source \
test
# define any libraries to link into executable:
# if I want to link in libraries (libx.so or libx.a) I use the -llibname
# option, something like (this will link in libmylib.so and libm.so:
LIBS =
# TODO define the C source files
TST_SRCS = min.c max.c
SRCS = CUnit.c Automated.c Basic.c Console.c CUCurses.c CUError.c Cunit_intl.c \
MyMem.c TestDB.c TestRun.c Util.c wxWidget.c \
$(TST_SRCS)
# define the C object files
#
# This uses Suffix Replacement within a macro:
# $(name:string1=string2)
# For each word in 'name' replace 'string1' with 'string2'
#OBJ = $(SRCS:%.c=%.o)
OBJ = $(TST_SRCS:%.c=%.o)
#OBJ=$(join ($(SOURCES)), $(notdir $(SRCS:%.c=%.o)))
# define the C compiler to use
CC = gcc
# define any compile-time flags
CFLAGS = -O0 -g -Wall -fmessage-length=0 -fprofile-arcs -ftest-coverage
#TODO Linkerflags
LFLAGS = --coverage
VPATH=source
# define the executable file,
TARGET = CUnit
all:
$(CC) -I $(HEADERS) $(CFLAGS) $(OBJ) -o $(TARGET) $(LFLAGS)
You can make use of vpath or VPATH in makefile to point to the directory containing the source files.
See the online gnu make manual here.

Automake + libtool: pattern rule for per-object CFLAGS?

I'm using GNU Automake and libtool to compile my program. My Makefile.am looks like this:
lib_LTLIBRARIES = \
libObjectively.la
libObjectively_la_SOURCES = \
Array.c \
Class.c \
Condition.c \
Date.c \
DateFormatter.c \
Dictionary.c \
Lock.c \
Log.c \
Object.c \
String.c \
Thread.c
libObjectively_la_CFLAGS = \
-I ..
libObjectively_la_LDFLAGS = \
-pthread \
-shared
Everything compiles just fine. However, I would like to set CFLAGS for each source file using a pattern rule as well. In regular old Makefile syntax, this would look something like:
%.o: %.c
$(CC) $(CFLAGS) -D__Class=$(subst .o,,$#) -o $# $<
Is there a way to do this with Automake + libtool?
Turns out, there is no portable way to do this sort of thing.

Problems with linking CUDA for running fastHOG algorithm

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

Resources