繁体   English   中英

Makefile包括erro

[英]Makefile include erro

我是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

您需要在每个编译器调用上添加-I/usr/include/mysql ,该调用将编译包含#include <mysql.h>或等效的源代码。

你在编译main.c那行上错过了。

提示1:移动-I (包含搜索路径) 之前的源代码文件,你正在编译,以及-L (库搜索路径)和-l (库)部分的代码文件之后 -I用于首先运行的预处理器。 -L-l用于最后运行的链接器。

提示2:除非您确切知道自己在做什么,否则不要使用-lpthread 请改用-pthread 如果你需要一个编译,你最有可能需要它用于同一个项目中的所有编译。 (并将其放在所有内容之前,这会影响完整的编译,预处理器和链接器。)

试试s.th. 像这样(最终用main.exe替换main取决于你的目标OS环境):

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 *.o

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM