2014-05-06 24 views
0

我想在我的linux服務器上設置fastHOG代碼庫,但無法完成它,因爲我正在獲取堆鏈接錯誤。我在這裏給出了鏈接錯誤的示例部分鏈接CUDA運行fastHOG算法的問題

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' 

看起來鏈接器沒有意識到make文件中提供的任何鏈接器庫。它並沒有說什麼,如「無法找到這個庫」,但它避免了被鏈接如

# 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 

我能創造所有的目標文件,但在問題正在添加提供了有關庫中的所有信息鏈接過程中,我是CUDA的新手,任何人都可以幫我解決這個問題嗎?

我的操作系統是64位Linux

編輯:在common.mk文件

################################################################################ 
# 
# 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 [email protected] -c $< 

$(OBJDIRUTILS)/%.cpp.o : $(SRCDIRUTILS)%.cpp $(C_DEPS) 
    $(VERBOSE)$(CXX) $(CXXFLAGS) -o [email protected] -c $< 

$(OBJDIR)/%.cpp.o : $(SRCDIR)%.cpp $(C_DEPS) 
    $(VERBOSE)$(CXX) $(CXXFLAGS) -o [email protected] -c $< 

$(OBJDIRHOG)/%.cpp.o : $(SRCDIRHOG)%.cpp $(C_DEPS) 
    $(VERBOSE)$(CXX) $(CXXFLAGS) -o [email protected] -c $< 

$(OBJDIR)/%.cu.o : $(SRCDIR)%.cu $(CU_DEPS) 
    $(VERBOSE)$(NVCC) $(NVCCFLAGS) $(SMVERSIONFLAGS) -o [email protected] -c $< 

$(OBJDIRHOG)/%.cu.o : $(SRCDIRHOG)%.cu $(CU_DEPS) 
    $(VERBOSE)$(NVCC) $(NVCCFLAGS) $(SMVERSIONFLAGS) -o [email protected] -c $< 

$(CUBINDIR)/%.cubin : $(SRCDIR)%.cu cubindirectory 
    $(VERBOSE)$(NVCC) $(CUBIN_ARCH_FLAG) $(NVCCFLAGS) $(SMVERSIONFLAGS) -o [email protected] -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 [email protected] -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) 
+0

很明顯,CUDA運行時庫(libcudart)沒有被鏈接。爲什麼發生這種情況是不可能的,因爲你沒有顯示鏈接命令。 Makefile的片段不足以診斷問題的根本原因。 – talonmies

+0

我已經添加了所有的片段,請你再看一遍嗎? – user3606519

+0

修改時破壞了common.mk文件。我已經投票結束這個 - [SO]不是一個錯字發現服務,這個問題將永遠不會對任何人有用,除了你。 – talonmies

回答

0

的我的生成文件

# 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 

內容的common.mk已經被打破(大概您對此作出的修改):

LIB := /pkg/suse11/cuda/4.2/sdk/CUDALibraries/common/FreeImage/lib/linux/libfreeimage64.a 

這無疑不是你想要的,它正在銷燬上面指定的所有精心設計的庫依賴項。我想你打算像

LIB += /pkg/suse11/cuda/4.2/sdk/CUDALibraries/common/FreeImage/lib/linux/libfreeimage64.a