On the command line, the following produces an executable:
g++ -o a.out main.cpp class1.cc class2.cc /usr/lib/libgsl.a /usr/lib/libgslcblas.a
However I am unsure how to get cmake to work properly. When I add a line like
include_directories(/usr/lib/)
link_libraries(usr/lib/libgsl.a usr/libgslcblas.a)
the configuring seems to work but building fails:
CMakeFiles/kmv.dir/main.o: In function `main':
main.cpp:27: undefined reference to `gsl_matrix_alloc'
main.cpp:35: undefined reference to `gsl_matrix_fscanf'
collect2: ld returned 1 exit status
make[2]: *** [kmv] Error 1
make[1]: *** [CMakeFiles/kmv.dir/all] Error 2
make: *** [all] Error 2
*** Failed ***
Seems to be a synthax problem. Any hint is welcome. Thank you.
Instead of
include_directories(/usr/lib)
link_libraries(usr/lib/libgsl.a usr/libgslcblas.a)
try
add_executable (targetName main.cpp class1.cc class2.cc)
target_link_libraries(targetName gsl gslcblas)
Where targetName is the name of the output binary you intend to create. The path /usr/lib
should already be in the default library search path for CMake, so you shouldn't have to specify that, but if you did have to specify a custom library path, you would do it like so
link_directories(/some/custom/library/path)
The include_directories
CMake directive is used for adding header search paths, not library search paths...
Probably, link_libraries is deprecated
http://www.cmake.org/pipermail/cmake/2009-April/028439.html
Try using target_link_libraries instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With