I'd say that most of the output of mysql_config --cflags and mysql_config
--libs is a bug - for the shared library, there's no need to explicitly include
the pthread etc. libraries (unless, of course, your program also uses them
directly). In CMake terms, they should have been PRIVATE dependencies of the
shared library, rather than PUBLIC. (I don't seem to have been able to
convince the MariaDB Connector/C developers of that, though...)
I'm attaching a file I wrote for our project to enable:
find_package(MariaDB REQUIRED)
include_directories(${MARIADB_INCLUDE_DIR})
target_link_libraries(mainexe ${MARIADB_LIBRARY})
--
Daniel Schepler
________________________________________
From: CMake [[email protected]] on behalf of Peleg Bar-Sapir
[[email protected]]
Sent: Wednesday, April 29, 2015 2:56 PM
To: [email protected]
Subject: [CMake] Linking to MySQL C++ Connector libraries using extra flags,
Ubuntu 14.04 LTS, gcc
Hello,
First, I would like to point out that I'm new to CMake, and I'm not a
professional programer by any means - just a Physics research student.
I looked for answers to my issue online, but couldn't find anything
that helped me. I also asked my peers and friends, but unfortunately
none of them could find an answer as well.
I want to use MySQL connector for C++ in a program. Usually I do this
by using the 'mysql' and 'my_global' libraries, and then run gcc with
this added flag: `mysql_config --cflags --libs`.
Typing this command into my console results in:
$mysql_config --cflags --libs
-I/usr/include/mysql -DBIG_JOINS=1 -fno-strict-aliasing -g -DNDEBUG
-L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -lm -ldl
meaning there are some linking flags that must be given so gcc would
compile my code, apart from just "-lmysql" or "-l/usr/include/mysql".
My question is how do I ensure this works also with CMake? I
understand how to use the CMakeLists.txt file to configure additional
external libraries, but none of them require special flags as above,
at least in my basic use of them. Since there's no module for MySQL
connector, I'm a bit lost here.
Could anyone please give me a some advices, or point me to what should be done?
Thanks,
Peleg Bar Sapir
--
Powered by www.kitware.com
Please keep messages on-topic and check the CMake FAQ at:
http://www.cmake.org/Wiki/CMake_FAQ
Kitware offers various services to support the CMake community. For more
information on each offering, please visit:
CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
if (WIN32)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set(MARIADB_WIN_PATH "C:/Program Files/MariaDB/MariaDB C Client Library 64-bit")
else ()
set(MARIADB_WIN_PATH "C:/Program Files (x86)/MariaDB/MariaDB C Client Library"
"C:/Program Files/MariaDB/MariaDB C Client Library")
endif ()
endif ()
# Look for the header file.
find_path(MARIADB_INCLUDE_DIR NAMES mysql.h
PATH_SUFFIXES include mariadb include/mariadb
PATHS /usr/include/mariadb ${MARIADB_WIN_PATH})
# Look for the library.
find_library(MARIADB_LIBRARY NAMES mariadb libmariadb
mariadbclient libmariadbclient
PATH_SUFFIXES lib mariadb lib/mariadb
PATHS ${MARIADB_WIN_PATH})
# Find version string.
if (MARIADB_INCLUDE_DIR AND EXISTS "${MARIADB_INCLUDE_DIR}/mysql_version.h")
file(STRINGS "${MARIADB_INCLUDE_DIR}/mysql_version.h" mariadb_version_str
REGEX "^#define[\t ]+MARIADB_PACKAGE_VERSION[\t ]+\".*\"")
string(REGEX REPLACE "^#define[\t ]+MARIADB_PACKAGE_VERSION[\t ]+\"(.*)\".*"
"\\1" MARIADB_VERSION "${mariadb_version_str}")
endif ()
# handle the find_package args and set MYSQL_FOUND
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(MARIADB
REQUIRED_VARS MARIADB_LIBRARY MARIADB_INCLUDE_DIR
VERSION_VAR MARIADB_VERSION)
mark_as_advanced(MARIADB_INCLUDE_DIR MARIADB_LIBRARY)
--
Powered by www.kitware.com
Please keep messages on-topic and check the CMake FAQ at:
http://www.cmake.org/Wiki/CMake_FAQ
Kitware offers various services to support the CMake community. For more
information on each offering, please visit:
CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake