开发者

makefile error ----> make: *** No rule to make target `mysql.h'

开发者 https://www.devze.com 2023-03-15 01:19 出处:网络
This might sound like a dumb question. But here goes..... I am using a C program called db_access.c which interacts with MySQL (in Ubuntu 10.10 with MySQL Server version: 5.1.49-1ubuntu8.1 (Ubuntu)).

This might sound like a dumb question. But here goes..... I am using a C program called db_access.c which interacts with MySQL (in Ubuntu 10.10 with MySQL Server version: 5.1.49-1ubuntu8.1 (Ubuntu)). Inside the program, I have: include "mysql.h" When I do the following, everything works out right:

gcc -I/usr/include/mysql db_access.c -lmysqlclient -o db_access
./db_access

Problem arises when I try to integrate it into an existing (and working makefile). The contents of the 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

I have two other C programs, MappingServer.c and route_aggregation.c. These 3 files need to be compiled together. By the way, I also did:

root@ahuq-kitchen:/home/ahuq/MappingServer# mysql_config --cflags
-I/usr/include/mysql  -DBIG_JOINS=1  -fno-strict-aliasing   -DUNIV_LINUX -DUNIV_LINUX

and

    root@ahuq-kitchen:/home/ahuq/MappingServer# mysql_config --libs
-Wl,-Bsymbolic-functions -rdynamic -L/usr/lib/mysql -lmysqlclient

So I think the paths are OK. When I do: make all I get:

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: functio开发者_运维问答n returns address of local variable
make: *** No rule to make target `mysql.h', needed by `db_access.o'.  Stop.

Why is this happening?


the line

db_access.o: db_access.c map_registration.h mysql.h

tells make that db_access.o depends on db_access.c, map_registration.h and mysql.h. make complains because mysql.h cannot be found in the current directory (it's in /usr/include/mysql).

see the question Makefile updated library dependency for how to specify libraries as dependencies in make


You put "mysql.h" as a dependency, but it's not in the current directory, so Make thinks it needs to build it, but doesn't know how.


try to remove all the lines like:

MappingServer.o: MappingServer.c map_registration.h 

if the map_registration.h is included in the c file, make is smart enough to find it. The only thing to be noticed may be to set the search file path using: -I.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号