rocketas
rocketas

Reputation: 1707

These compiler options into a CMakeLists.txt

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>

Upvotes: 4

Views: 815

Answers (2)

Peter Clark
Peter Clark

Reputation: 2943

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).

Upvotes: 3

lazycoder
lazycoder

Reputation: 336

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.

Upvotes: 5

Related Questions