求助:添加了两个文件后,这个makefile该怎么改?

发布于 2022-09-30 07:37:32 字数 6053 浏览 13 评论 0

原来写好的程序和makefile,都没问题。下面是原有的makefile内容(ftp_client.c http_client.c pop3_client.c smtp_client.c 是源文件,要生成同名的四个可执行文件:

COMPILER=gcc
CFLAGS= -Wall -g
INCLUDE=-I. -I/usr/include
LIBRARY=-L. -L/usr/lib

FTPClient_OBJ = ftp_client.o util.o
FTPClient_INCLUDE = Client.h

HTTPClient_OBJ = http_client.o util.o
HTTPClient_INCLUDE = Client.h

POP3Client_OBJ = pop_client.o util.o
POP3Client_INCLUDE = Client.h

SMTPClient_OBJ= smtp_client.o util.o
SMTPClient_INCLUDE = Client.h

all:ftp_client http_client pop_client smtp_client
%.o:%.c
        $(COMPILER) $(CFLAGS) $(INCLUDE) -c $*.c
        
ftp_client: $(FTPClient_OBJ) $(FTPClient_INCLUDE)
        $(COMPILER) $(CFLAGS) -o ftp_client $(FTPClient_OBJ) $(LIBRARY)

http_client: $(HTTPClient_OBJ) $(FTPClient_INCLUDE)
        $(COMPILER) $(CFLAGS) -o http_client $(HTTPClient_OBJ) $(LIBRARY)
        
pop_client: $(POP3Client_OBJ) $(POP3Client_INCLUDE)
        $(COMPILER) $(CFLAGS) -o pop_client $(POP3Client_OBJ) $(LIBRARY)

smtp_client: $(SMTPClient_OBJ) $(SMTPClient_INCLUDE)
        $(COMPILER) $(CFLAGS) -o smtp_client $(SMTPClient_OBJ) $(LIBRARY)

clean:
        rm -f ftp_client http_client pop_client smtp_client *.o

    现在我想将程序结果写入数据库(mysql), mysql装在/usr/local/ 下,为了使用mysql,我写了自己的新接口,这些接口在sql_mysql.c中定义,在sql_mysql.h中包含声明,sql_mysql.h中包含#include<mysql.h>。下面是改过的makefile:

COMPILER=gcc
CFLAGS= -Wall -g
MYSQL_HOME=/usr/local/mysql

INCLUDE=-I. -I/usr/include -I$(MYSQL_HOME)/include
LIBRARY=-L. -L/usr/lib -L$(MYSQL_HOME)/lib

FTPClient_OBJ = ftp_client.o util.o sql_mysql.o
FTPClient_INCLUDE = Client.h sql_mysql.h

HTTPClient_OBJ = http_client.o util.o sql_mysql.o
HTTPClient_INCLUDE = Client.h sql_mysql.h

POP3Client_OBJ = pop_client.o util.o sql_mysql.o
POP3Client_INCLUDE = Client.h sql_mysql.h

SMTPClient_OBJ= smtp_client.o util.o sql_mysql.o
SMTPClient_INCLUDE = Client.h sql_mysql.h

all:ftp_client http_client pop_client smtp_client
%.o:%.c
        $(COMPILER) $(CFLAGS) $(INCLUDE) -c $*.c

ftp_client: $(FTPClient_OBJ) $(FTPClient_INCLUDE)
        $(COMPILER) $(CFLAGS) -o ftp_client $(FTPClient_OBJ) $(LIBRARY)

http_client: $(HTTPClient_OBJ) $(FTPClient_INCLUDE)
        $(COMPILER) $(CFLAGS) -o http_client $(HTTPClient_OBJ) $(LIBRARY)

pop_client: $(POP3Client_OBJ) $(POP3Client_INCLUDE)
        $(COMPILER) $(CFLAGS) -o pop_client $(POP3Client_OBJ) $(LIBRARY)

smtp_client: $(SMTPClient_OBJ) $(SMTPClient_INCLUDE)
        $(COMPILER) $(CFLAGS) -o smtp_client $(SMTPClient_OBJ) $(LIBRARY)

clean:
        rm -f ftp_client http_client pop_client smtp_client *.o

出现错误如下(部分) :

gcc -Wall -g  -o ftp_client ftp_client.o util.o sql_mysql.o -L. -L/usr/lib -L/usr/local/mysql/lib
sql_mysql.o(.text+0x31): In function `sql_create_socket':
/home/wangyonggui/C_ver_bydavid/sql_mysql.c:61: undefined reference to `mysql_init'
sql_mysql.o(.text+0x52):/home/wangyonggui/C_ver_bydavid/sql_mysql.c:62: undefined reference to `mysql_real_connect'
sql_mysql.o(.text+0x91): In function `sql_connect':
/home/wangyonggui/C_ver_bydavid/sql_mysql.c:89: undefined reference to `conf_get_string'
sql_mysql.o(.text+0xc7):/home/wangyonggui/C_ver_bydavid/sql_mysql.c:95: undefined reference to `conf_get_string'
sql_mysql.o(.text+0xfd):/home/wangyonggui/C_ver_bydavid/sql_mysql.c:100: undefined reference to `conf_get_string'
sql_mysql.o(.text+0x133):/home/wangyonggui/C_ver_bydavid/sql_mysql.c:105: undefined reference to `conf_get_string'
sql_mysql.o(.text+0x1a1): In function `sql_query':
/home/wangyonggui/C_ver_bydavid/sql_mysql.c:131: undefined reference to `mysql_query'
sql_mysql.o(.text+0x1ee): In function `sql_select_query':
/home/wangyonggui/C_ver_bydavid/sql_mysql.c:160: undefined reference to `mysql_query'
sql_mysql.o(.text+0x25c): In function `sql_store_result':
/home/wangyonggui/C_ver_bydavid/sql_mysql.c:190: undefined reference to `mysql_store_result'
sql_mysql.o(.text+0x2b6): In function `sql_num_fields':
/home/wangyonggui/C_ver_bydavid/sql_mysql.c:220: undefined reference to `mysql_field_count'
sql_mysql.o(.text+0x2f6): In function `sql_num_rows':
/home/wangyonggui/C_ver_bydavid/sql_mysql.c:247: undefined reference to `mysql_num_rows'
sql_mysql.o(.text+0x330): In function `sql_fetch_row':
/home/wangyonggui/C_ver_bydavid/sql_mysql.c:268: undefined reference to `mysql_fetch_row'
sql_mysql.o(.text+0x361): In function `sql_free_result':
/home/wangyonggui/C_ver_bydavid/sql_mysql.c:287: undefined reference to `mysql_free_result'
sql_mysql.o(.text+0x38b): In function `sql_close':
/home/wangyonggui/C_ver_bydavid/sql_mysql.c:306: undefined reference to `mysql_close'
sql_mysql.o(.text+0x3e6): In function `sql_affected_rows':
/home/wangyonggui/C_ver_bydavid/sql_mysql.c:349: undefined reference to `mysql_affected_rows'
sql_mysql.o(.text+0x425): In function `sql_escape_string':
/home/wangyonggui/C_ver_bydavid/sql_mysql.c:374: undefined reference to `mysql_real_escape_string'
collect2: ld returned 1 exit status
make: *** [ftp_client] Error 1

请各位大虾该看看错出哪了?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

琉璃梦幻 2022-10-07 07:37:32

没连库吧?? -lmysqlclient

孤君无依 2022-10-07 07:37:32

9494, 多谢了

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文