这听起来像是一个愚蠢的问题。但是这里......我正在使用一个名为 db_access.c 的 C 程序,它与 MySQL 交互(在 Ubuntu 10.10 中,MySQL 服务器版本:5.1.49-1ubuntu8.1(Ubuntu))。在程序中,我有:include "mysql.h"
当我执行以下操作时,一切正常:
gcc -I/usr/include/mysql db_access.c -lmysqlclient -o db_access
./db_access
当我尝试将它集成到现有(和工作的 makefile)中时出现问题。生成文件的内容:
all: MappingServer
#Macro definitions
CC = gcc
CFLAGS = -lm
INCLUDES = -I/usr/include/mysql
LIBS = -L/usr/lib/mysql -lmysqlclient
MappingServer.o: MappingServer.c map_registration.h
$(CC) $(CFLAGS) -c MappingServer.c
route_aggregation.o: route_aggregation.c map_registration.h
$(CC) $(CFLAGS) -c route_aggregation.c
db_access.o: db_access.c map_registration.h mysql.h
$(CC) $(CFLAGS) $(INCLUDES) -c db_access.c
MappingServer: MappingServer.o route_aggregation.o db_access.o
$(CC) $(LIBS) -o MappingServer MappingServer.o route_aggregation.o db_access.o
clean:
-rm MappingServer.o route_aggregation.o db_access.o
我还有另外两个 C 程序,MappingServer.c 和 route_aggregation.c。这3个文件需要一起编译。顺便说一句,我也做了:
root@ahuq-kitchen:/home/ahuq/MappingServer# mysql_config --cflags
-I/usr/include/mysql -DBIG_JOINS=1 -fno-strict-aliasing -DUNIV_LINUX -DUNIV_LINUX
和
root@ahuq-kitchen:/home/ahuq/MappingServer# mysql_config --libs
-Wl,-Bsymbolic-functions -rdynamic -L/usr/lib/mysql -lmysqlclient
所以我认为路径没问题。当我这样做时:make all
我得到:
root@ahuq-kitchen:/home/ahuq/MappingServer# make all
gcc -lm -c MappingServer.c
gcc -lm -c route_aggregation.c
route_aggregation.c: In function ‘vtysh_input’:
route_aggregation.c:602: warning: function returns address of local variable
make: *** No rule to make target `mysql.h', needed by `db_access.o'. Stop.
为什么会这样?
最佳答案
线
db_access.o: db_access.c map_registration.h mysql.h
告诉 make db_access.o
依赖于 db_access.c
、map_registration.h
和 mysql.h
. make 提示因为在当前目录中找不到 mysql.h
(它在 /usr/include/mysql
)。
查看问题Makefile updated library dependency了解如何在 make 中将库指定为依赖项
关于mysql - makefile 错误 ----> make : *** No rule to make target `mysql.h' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6471845/