I am trying to set up an environment using Eclipse CDT as IDE, but with CMake and Qt. If anyone has done this or have an idea on how it could be done it would me much appreciated.
I can’t help you specifically with CMake and QT, but it’s useful to have a look at common/common.mk, and to check the compiler/linker commands of the CUDA sample projects with ‘make verbose=1’.
Are you building a big C++ main() application and linking in CUDA files, or are you planning to use the CUDA stuff as a shared lib or … ?
Thanks for your reply!
I am thinking of making a library of the CUDA code which I then will call from a regular Qt project written in C++. I think this approach will work, but I haven’t gotten around to test it yet.
What I did was to copy the common.mk file to a project-specific common.mk and hack that to accept the ‘shared=1’ flag, so that I build with “make shared=1”.
I set this to add the “-shared” flag to the GCC linking line in the make process. Then with some more hacking I end up with a libMyProject.so. That, plus a header file, is what I include / link to in my main C++ project.
Currently, my CUDA library needs to be built separately from the main application. It’s inconvenient but works.
I can post my hacked common.mk file here once I’ve cleaned it up a bit. It’s a bit of a ugly hack, so I’d prefer a more mature solution be worked out here in the forum.
Here’s the ‘diff -u’ between common.mk and my common-hax.mk file:
--- /home/krilli/NVIDIA_CUDA_SDK/common/common.mk 2007-12-27 11:27:23.000000000 +0000 +++ common-hax.mk 2008-02-19 19:14:16.000000000 +0000 @@ -45,8 +45,8 @@ # (override directories only if they are not already defined) SRCDIR ?= ROOTDIR ?= .. -ROOTBINDIR ?= $(ROOTDIR)/../bin -BINDIR ?= $(ROOTBINDIR)/linux +ROOTBINDIR ?= ./bin +BINDIR ?= $(ROOTBINDIR) ROOTOBJDIR ?= obj LIBDIR := $(ROOTDIR)/../lib COMMONDIR := $(ROOTDIR)/../common @@ -109,6 +109,12 @@ CFLAGS += -fno-strict-aliasing endif +ifeq ($(shared),1) + EXECUTABLE := lib$(strip $(EXECUTABLE)).so + CXXFLAGS += -shared + BINSUBDIR := lib +endif + # append optional arch/SM version flags (such as -arch sm_11) NVCCFLAGS += $(SMVERSIONFLAGS) @@ -193,6 +199,10 @@ LINKLINE = $(LINK) -o $(TARGET) $(OBJS) $(LIB) endif +ifeq ($(shared), 1) + LINKLINE += -shared +endif + # check if verbose ifeq ($(verbose), 1) VERBOSE :=
Then you have to edit the Makefile to use the hacked common.mk, which is pretty simple.
I’ll take a look at this and try to get it to work. It is as you say a bit inconvenient to build the CUDA stuff in a different project and compile it as a library, but at least it is a solution.
It should be possible to have the CUDA library as a subdir, and automatically building it along with the rest of the project. The thing is that by default, subdirs are usually built with “make all”, but the NVIDIA makefile doesn’t use that terminology, and I gave up on trying to massage it together.
Did you see Wumpus’s Eclipse instructions? I temporarily gave up on figuring them out, but his seems like a better solution. Here they are:
Thanks, but I really don’t want to get involved with Automake and friends. I am trying to make a cross platform app so my alternative is probably CMake. I know it has been done, there is a post here on the forum. It should be easier than hacking your own Makefiles etc. At least this is what I think.
I think you’re right :) Still, the makefile hackery is maybe a good way to get some hints. Can you keep us posted when you have some success? Thanks,
Did you see this thread? Some CMake hints here.