Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Makefile not using include/library paths?

Well, after 3 hours of researching, I'm about to go insane, so I figure it's time to pass it off to some new eyes.

CXXFLAGS        = -g -Wall
OBJS            = main.o
PROG            = test
INCLUDES        = -I /usr/include/mysql -I /usr/local/include
LIBS            = -L /usr/lib/mysql -l libmysqlclient.so.15.0.0 -L /usr/local/lib -l libmysqlpp.so.3.1.0

all:            $(PROG)

${PROG}:        $(OBJS)
            $(CXX) $(INCLUDES) -o $(PROG) $(OBJS) $(LIBS)

clean:;         $(RM) -f $(PROG) core *.o

There's something wrong with the include paths, because I get errors that mysql_version.h does not exist when it clearly does exist in /usr/include/mysql.

Checking the first part out of the ouput, it says

g++ -g -Wall   -c -o main.o main.cpp

which makes me think that I've formatted something in the Makefile wrong (due to the extra spaces and lack of include/library paths). However, I've looked at dozens of manuals and articles on Makefiles and the g++ options and... no progress.

I assume this should be a simple fix. Please, please help (do you sense my despair?).

On another note, do you think specifying the library specifically is necessary? I had this stuff running in XCode just fine, but I'm trying to migrate the code to my web server... the Makefile has stopped all progress, and I figure it's something I should learn from.

like image 653
Liandri Avatar asked Dec 17 '22 03:12

Liandri


1 Answers

In your makefile, you have added your include directives to the linking stage, not the compiling stage.

The lines

${PROG}:        $(OBJS)
            $(CXX) $(INCLUDES) -o $(PROG) $(OBJS) $(LIBS)

Say to make the program in ${PROG} from object files in ${OBJS} by calling the compiler in ${CXX} passing the include folders (along with your other arguments). Instead, for your variable section, do this:

INCLUDES        = -I /usr/include/mysql -I /usr/local/include
CXXFLAGS        = -g -Wall ${INCLUDES}
OBJS            = main.o
PROG            = test
LIBS            = -L /usr/lib/mysql -l libmysqlclient.so.15.0.0 -L /usr/local/lib -l libmysqlpp.so.3.1.0

This way your CXXFLAGS (which are used for the compile stage) should now pickup your include directives.

like image 168
MJD Avatar answered Jan 02 '23 19:01

MJD