{"id":361,"date":"2022-08-30T15:00:04","date_gmt":"2022-08-30T15:00:04","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/06\/makefile-to-compile-opencv-with-cuda-in-ubuntu-stopped-working-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:00:04","modified_gmt":"2022-08-30T15:00:04","slug":"makefile-to-compile-opencv-with-cuda-in-ubuntu-stopped-working-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/makefile-to-compile-opencv-with-cuda-in-ubuntu-stopped-working-collection-of-common-programming-errors\/","title":{"rendered":"makefile to compile opencv with cuda in ubuntu stopped working-Collection of common programming errors"},"content":{"rendered":"<p>I am trying to compile a project on my laptop in which I need both CUDA and opencv. So I have created 3 files<\/p>\n<p>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:<\/p>\n<pre><code>CXX=g++\nCUDA_INSTALL_PATH=\/usr\/local\/cuda\nCFLAGS= -I. -I$(CUDA_INSTALL_PATH)\/include `pkg-config --cflags opencv`\nLDFLAGS= -L$(CUDA_INSTALL_PATH)\/lib64 -lcudart `pkg-config --libs opencv`\n\nall:\n    $(CXX) $(CFLAGS) -c main.cpp -o main.o\n    nvcc $(CUDAFLAGS) -arch=\"sm_21\" -c kernel.cu -o kernel.o\n    $(CXX) $(LDFLAGS) main.o kernel.o -o main\n<\/code><\/pre>\n<p>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&#8217;t give error.<\/p>\n<p>I have built and ran both opencv and cuda sdk samples and they worked fine separately. Can you help me?<\/p>\n<blockquote>\n<p>g++ -L\/usr\/local\/cuda\/lib64 -lcudart <code>pkg-config --libs opencv<\/code> main.o kernel_gpu.o -o grayscale<\/p>\n<p>main.o: In function `main&#8217;:<\/p>\n<p>main.cpp:(.text+0x44): undefined reference to `cv::imread(std::basic_string, std::allocator &gt; const&amp;, int)&#8217;<\/p>\n<p>main.cpp:(.text+0x72): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&amp;)&#8217;<\/p>\n<p>main.cpp:(.text+0xa6): undefined reference to `cv::imshow(std::basic_string, std::allocator &gt; const&amp;, cv::_InputArray const&amp;)&#8217;<\/p>\n<p>main.cpp:(.text+0xc8): undefined reference to `cv::waitKey(int)&#8217;<\/p>\n<p>main.o: In function `cv::Mat::~Mat()&#8217;:<\/p>\n<p>main.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)&#8217;<\/p>\n<p>main.o: In function `cv::Mat::release()&#8217;:<\/p>\n<p>main.cpp:(.text._ZN2cv3Mat7releaseEv[cv::Mat::release()]+0x47): undefined reference to `cv::Mat::deallocate()&#8217;<\/p>\n<p>kernel_gpu.o: In function <code>cuda_BGsub': tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x41): undefined reference to<\/code>cudaConfigureCall&#8217;<\/p>\n<p>kernel_gpu.o: In function <code>cuda_grayscale': tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0xb3): undefined reference to<\/code>cudaConfigureCall&#8217;<\/p>\n<p>kernel_gpu.o: In function <code>cuda_Filter': tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x10d): undefined reference to<\/code>cudaConfigureCall&#8217;<\/p>\n<p>kernel_gpu.o: In function <code>cuda_Noise_reduc': tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x176): undefined reference to<\/code>cudaConfigureCall&#8217;<\/p>\n<p>kernel_gpu.o: In function <code>cuda_RGB': tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x1d9): undefined reference to<\/code>cudaConfigureCall&#8217;<\/p>\n<p>kernel_gpu.o:tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x234): more undefined references to `cudaConfigureCall&#8217; follow<\/p>\n<p>kernel_gpu.o: In function `__cudaUnregisterBinaryUtil()&#8217;:<\/p>\n<p>tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x409): undefined reference to `__cudaUnregisterFatBinary&#8217;<\/p>\n<p>kernel_gpu.o: In function `__device_stub__Z5BGsubPhS_S_iib(unsigned char*, unsigned char*, unsigned char*, int, int, bool)&#8217;:<\/p>\n<p>tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x442): undefined reference to `cudaSetupArgument&#8217;<\/p>\n<p>tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x465): undefined reference to `cudaSetupArgument&#8217;<\/p>\n<p>tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x488): undefined reference to `cudaSetupArgument&#8217;<\/p>\n<p>tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x4a7): undefined reference to `cudaSetupArgument&#8217;<\/p>\n<p>tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x4c6): undefined reference to `cudaSetupArgument&#8217;<\/p>\n<p>kernel_gpu.o:tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x4e5): more undefined references to `cudaSetupArgument&#8217; follow<\/p>\n<p>kernel_gpu.o: In function `<strong>sti_<\/strong>_cudaRegisterAll_45_tmpxft_000016bc_00000000_4_kernel_gpu_cpp1_ii_cdcbb70e()&#8217;:<\/p>\n<p>tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0xe7e): undefined reference to `__cudaRegisterFatBinary&#8217;<\/p>\n<p>tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0xedc): undefined reference to `__cudaRegisterFunction&#8217;<\/p>\n<p>tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0xf29): undefined reference to `__cudaRegisterFunction&#8217;<\/p>\n<p>tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0xf76): undefined reference to `__cudaRegisterFunction&#8217;<\/p>\n<p>tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0xfc3): undefined reference to `__cudaRegisterFunction&#8217;<\/p>\n<p>tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x1010): undefined reference to `__cudaRegisterFunction&#8217;<\/p>\n<p>kernel_gpu.o:tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x105d): more undefined references to `__cudaRegisterFunction&#8217; follow<\/p>\n<p>kernel_gpu.o: In function `cudaError cudaLaunch(char*)&#8217;:<\/p>\n<p>tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text.<em>Z10cudaLaunchIcE9cudaErrorPT<\/em>[cudaError cudaLaunch(char*)]+0x14): undefined reference to `cudaLaunch&#8217;<\/p>\n<p>collect2: ld returned 1 exit status<\/p>\n<p>make: <em>*<\/em> [all] Error 1<\/p>\n<\/blockquote>\n<pre><code>CXX=g++\nCUDA_INSTALL_PATH=\/usr\/local\/cuda\nCFLAGS= -I. -I$(CUDA_INSTALL_PATH)\/include `pkg-config --cflags opencv`\nLDFLAGS= -L$(CUDA_INSTALL_PATH)\/lib64 -lcudart `pkg-config --libs opencv`\n\nall:\n    $(CXX) $(CFLAGS) -c main.cpp -o main.o\n    nvcc $(CUDAFLAGS) -arch=\"sm_21\" -c kernel.cu -o kernel.o\n    $(CXX)  main.o `pkg-config --libs opencv` -L$(CUDA_INSTALL_PATH)\/lib64 -lcudart kernel.o -o main\n<\/code><\/pre>\n<p id=\"rop\"><small>Originally posted 2013-11-06 03:16:39. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>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 &#8211;cflags [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-361","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/361","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=361"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/361\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=361"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}