[CMake] Beginner's Question: Organizing Projects

Dominik Gabi dkgispam at gmail.com
Thu Oct 28 08:23:13 EDT 2010


On Wed, 2010-10-27 at 10:54 -0500, Ryan Pavlik wrote:
> On Wed, Oct 27, 2010 at 9:04 AM, Rolf Eike Beer <eike at sf-mail.de> wrote:
> >> Thanks. The way I understand this is that now instead of
> >>
> >> include_directories(${GTKMM_INCLUDE_DIRS})
> >>
> >> i would write something like
> >>
> >> include_directories(${GTKMM_INCLUDE_DIRS})
> >> # and at the end of the file
> >> set(INCLUDE_DIRECTORIES ${INCLUDE_DIRECTORIES} PARENT_SCOPE)
> >>
> >> ? I'd do the same with the LINK_DIRECTORIES, LINK_LIBRARIES property and
> >> for all other libraries?
> >
> > Don't set LINK_DIRECTORIES and LINK_LIBRARIES. When you are a beginner
> > probably every usage of them is wrong.
> >
> > You simply do
> >
> > TARGET_LINK_LIBRARIES(mytarget ${GTK_LIBRARIES}) (or however that is called)
> >
> > The only thing you need to "export upwards" in this case would be the
> > GTK_LIBRARIES variable.
> >
> > Eike
> 
> This is good advice, however, in most cases, since you're using
> pkgconfig directly (which is not the recommended way), that will cause
> more failure.  Best thing to do is to create/find a cmake module for
> each of those packages, that might use pkgconfig for help finding the
> library, but that doesn't just use what it returns verbatim.
> 
> Ryan
> 

As it turns out, my problems are probably not cmake related. Thanks for
the help anyway.

Maybe it's my limited understanding of C++. So here's the problem. The
project structure is as before. I've got a ui directory that uses
classes from the geometry directory. I've set up a simple test class in
the geometry directory that I use in some file in ui.

// Test.h
class Test
{
	public:
		static void test();
};

// Test.cpp
#include "Test.h"
#include <iostream>
void Test::test()
{
	std::cout << "Hello World!" << std::endl;
}

With these two files it works perfectly fine. Everything compiles, links
and runs without problems. Unfortunately, as soon as I add templates the
situation is different:

// Test.h
template<class T>
class Test
{
public:
static void test();
};

// Test.cpp
#include "Test.h"
#include <iostream>
template<class T>
void Test<T>::test()
{
std::cout << "Hello World!" << std::endl;
}

results in the following error (I've left out the name spaces above for
clarity):

dominik at DMac:Pixels$ make
Scanning dependencies of target Ui
[ 33%] Building CXX object ui/CMakeFiles/Ui.dir/MainWindow.cpp.o
Linking CXX static library libUi.a
[ 33%] Built target Ui
[ 66%] Built target Geometry
Linking CXX executable Pixels
ui/libUi.a(MainWindow.cpp.o): In function
`UI::MainWindow::start_application(int, char**)':
MainWindow.cpp:(.text+0x9e1): undefined reference to
`GE::Test<double>::test()'
collect2: ld returned 1 exit status
make[2]: *** [Pixels] Error 1
make[1]: *** [CMakeFiles/Pixels.dir/all] Error 2
make: *** [all] Error 2

I don't get it, can anyone explain this to me?

Dominik.




More information about the CMake mailing list