I am new to makefile I have this error while compiling.
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.
You're missing that on the line that compiles 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. -I
is for the preprocessor, that runs first . -L
and -l
are for the linker, that runs last .
Tip 2: do not use -lpthread
unless you know exactly what you're doing. Use -pthread
instead. 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. like this (eventually replace main
with main.exe
this depends on your target OS environment):
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.