[CMake] Undefined symbols when header file with code is included

Nicholas Kinar n.kinar at usask.ca
Fri Aug 27 14:58:41 EDT 2010


  Hello,

Since I often use a number of C++ helper functions for my daily 
programming tasks, I've written a header file (my_util.h) which is then 
included into a source file (i.e. model.cpp).  All helper function code 
is contained within the header file, and there is not a corresponding 
my_util.cpp file which includes my_util.h.  Normally I've found that 
this works fine when compiling a program with the Eclipse IDE, but I've 
run into a snag when trying to do the same thing with CMake.

In my CMakeLists.txt file, I am using the line:

include_directories(/Volumes/FILES/CODE-LIBRARY/utilities)

I believe that this should be sufficient to let CMake know that my 
header file is in this particular directory, but when I run the 
generated makefile, I receive the following error:

Undefined symbols:
   "void util::load_matrix<double>(std::basic_string<char, 
std::char_traits<char>, std::allocator<char> >, TNT::Array2D<double>*)", 
referenced from:
       run_test()    in model.cpp.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make[2]: *** [model] Error 1
make[1]: *** [CMakeFiles/model.dir/all] Error 2
make: *** [all] Error 2
Matilda-2:FDTD-model-1 nicholaskinar$

What am I doing wrong, and what do I have to modify to let CMake link my 
header file with the output executable?  I am building my project on 
UNIX (Mac OS X and Linux) systems using CMake 2.8.2.

Nicholas


More information about the CMake mailing list