"Never memorize something you can look up", Albert Einstein

XCode C MySQL Connector

I found out adding the MySQL library to XCode was more work than I excepted. So here’s a short overview of everything you need to configure for XCode to build against MySQL.

  1. Download MySQL Connector for C
    https://dev.mysql.com/downloads/connector/c/
  2. Start a new project in XCode (DUH!)
  3. Add ‘lib/libmysqlclient.dylib’ to ‘Link Binary With Libraries’
    Link Binary With Libraries ‘Link Binary With Libraries’ can be found in Targets, executable. If you’ve done this right you see the libmysqlclient.dylib in the overview twice, like on the picture above.
  4. Install the resources on the filesystem

    Note. This is not really required, you can add the headers to your download-folder, I found it clean to move them to /usr/local

    To quote StackOverflow (man I love that forum):
    The lib/ files go in /usr/local/lib The include/ files go in /usr/local/include The bin/ files go in /usr/local/bin

  5. Add the headers to XCode

    Next is adding the headers to XCode so it can find them. Open the ‘project settings’ by right-clicking on your base-project file and select ‘Get Info’.
    Get Info

  6. Add Header Search Paths

    Last step, go to ‘Build’, scroll down to the group ‘Search Paths’ and add ‘/usr/local/include’ to the ‘Header Search Paths’.
    Header Search Paths

  7. Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ error

    If you get this error message while running your code. The easiest solution to solve this is by changing ‘localhost’ to ‘127.0.0.1’ in your connecting code.

Sources:
http://zetcode.com/tutorials/mysqlcapitutorial/
http://stackoverflow.com/questions/1992592/c-api-with-mysql-in-xcode
http://stackoverflow.com/questions/4615442/how-to-install-mysql-connector-c-on-mac-os-x
http://stackoverflow.com/questions/749027/how-to-add-a-global-include-path-for-xcode
http://stackoverflow.com/questions/1297005/xcode-include-paths
http://drupal.org/node/184465

 


Only members are allowed to post a comment.

Comments

Geplaatst door studio33 op 06-Jul-11 02:07

I am getting error code tmp/mysql.sock when I try to connect to the local MySQL server.

Can you shed any light on that?

Geplaatst door studio33 op 06-Jul-11 02:07

My bad, didn’t read to the end.


sydney video production