Reputation: 3
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
Upvotes: 0
Views: 145
Reputation: 100836
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).
Upvotes: 1