[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Howto write GNUmakefile.preamble with using C API
From: |
Nicola Pero |
Subject: |
RE: Howto write GNUmakefile.preamble with using C API |
Date: |
Tue, 22 Jul 2008 09:51:34 +0200 (CEST) |
Hi Jaroslav,
I had a quick look and tried myself on my machine.
First of all, you can compile the C file using gnustep-make. Use the following
GNUmakefile:
include $(GNUSTEP_MAKEFILES)/common.make
CTOOL_NAME = test
test_C_FILES = test.c
ADDITIONAL_CFLAGS += $(shell mysql_config --cflags)
ADDITIONAL_TOOL_LIBS += $(shell mysql_config --libs)
include $(GNUSTEP_MAKEFILES)/ctool.make
That works for me. You can check what is happening when you compile and link by
using 'make messages=yes'.
If you want to migrate it to Objective-C, then rename your test.c file to
test.m,
and slightly modify your GNUmakefile:
include $(GNUSTEP_MAKEFILES)/common.make
TOOL_NAME = test
test_OBJC_FILES = test.m
ADDITIONAL_OBJCFLAGS += $(shell mysql_config --cflags)
ADDITIONAL_TOOL_LIBS += $(shell mysql_config --libs)
include $(GNUSTEP_MAKEFILES)/tool.make
Again, I tried this and it works for me - it dumps the list of tables in the
database
to standard output when I compile it :-)
Not sure why you'd be getting a Segmentation Fault; maybe a typo when copying
the list
of headers/libs ? If you use mysql_config (via $(shell ...)) as in my examples
above,
you should avoid this problem :-)
Thanks
-----Original Message-----
From: "Jaroslav Joska" <jaroslav.joska@email.cz>
Sent: Monday, 21 July, 2008 21:10
To: "GNUstep" <discuss-gnustep@gnu.org>
Subject: Howto write GNUmakefile.preamble with using C API
Hi all!
When I waited for reply to my question about installing SQLClient,
I tried C program API to connect with MySQL. Tjis is C file test.c:
*#include* <mysql.h>
*#include* <stdio.h>
*main*() {
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
char *server = "localhost";
char *user = "root";
char *password = "PASSWORD"; //* set me first *//
char *database = "mysql";
conn = *mysql_init*(NULL);
//* Connect to database *//
*if* (!*mysql_real_connect*(conn, server,
user, password, database, 0, NULL, 0)) {
*fprintf*(stderr, "%s\n", *mysql_error*(conn));
*exit*(1);
}
//* send SQL query *//
*if* (*mysql_query*(conn, "show tables")) {
*fprintf*(stderr, "%s\n", *mysql_error*(conn));
*exit*(1);
}
res = *mysql_use_result*(conn);
//* output table name *//
*printf*("MySQL Tables in mysql database:\n");
*while* ((row = *mysql_fetch_row*(res)) != NULL)
*printf*("%s \n", row[0]);
//* close connection *//
*mysql_free_result*(res);
*mysql_close*(conn);
}
I successfully complied with this command:
# |*gcc -o test $(mysql_config --cflags) test.c *||*$(mysql_config --libs)*|
#./test
and it's fully working.
And this is my question. Can I compile this file (first rename to
test.m) with GNUstep make?
I changed GNUstep.preamble many times. I compiled test.m file without
error massage, but
for everytime I got "Segmentation fault :11" without core file.
Does anybody knows which variables in my GNUmakefile.preamble have I to
change?
ADDITIONAL_CPPFLAGS +=
ADDITIONAL_OBJCFLAGS +=
ADDITIONAL_TOOL_LIBS += -L/usr/local/lib/mysql -lmysqlclient -lz -lcrypt -lm
ADDITIONAL_CFLAGS += -I/usr/local/include/mysql -fno-strict-aliasing -pipe
ADDITIONAL_INCLUDE_DIRS += -I/usr/local/include/mysql
ADDITIONAL_LDFLAGS +=
ADDITIONAL_LIB_DIRS += -L/usr/local/lib/mysql
ADDITIONAL_INSTALL_DIRS +=
This is my MySQL configuration.
# mysql_config
Usage: /usr/local/bin/mysql_config [OPTIONS]
Options:
--cflags [-I/usr/local/include/mysql
-fno-strict-aliasing -pipe]
--include [-I/usr/local/include/mysql]
--libs [-L/usr/local/lib/mysql -lmysqlclient -lz
-lcrypt -lm]
--libs_r [-L/usr/local/lib/mysql -lmysqlclient_r -lz
-pthread -lcrypt -lm -pthread]
--socket [/tmp/mysql.sock]
--port [0]
--version [5.1.23-rc]
--libmysqld-libs [-L/usr/local/lib/mysql -lmysqld -lz -pthread
-lcrypt -lm -pthread -lwrap]
_______________________________________________
Discuss-gnustep mailing list
Discuss-gnustep@gnu.org
http://lists.gnu.org/mailman/listinfo/discuss-gnustep