Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using MySQL in XCODE for C++ project

Currently, I have a project in C++ where i have to get a mysql database and ask for tablevalues. I understand that now I have to import the mysql library.

So I do so by going to this site: MySQL Mac OSX 10.7 (64bit)

Now that I have successfully downloaded the files and imported the include folder and libraries that the folder contains, I get this error in the mysql.driver.h file I imported with the rest of the mysql files in the folder I just recently downloaded ...

#include <boost/scoped_ptr.hpp> // 'boost/scoped_ptr.hpp' file not found

So this is telling me that this templated header file was not found...

Do I need to download the boost library now? I did and imported BOOST into my project but it just gave me more errors...

Anyone ran into this same issue before or can help? :) I'd greatly appreciate it!

EDIT

I also read up on a forum in the mySQL webpage and saw that I would need to add linker flags and header/library search paths? I did this but nothing helped :(

Header Search Paths - /usr/local/mysql/include

Library Search Paths - /usr/local/mysql/lib

Other Linker Flags -lz -lm -lmysqlclient
like image 734
jsetting32 Avatar asked Mar 10 '26 16:03

jsetting32


1 Answers

I am a newbie and had a hard time on getting the C++ connector for mysql to work under Xcode. These are the steps necessary for it to work:

  1. Download the MySQL C connector dmg package and install it. This package installs in /usr/local/mysql-connector.... Rename that folder to mysql. (in order to view the /usr folder in finder click on the GO menu and then on GO TO FOLDER once there type in /usr.)
  2. Download the MySQL C++ connector binary. Uncompress it by double clicking the file. Once the file uncompresses, create a folder named mysqlCPP in /usr/local/ (you will now have a folder named mysql and mysqlCPP). Now copy the folders /include and /lib from the uncompressed C++ connector folder to the mysqlCPP folder you just created.
  3. Download the BOOST library from boost.org. Uncompress the downloaded file and copy the boost directory to /usr/local/. (now you should have /mysql /mysqlCPP /boost directories here. There may be additional system folders DONT DELETE THEM.

Now on XCODE open your project and in Build Settings do the following:

  1. Look for OTHER LINKER FLAGS, double click and add the following: -lz -lm -lmysqlcppconn-static (this builds a static reference and a bigger executable, if you wish to link dynamically you need type -lz -lm -lmysqlcppconn but you MUST COPY THE dynamic library into the EXECUTION directory of the file. Add to all options under OTHER LINKER FLAGS.
  2. Look for HEADER SEARCH PATHS, double click and add the following /usr/local/mysqlCPP/include, /usr/local/mysql/include and /usr/local/ all should be added non-recursive. Don't forget to type in for all inputs Debug, Release, Any Architecture, etc.
  3. Look for LIBRARY SEARCH PATHS, double click and add the following: /usr/local/mysql/lib and /usr/local/mysqlCPP/lib. Don't forget to type in for all inputs Debug, Release, Any Architecture, etc. Now you have both installed Connector-C and Connector-C++.
  4. Look for C++ Standard Library and choose the libstdc++ (GNU C++ standard library)

Now you should be set and ready to compile C++ programs. If you wish to use the C connector instead then you should change the OTHER LINKER FLAGS to: -lm -lz -lmysqlclient. Just try with any of the samples on mysql.com and both connectors should work.

like image 71
GAC Avatar answered Mar 12 '26 07:03

GAC