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



_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to