简体   繁体   中英

Modifying CUDA and cpp Makefile

I am trying to modify my makefile to support .cpp and .cu, however, I keep getting an error such as:

/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o(.text+0x20): error: undefined reference to 'main'
hostCode.o:displayfunc.cpp:function readScene(char*): error: undefined reference to 'camera'
hostCode.o:displayfunc.cpp:function readScene(char*): error: undefined reference to 'camera'
hostCode.o:displayfunc.cpp:function readScene(char*): error: undefined reference to 'camera'
hostCode.o:displayfunc.cpp:function readScene(char*): error: undefined reference to 'camera'
hostCode.o:displayfunc.cpp:function readScene(char*): error: undefined reference to 'sphereCount'
hostCode.o:displayfunc.cpp:function readScene(char*): error: undefined reference to 'sphereCount'
hostCode.o:displayfunc.cpp:function readScene(char*): error: undefined reference to 'sphereCount'
hostCode.o:displayfunc.cpp:function readScene(char*): error: undefined reference to 'spheres'
hostCode.o:displayfunc.cpp:function readScene(char*): error: undefined reference to 'spheres'
hostCode.o:displayfunc.cpp:function readScene(char*): error: undefined reference to 'sphereCount'
hostCode.o:displayfunc.cpp:function idleFunc(): error: undefined reference to 'updateRendering()'
hostCode.o:displayfunc.cpp:function reshapeFunc(int, int): error: undefined reference to 'reInitCamera(bool)'
hostCode.o:displayfunc.cpp:function keyFunc(unsigned char, int, int): error: undefined reference to 'reInitCamera(bool)'

Makefile

CXX = g++
NVCC = nvcc -ccbin $(CXX)


INCLUDES := -I/home/cuda_app/inc/

LDFLAGS = -lGL -lGLU -lglut -lpthread


ALL:= test

test:    hostCode.o deviceCode.o

        $(NVCC) $(INCLUDES) -o $@ $< $(LDFLAGS)

deviceCode.o: SmallPtCUDA.cu

        $(NVCC) $(INCLUDES) -o $@ -c $< $(LDFLAGS)


hostCode.o: displayfunc.cpp

        $(CXX) $(INCLUDES) -o $@ -c $< $(LDFLAGS)

clean:

        rm -rf  *.o  $(ALL)

How can I compile both .cpp and .cu ?

Can anybody help with this please? Thanks

When asking a question about build errors, it's always best to include not just the errors but also the command invoking the compiler or linker. With errors like this the problem is there; seeing the error messages is helpful but not definitive.

In your case the problem is your link command is incorrect in your makefile:

test:    hostCode.o deviceCode.o
        $(NVCC) $(INCLUDES) -o $@ $< $(LDFLAGS)

You are using $< here which expands to just the first prerequisite. If you'd included the link line and examined it you'd see that the deviceCode.o file is not present on the link line. You want your link command to look like this:

test:    hostCode.o deviceCode.o
        $(NVCC) $(INCLUDES) -o $@ $^ $(LDFLAGS)

Using $^ which expands to all the prerequisites.

Also, just a note that by convention LDFLAGS contains linker options like -L , and LDLIBS is used for linker options like -l . However your setup will work (it's just not conventional).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM