"undefined reference to " error jpeglib.h

Hi all,

I am a beginner to CUDA and having a difficulty compiling a program. The error message when I typed “make” is following:

[codebox]/tmp/cc86tU8n.o: In function `Store_Image(unsigned char*, char*, int, int)':

utils.c:(.text+0x215): undefined reference to `jpeg_std_error’

utils.c:(.text+0x239): undefined reference to `jpeg_CreateCompress’

utils.c:(.text+0x2ad): undefined reference to `jpeg_stdio_dest’

utils.c:(.text+0x2e1): undefined reference to `jpeg_set_defaults’

[/codebox]

I guess that those error messages are related to jpeglib.h included in utils.c. When I compile utils.c without CUDA, I put “/usr/lib/libjpeg.so.62” at the end of the compile command. The thing is that I don’t know how to include extra libraries under CUDA environment.

For example, normally I do…

[codebox] gcc -g -o $@ $(OBJECTS) /usr/lib/libjpeg.so.62 [/codebox]

how can I do this in CUDA?

Below is Makefile that I have from template code.

[codebox]# Add source files here

EXECUTABLE := practice

CUDA source files (compiled with cudacc)

CUFILES := practice.cu

CUDA dependency files

CU_DEPS := \

    practice_kernel.cu \

    utils.h \

C/C++ source files (compiled with gcc / c++)

CCFILES := \

    practice_gold.cpp \

    utils.c \

############################################################

####################

Rules and targets

include …/…/common/common.mk

[/codebox]

I am not sure where I should edit. Should I compile each files separately? or is there any file that I should edit to include the extra library?

Thank you for reading, and really hope for a help. Thanks again.

Don’t bother using the SDK makefile, it is byzantine and poorly designed and isn’t intended for anything other than building the SDK examples. Just use what ever you are used to. Add a rule for compiling .cu files with nvcc, and add the include path and library path for the cuda toolkit, and you are done. In GNU make, something like this

NVCC			:= $(CUDAHOME)/bin/nvcc

COMPILE.nvcc:= $(NVCC) $(NVCCFLAGS)

%.cu.o : %.cu 

		 $(COMPILE.nvcc) -o $@ $<

will comple a .cu file into a regular object file you can link with gcc. You need to set CUDAHOME to wherever you have installed the toolkit, and pass

-L$(CUDAHOME)/lib -lcuda

or

-L$(CUDAHOME)/lib64 -lcuda

to the linker (the first 32 bit and the second 64 bit) to include the CUDA libraries and you should be good to go.

However:

gcc -g -o $@ $(OBJECTS) /usr/lib/libjpeg.so.62

isn’t how you should do that. This is how is should be done:

gcc -g -o $@ $(OBJECTS) -ljpeg

Thank you very much!!! =D I really appreciate that.