Problem compiling openCV and CUDA

I am trying to compile cuda-bgs in linux.
I have commented out 2-3 lines of code that used “conio.h” which is not portable.
If i try to compile with nvcc the main.cpp it says that it can not link the cuda functions.
If i rename it to i get the following error:

Any Ideas how to overcome this?
If i comment out an include line in the cuFastBG… file i can do:
nvcc -c cuFastBG… and end up with an .o file .
Then i use the following command:
g++ CvFastBgGMM_ver5.o main.cpp -o loadimg -I"/usr/include/opencv" -lcxcore -lcv -lhighgui -lcuda -I"/usr/local/cuda/include" -L/usr/local/cuda/lib64 -lcudart

but it produces:
main.cpp:(.text+0x105): undefined reference to cvCreateFastBgGMMParams(int, int)' main.cpp:(.text+0x127): undefined reference to cvCreateFastBgGMM(CvFastBgGMMParams*, _IplImage*)’
main.cpp:(.text+0x162): undefined reference to cvUpdateFastBgGMMTimer(CvFastBgGMM*, _IplImage*)' main.cpp:(.text+0x2bc): undefined reference to cvReleaseFastBgGMM(CvFastBgGMM**)’

if i try and compile main.cpp with g++ it succedes,if i compile the .cu file with nvcc it also succedes.
But if i try:
g++ main.o CvFastBgGMM_ver5.o -I"/usr/include/opencv" -lcxcore -lcv -lhighgui -lcuda -I"/usr/local/cuda/include" -L/usr/local/cuda/lib64 -lcudart
I get the exact same error.
I am attaching you my modified version so you can have a look.

Thank you for your time.

CvFastBgGMM.h (7.8 KB) (21.3 KB)

main.cpp (2.29 KB)

I am on a good way with this.
I found the cuda-grayscale project on google-code and it was literally a life-saver.