I'd put debugging statements in to see what is being returned as 
MYSQL_INCLUDE_DIR and MYSQL_LIBRARY; and if those look correct, I'd run "make 
VERBOSE=1" to check exactly what's on the compilation command line.
-- 
Daniel
________________________________________
From: Peleg Bar-Sapir [pel...@gmail.com]
Sent: Wednesday, April 29, 2015 4:46 PM
To: Daniel Schepler
Cc: cmake@cmake.org
Subject: Re: [CMake] Linking to MySQL C++ Connector libraries using extra 
flags, Ubuntu 14.04 LTS, gcc

Hello Daniel,

Thanks for your help.
I took your file and plagiarized it, replacing
"MariaDB"/MARIADB"/"mariadb" with "MySQL"/"MYSQL"/"mysql" accordinly -
and did the same for the CMakeLists.txt (I put FindMySQL.cmake in
/CMake/Modules). Running 'cmake .' now gives no error, but running
make gives me still the linking error:

$ make
[100%] Building CXX object
CMakeFiles/entity_find_visual.dir/entity_find_visual.cpp.o
/home/[...]/find_visual/entity_find_visual.cpp:17:19: fatal error:
mysql.h: No such file or directory
 #include <mysql.h>
                   ^
compilation terminated.
make[2]: *** [CMakeFiles/entity_find_visual.dir/entity_find_visual.cpp.o]
Error 1
make[1]: *** [CMakeFiles/entity_find_visual.dir/all] Error 2
make: *** [all] Error 2

This is almost exactly what happens when I run a Makefile without the flag:

$make foo
g++ foo.cpp foolib.cpp -o foo `pkg-config --cflags --libs gsl` -std=c++11
In file included from foo.cpp:5:0:
foolib.h:16:23: fatal error: my_global.h: No such file or directory
 #include <my_global.h>
                       ^
compilation terminated.

Am I missing something?

Peleg

On Thu, Apr 30, 2015 at 12:52 AM, Daniel Schepler
<dschep...@scalable-networks.com> wrote:
> 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-boun...@cmake.org] on behalf of Peleg Bar-Sapir 
> [pel...@gmail.com]
> Sent: Wednesday, April 29, 2015 2:56 PM
> To: cmake@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
>

-- 

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

Reply via email to