2011-05-27 63 views
0

您好我正在開發用C編寫並嘗試使用Mysql的CGI。 當我嘗試使用它,我得到了那些未定義引用錯誤在這裏表明,與mysql_開始的符號,如:在C和Mysql鏈接錯誤

/usr/bin/ld: Warning: type of symbol `password' changed from 2 to 1 in ../../lib /libcgi_module.a(users.o) 
../../lib/libcgi_module.a(users.o): In function `save': 
/home/jitcomm/intern_GUI/jit24_test_v2/cgi_src/cgi_module/users.c:18: multiple definition of `save' 
../../lib/libcgi_module.a(mode.o):/home/jitcomm/intern_GUI/jit24_test_v2/cgi_src/cgi_module/mode.c:56: first defined here 
../../lib/libcgi_module.a(users.o): In function `saveUser': 
users.c:(.text+0x192): undefined reference to `mysql_init' 
users.c:(.text+0x1e4): undefined reference to `mysql_real_connect' 
users.c:(.text+0x1f5): undefined reference to `mysql_error' 
users.c:(.text+0x267): undefined reference to `mysql_query' 
users.c:(.text+0x278): undefined reference to `mysql_error' 
users.c:(.text+0x2ab): undefined reference to `mysql_close' 

所以我寫了一些示例代碼,當我用我的節目,我可以很好地運行用此線

gcc -o saveUser $(mysql_config --cflags) saveUser.c $(mysql_config --libs) 

它運作良好。

下一步,我嘗試把我的編碼放在CGI中。 我仍然得到那些未定義的參考。 這是我的Makefile.basic

CC=/usr/bin/gcc 
#CC=powerpc-linux-gcc 
CP=/usr/bin/cp 
CFLAGS = -g -Wall $(mysql_config --cflags) $(mysql_config --libs) 

www=/var/www 
htdocs=/htdocs 
cgi_bin=/cgi-bin 
config=/etc/apache2/sites-available/default 

我該怎麼辦?哪裏出問題了?請幫幫我。我一直在網上搜索一週,但仍然無法獲得解決方案。我想這是在makefile.basic和鏈接到MySQL是錯誤的。

感謝

更新:

這裏是我的頂層Makefile文件

ROOT=. 
    CURDIR=$(shell /bin/pwd) 
    JITCOMM_INSTALL=$(ROOT)/install 

    include $(ROOT)/Makefile.basic 

    #set root directory 
    SUB_DIRS = cgi_src 
    SUB_DIRS += check_update 
    SUB_DIRS += loadconfig 
SUB_DIRS += keepalive 
SUB_DIRS += script 
SUB_DIRS += server 
SUB_DIRS += startproxy 
SUB_DIRS += net_stats 
#SUB_DIRS += ../sniffer_gui 
#SUB_DIRS += java 

all: 
ifneq ($(SUB_DIRS),) 
     @for i in $(SUB_DIRS) ; do if [ ! -d $(CURDIR)/$${i} ]; then continue; fi; \ 
     cd $(CURDIR)/$${i}; make || exit; cd $(CURDIR); done 
endif 

clean: 
     @rm -f $(ROOT)/lib/* 
     @rm -rf $(JITCOMM_INSTALL) 
ifneq ($(SUB_DIRS),) 
     @for i in $(SUB_DIRS) ; do if [ ! -d $(CURDIR)/$${i} ]; then continue; fi; \ 
     cd $(CURDIR)/$${i}; make clean || exit; cd $(CURDIR); done 
endif 


install: all 
     @rm -rf $(JITCOMM_INSTALL) 
     @mkdir $(JITCOMM_INSTALL) 
     @mkdir $(JITCOMM_INSTALL)/etc 
     @mkdir $(JITCOMM_INSTALL)/etc/acpro 
     @mkdir $(JITCOMM_INSTALL)/etc/syslog-ng 
     @mkdir $(JITCOMM_INSTALL)/etc/apache2 
     @mkdir $(JITCOMM_INSTALL)/etc/apache2/sites-available 
     @mkdir $(JITCOMM_INSTALL)/var 
     @mkdir $(JITCOMM_INSTALL)/var/www 
     @mkdir $(JITCOMM_INSTALL)/var/www/cgi-bin 

這是我Makefile文件的cgi-src文件夾

ROOT=../ 
CURDIR=$(shell /bin/pwd) 

include $(ROOT)/Makefile.basic 

#set root directory 
SUB_DIRS = util 
SUB_DIRS += cgi_util 
SUB_DIRS += cgi_module 

#Must be last 
SUB_DIRS += cgi_main 

all: 
ifneq ($(SUB_DIRS),) 
     @for i in $(SUB_DIRS) ; do if [ ! -d $(CURDIR)/$${i} ]; then continue; fi; \ 
     cd $(CURDIR)/$${i}; make || exit; cd $(CURDIR); done 
endif 

clean: 
ifneq ($(SUB_DIRS),) 
     @for i in $(SUB_DIRS) ; do if [ ! -d $(CURDIR)/$${i} ]; then continue; fi; \ 
     cd $(CURDIR)/$${i}; make clean || exit; cd $(CURDIR); done 
endif 


install: 

ifneq ($(SUB_DIRS),) 
     @for i in $(SUB_DIRS) ; do if [ ! -d $(CURDIR)/$${i} ]; then continue; fi; \ 
     cd $(CURDIR)/$${i}; make install || exit; cd $(CURDIR); done 
endif 

這裏是我的Makefile.basic

CC=/usr/bin/gcc 
#CC=powerpc-linux-gcc 
CP=/usr/bin/cp 
CFLAGS=-g -Wall $(shell mysql_config --cflags) $(shell mysql_config --libs) 

www=/var/www 
htdocs=/htdocs 
cgi_bin=/cgi-bin 
config=/etc/apache2/sites-available/default 


INSTALL_DIR=$(pwd)/.install 

最新:在cgi_module

的Makefile

#set common variant 
.SUFFIXES: .c .h .o 

ROOT=../../ 
include $(ROOT)/Makefile.basic 

#LINK_NAME = changepass.cgi login.cgi network.cgi reboot.cgi shutdown.cgi 
LINK_NAME = login.cgi 

INCS = -I../include 
INCS += -I../../cgi_src/util/include 
OBJES=../../lib/ 


TARGET = libcgi_module.a 
#don't change below 
LIB_OBJS = $(patsubst %.c, %.o, $(wildcard *.c)) 
CLEAN_OBJS = $(LIB_OBJS) $(TARGET) 

INST_OBJ = $(TARGET) 
%.o: %.c 
     $(CC) -c $(CFLAGS) $(INCS) -o [email protected] $< 

all: $(TARGET) 

$(TARGET): $(LIB_OBJS) 
     $(AR) -vsur [email protected] $^ 
     @cp $(TARGET) $(OBJES) 

clean: 
     [email protected] -rf $(CLEAN_OBJS) 

install: 
+0

你可以發佈位於cgi_module(與gcc調用)的makefile嗎? – 2011-05-31 07:52:15

+0

我發佈最新更新,謝謝! – kevin 2011-05-31 09:27:42

回答

1

試試這個

CC=/usr/bin/gcc 
#CC=powerpc-linux-gcc 
CP=/usr/bin/cp 
CFLAGS = -g -Wall $(shell mysql_config --cflags) $(shell mysql_config --libs) 


foo: 
    @echo "CFLAGS are $(CFLAGS)" 

並啓動make foo

+0

@cedric >>對不起,我遲到的回覆。我仍然有錯誤。無論如何要克服這個問題?非常感謝 !!! – kevin 2011-05-30 01:57:08

+0

@kevin:嘗試在生成文件顯示CFL​​AGS值 'FOO創建一個foo的目標: @echo 「CFLAGS是$(CFLAGS)」' 和發射'讓foo' – 2011-05-30 07:51:51

+0

@cedric >>什麼是富?對不起我的無知,我剛剛在2.5個月前開始使用C語言。你能詳細說明一下嗎?謝謝 !!! – kevin 2011-05-30 08:03:44