'libmysqlclient'에 해당되는 글 1건

  1. 2011.04.09 Cocoa tutorial – linking and using libmysqlclient in your application

Cocoa tutorial – linking and using libmysqlclient in your application

Here’s a little tutorial on how to use libmysqlclient in a Cocoa application.

First of all you need to create a new Xcode project; suppose to create it in the directory: /path/to/your/project/.

Then you need to retrieve the libmysqlclient.aand libmysqlclient_r.afiles located in the /usr/local/mysql/lib/default directory. To do this you can, for example, start a new Terminal session and type the following commands:

cp/usr/local/mysql/lib/libmysqlclient.a /path/to/your/project/cp/usr/local/mysql/lib/libmysqlclient_r.a /path/to/your/project/

Now go to Xcode and select “Project” -> “Edit Project Settings” in the main menu. Now select the “Build” tab and make the following changes to all your configurations (Debug and Release):

  • “Architectures”: the same of your libmysqlclient architecture;
  • “Valid Architectures”: architectures compatibles with your libmysqlclient architecture(s);
  • “C/C++ Compiler Version”: GCC 4.2;
  • uncheck “Prebinding”;
  • turn on (if desired) the “Objective-C Grabage Collection”;
  • “C Language Dialect”: C99 [-std=c99];
  • check “Mismatched Return Type”;
  • check “Unused Variables”.

Note that not all of these flags are strictly required for the correct use of libmysqclient.aand libmysqlclient_r.a; you can test them and see what happens when you change some of them.

Now you need to import the libraries. To do so, right click on the group “Frameworks” located in the “Groups & Files” tree in Xcode and select “Add” -> “Existing Frameworks…”. Locate the libmysqlclient.afile and click the Add button. Repeat the operation with the libmysqlclient_r.afile.

Now you need to tell Xcode to copy the two libraries in the bundle directory. To do so, you must create a new copy build phase in your target and put the libraries in it:

  • Expand the “Targets” group in the “Groups & Files” tree;
  • right click on your application and select: “Add” -> “New Build Phase” -> “New Copy Files Build Phase”;
  • in the new window select “Frameworks” in the Destination popup menu;
  • close the window;
  • drag and drop the libmysqlclient.aand libmysqlclient_r.afiles from the Frameworks group to the new “Copy Files” group.

Now you need to copy all the MySQL C API headers in your project directory. To do so you can, for example, do something like this:


That’s all. To access any MySQL API function, you only need to import the mysql.hand unistd.h

Here’s a short example on how to use the API in a .m file:

... #include "mysql.h"#include "unistd.h"  @implementationAppController   ...   -(void)connect {MYSQL conn; mysql_init(amp;conn);   if(!mysql_real_connect(amp;conn, "", "", "", "", 0, NULL, 0))NSLog(@"%s", [NSStringstringWithUTF8String:mysql_error(amp;conn)]); elseNSLog(@"Connected"); }@end

Download the test project.

출처 : http://blog.naver.com/PostView.nhn?blogId=ups999&logNo=150097675553
Posted by 오늘마감

댓글을 달아 주세요