I am trying to create a CMakeLists.txt out of the inline compile options-
g++ -Wall -I/usr/include/cppconn -o testapp tester.cpp -L/usr/lib -lmysqlcppconn
I expected the following to work
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
set(CMAKE_C_FLAGS "-Wall")
project(testapp)
find_package(PCL 1.4 REQUIRED)
include_directories(. "/usr/include/cppconn")
link_directories("/usr/lib/" "mysqlcppconn")
add_executable(testapp tester.cpp)
But in make
I get undefined reference errors for the above library's content. Am I misunderstanding include_directories
and/or link_directories
?
My tester.cpp includes are this
#include <stdlib.h>
#include <iostream>
#include <mysql_connection.h>
#include <driver.h>
#include <exception.h>
#include <resultset.h>
#include <statement.h>
You also need to actually link against the library, link_directories()
only specifies multiple directories.
You need to add
target_link_libraries(testapp mysqlcppconn)
after add_executable()
also you should be able to skip the link_directories()
completely /usr/lib
is usually in the library search path by default.
You aren't actually specifying the libraries you want to link to anywhere, see the documentation for link_directories (all it takes is a list of directories). You'll want to look into target_link_libraries. You may also want to look into find_library and "find modules" for the preferred way of handling 3rd party libraries with CMake (though you don't necessarily need to).
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