[CMake] Linking to MySQL C++ Connector libraries using extra flags, Ubuntu 14.04 LTS, gcc

Daniel Schepler dschepler at scalable-networks.com
Wed Apr 29 18:52:16 EDT 2015


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 [cmake-bounces at cmake.org] on behalf of Peleg Bar-Sapir [pelegs at gmail.com]
Sent: Wednesday, April 29, 2015 2:56 PM
To: cmake at cmake.org
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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: FindMariaDB.cmake
Type: text/x-cmake
Size: 1434 bytes
Desc: FindMariaDB.cmake
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150429/b5996cc9/attachment.bin>


More information about the CMake mailing list