Li:
you have to link in the mysql library mysqlclient.a in your makefile
Here is my makefile which you may use for reference
# This assumes the MySQL software is installed in /usr/local/mysql
inc := /cygdrive/g/mysql/mysql-debug-4.0.12-pc-linux-i686/include
lib := /cygdrive/g/mysql/mysql-debug-4.0.12-pc-linux-i686/lib
# If you have not installed the MySQL software yet, try this instead
#inc :=
/cygdrive/g/mysql/mysql-debug-4.0.12-pc-linux-i686/include:$(HOME)/mysql-4.0
/include
#lib := $(HOME)/mysql-4.0/libmysqld
CC := gcc
CPPFLAGS := -I$(inc) -D_THREAD_SAFE -D_REENTRANT
CFLAGS := -g -W -Wall
LDFLAGS := -static
# You can change -lmysqld to -lmysqlclient to use the
# client/server library
#LDLIBS = -L$(lib) -lmysqld -lz -lm -lcrypt
LDLIBS = libmysqlclient.a -lz -lm -lcrypt
ifneq (,$(shell grep FreeBSD /COPYRIGHT 2>/dev/null))
# FreeBSD
LDFLAGS += -pthread
else
# Assume Linux
LDLIBS += -lpthread
endif
# This works for simple one-file test programs
sources := $(wildcard *.c)
objects := $(patsubst %c,%o,$(sources))
targets := $(basename $(sources))
all: $(targets)
clean:
rm -f $(targets) $(objects) *.core
Keep us apprised,
Martin
----- Original Message -----
From: "Li Yang" <[EMAIL PROTECTED]>
To: "mysql" <[EMAIL PROTECTED]>
Sent: Thursday, April 03, 2003 7:32 PM
Subject: A question about using C API in mysql (linux platform)
Hi, I'm a newbie to MySQL
Now I am using C to connect mysql in Linux
The heaser souce code like:
#include <stdio.h>
#include <string.h>
#include <mysql.h>
and After I use "gcc test.c -L /usr/local/mysql/lib/ -shared " to compile
it , and when I run the a.out ,it always say that "Segmentation Fault "
and If I use "gcc test.c -L /usr/local/mysql/lib/ -static " to compile it
,It says that "undefined reference to 'mysql_init' "
How should I do ?
Thanks!
Best Regards
Li Yang
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]