makefile to compile opencv with cuda in ubuntu stopped working-Collection of common programming errors

I am trying to compile a project on my laptop in which I need both CUDA and opencv. So I have created 3 files

In main.cpp I have opencv codes and in kernel.cu I have my kernels. I am using this makefile that I found in another project:

CXX=g++
CUDA_INSTALL_PATH=/usr/local/cuda
CFLAGS= -I. -I$(CUDA_INSTALL_PATH)/include `pkg-config --cflags opencv`
LDFLAGS= -L$(CUDA_INSTALL_PATH)/lib64 -lcudart `pkg-config --libs opencv`

all:
    $(CXX) $(CFLAGS) -c main.cpp -o main.o
    nvcc $(CUDAFLAGS) -arch="sm_21" -c kernel.cu -o kernel.o
    $(CXX) $(LDFLAGS) main.o kernel.o -o main

I had tried the same project on another computer with opencv 2.4.2 ,CUDA 4.0 and gcc 4.4 and it worked fine but now that I try it on my laptop with opencv 2.4.2 ,CUDA 4.2 and gcc 4.6 it keeps returning errors for the last line but it does create main.o and kernel.o and if I comment out the last line it doesn’t give error.

I have built and ran both opencv and cuda sdk samples and they worked fine separately. Can you help me?

g++ -L/usr/local/cuda/lib64 -lcudart pkg-config --libs opencv main.o kernel_gpu.o -o grayscale

main.o: In function `main’:

main.cpp:(.text+0x44): undefined reference to `cv::imread(std::basic_string, std::allocator > const&, int)’

main.cpp:(.text+0x72): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)’

main.cpp:(.text+0xa6): undefined reference to `cv::imshow(std::basic_string, std::allocator > const&, cv::_InputArray const&)’

main.cpp:(.text+0xc8): undefined reference to `cv::waitKey(int)’

main.o: In function `cv::Mat::~Mat()’:

main.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)’

main.o: In function `cv::Mat::release()’:

main.cpp:(.text._ZN2cv3Mat7releaseEv[cv::Mat::release()]+0x47): undefined reference to `cv::Mat::deallocate()’

kernel_gpu.o: In function cuda_BGsub': tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x41): undefined reference tocudaConfigureCall’

kernel_gpu.o: In function cuda_grayscale': tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0xb3): undefined reference tocudaConfigureCall’

kernel_gpu.o: In function cuda_Filter': tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x10d): undefined reference tocudaConfigureCall’

kernel_gpu.o: In function cuda_Noise_reduc': tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x176): undefined reference tocudaConfigureCall’

kernel_gpu.o: In function cuda_RGB': tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x1d9): undefined reference tocudaConfigureCall’

kernel_gpu.o:tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x234): more undefined references to `cudaConfigureCall’ follow

kernel_gpu.o: In function `__cudaUnregisterBinaryUtil()’:

tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x409): undefined reference to `__cudaUnregisterFatBinary’

kernel_gpu.o: In function `__device_stub__Z5BGsubPhS_S_iib(unsigned char*, unsigned char*, unsigned char*, int, int, bool)’:

tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x442): undefined reference to `cudaSetupArgument’

tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x465): undefined reference to `cudaSetupArgument’

tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x488): undefined reference to `cudaSetupArgument’

tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x4a7): undefined reference to `cudaSetupArgument’

tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x4c6): undefined reference to `cudaSetupArgument’

kernel_gpu.o:tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x4e5): more undefined references to `cudaSetupArgument’ follow

kernel_gpu.o: In function `sti__cudaRegisterAll_45_tmpxft_000016bc_00000000_4_kernel_gpu_cpp1_ii_cdcbb70e()’:

tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0xe7e): undefined reference to `__cudaRegisterFatBinary’

tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0xedc): undefined reference to `__cudaRegisterFunction’

tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0xf29): undefined reference to `__cudaRegisterFunction’

tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0xf76): undefined reference to `__cudaRegisterFunction’

tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0xfc3): undefined reference to `__cudaRegisterFunction’

tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x1010): undefined reference to `__cudaRegisterFunction’

kernel_gpu.o:tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x105d): more undefined references to `__cudaRegisterFunction’ follow

kernel_gpu.o: In function `cudaError cudaLaunch(char*)’:

tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text.Z10cudaLaunchIcE9cudaErrorPT[cudaError cudaLaunch(char*)]+0x14): undefined reference to `cudaLaunch’

collect2: ld returned 1 exit status

make: * [all] Error 1

CXX=g++
CUDA_INSTALL_PATH=/usr/local/cuda
CFLAGS= -I. -I$(CUDA_INSTALL_PATH)/include `pkg-config --cflags opencv`
LDFLAGS= -L$(CUDA_INSTALL_PATH)/lib64 -lcudart `pkg-config --libs opencv`

all:
    $(CXX) $(CFLAGS) -c main.cpp -o main.o
    nvcc $(CUDAFLAGS) -arch="sm_21" -c kernel.cu -o kernel.o
    $(CXX)  main.o `pkg-config --libs opencv` -L$(CUDA_INSTALL_PATH)/lib64 -lcudart kernel.o -o main

Originally posted 2013-11-06 03:16:39.