[CMake] Undefined symbols when header file with code is included
Nicholas Kinar
n.kinar at usask.ca
Fri Aug 27 15:27:13 EDT 2010
>
> 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.
>
My mistake; linking with code contained in a header file actually works
quite well in CMake. Just as the error says, the problem was due to an
undefined symbol. In the file my_util.h, I changed
template <class T>
void load_matrix(std::string fileName, TNT::Array2D<double> *M)
to
void load_matrix(std::string fileName, TNT::Array2D<T> *M)
I was then able to successfully compile and link my program.
Nicholas
More information about the CMake
mailing list