gpt4 book ai didi

mysql - C 和 Mysql 中的链接错误

转载 作者:行者123 更新时间:2023-11-29 14:49:16 25 4
gpt4 key购买 nike

嗨,我正在开发用 C 编写的 CGI,并尝试使用 Mysql。当我尝试使用它时,我收到了以 mysql_ 开头的符号的 undefined reference 错误,如下所示:

/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

我该怎么办?哪里出了问题?请帮帮我。我已经在互联网上搜索了一个星期,但仍然无法找到解决方案。我猜它在 ma​​kefile.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

这是我的cgi-src文件夹中的Makefile

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 $@ $<

all: $(TARGET)

$(TARGET): $(LIB_OBJS)
$(AR) -vsur $@ $^
@cp $(TARGET) $(OBJES)

clean:
-@rm -rf $(CLEAN_OBJS)

install:

最佳答案

试试这个

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

关于mysql - C 和 Mysql 中的链接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6150534/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com