简体   繁体   English

Makefile包括erro

[英]Makefile include erro

I am new to makefile I have this error while compiling. 我是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

output: 输出:

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

You need to add the -I/usr/include/mysql on each compiler invocation that will compile source code that contains #include <mysql.h> or equivalent. 您需要在每个编译器调用上添加-I/usr/include/mysql ,该调用将编译包含#include <mysql.h>或等效的源代码。

You're missing that on the line that compiles main.c . 你在编译main.c那行上错过了。

Tip 1: move the -I (include search paths) to before the source code files you're compiling, and the -L (library search paths) and -l (libraries) parts to after the code files. 提示1:移动-I (包含搜索路径) 之前的源代码文件,你正在编译,以及-L (库搜索路径)和-l (库)部分的代码文件之后 -I is for the preprocessor, that runs first . -I用于首先运行的预处理器。 -L and -l are for the linker, that runs last . -L-l用于最后运行的链接器。

Tip 2: do not use -lpthread unless you know exactly what you're doing. 提示2:除非您确切知道自己在做什么,否则不要使用-lpthread Use -pthread instead. 请改用-pthread And if you need it for one compile, your most likely need it for all the compiles in the same project. 如果你需要一个编译,你最有可能需要它用于同一个项目中的所有编译。 (And put that in front of everything, that affects the complete compilation, pre-processor and linker.) (并将其放在所有内容之前,这会影响完整的编译,预处理器和链接器。)

Try s.th. 试试s.th. like this (eventually replace main with main.exe this depends on your target OS environment): 像这样(最终用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