我是makefile的新手,我在编译时遇到了这个错误。
all: main
main.o:ssh-functions.o mysql_connector.o
g++ -c main.c ssh-functions.o mysql_connector.o -I libuv/include -L libuv/ -luv -lrt -lpthread
ssh-functions.o:ssh-functions.cpp
g++ -c ssh-functions.cpp -lssl -lcrypto
mysql_connector.o: mysql_connector.c
g++ -I/usr/include/mysql/ -c mysql_connector.c -L/usr/include/mysql/ -lmysqlclient
clean:
rm -rf *.o输出:
g++ -c ssh-functions.cpp -lssl -lcrypto
g++ -I/usr/include/mysql/ -c mysql_connector.c -L/usr/include/mysql/ -lmysqlclient
g++ -c main.c ssh-functions.o mysql_connector.o -I libuv/include -L libuv/ -luv -lrt -lpthread
In file included from main.c:4:0:
mysql_connector.c:4:19: fatal error: mysql.h: No such file or directory
compilation terminated.
make: *** [main.o] Error 1发布于 2013-02-24 04:26:36
您需要在将编译包含#include <mysql.h>或等效代码的源代码的每个编译器调用上添加-I/usr/include/mysql。
在编译main.c的代码行中,您遗漏了这一点。
提示1:将-I (包括搜索路径)移到您正在编译的源代码文件之前,将-L (库搜索路径)和-l (库)部分移到代码文件之后。-I用于最先运行的预处理器。-L和-l用于最后运行的链接器。
提示2:除非你非常清楚自己在做什么,否则不要使用-lpthread。请改用-pthread。
发布于 2013-02-24 04:55:46
试试s.th。就像这样(最终用main.exe替换main,这取决于您的目标操作系统环境):
MY_INCLPATHS=-I /usr/include/mysql -I libuv/include
MY_LIBPATHS=-L /usr/include/mysql -L libuv/
MY_LIBS=-lmysqlclient -lssl -lcrypto -luv -lrt -lpthread
all: main
main: main.o ssh-functions.o mysql_connector.o
g++ ${MY_LIBPATHS} main.o ssh-functions.o mysql_connector.o ${MY_LIBS} -o main
main.o: main.c
g++ ${MY_INCLPATHS} -c main.c
ssh-functions.o: ssh-functions.cpp
g++ ${MY_INCLPATHS} -c ssh-functions.cpp
mysql_connector.o: mysql_connector.c
g++ ${MY_INCLPATHS} -c mysql_connector.c
clean:
rm -rf main *.ohttps://stackoverflow.com/questions/15045195
复制相似问题