C++ makefile with MySQL -
i trying build c++ code under linux. first attempt (otherwise, use windows). code using mysql c api library, have problem building it. got output while trying build mainprogram
g++ -lstdc++ -c mainprogram.cpp `mysql_config -–libs` -o2 -o mainprogram.obj `mysql_config –-cflags` g++ (gcc) 4.1.2 20080704 (red hat 4.1.2-54) copyright (c) 2006 free software foundation, inc. free software; see source copying conditions. there no warranty; not merchantability or fitness particular purpose.
and linking not done, because mainprogram.obj missing
my makefile this:
cc = g++ cflags = -lm -lstdc++ -wall -o2 mysqlcflags = `mysql_config –-cflags` mysqllibs = `mysql_config -–libs` bin = my_program obj = blockingsocket.obj ftpclient.obj ftpdatatypes.obj ftpfilestatus.obj ftplistparse.obj mystringansi.obj mainprogram.obj .phony: sestav .phony: clean #----------------------------------------- clean: rm -f *.obj #----------------------------------------- sestav: ${bin} #----------------------------------------- $(bin): $(obj) $(obj) $(cc) $(cflags) $^ -o $@ #----------------------------------------- blockingsocket.obj: ./ftpclient/blockingsocket.cpp $(cc) -c ./ftpclient/blockingsocket.cpp -o2 -o blockingsocket.obj #------- ftpclient.obj: ./ftpclient/ftpclient.cpp $(cc) -c ./ftpclient/ftpclient.cpp -o2 -o ftpclient.obj ftpdatatypes.obj: ./ftpclient/ftpdatatypes.cpp $(cc) -c ./ftpclient/ftpdatatypes.cpp -o2 -o ftpdatatypes.obj ftpfilestatus.obj: ./ftpclient/ftpfilestatus.cpp $(cc) -c ./ftpclient/ftpfilestatus.cpp -o2 -o ftpfilestatus.obj ftplistparse.obj: ./ftpclient/ftplistparse.cpp $(cc) -c ./ftpclient/ftplistparse.cpp -o2 -o ftplistparse.obj mystringansi.obj: mystringansi.cpp $(cc) -c mystringansi.cpp -o2 -o mystringansi.obj mainprogram.obj: mainprogram.cpp $(cc) -lstdc++ -c mainprogram.cpp $(mysqllibs) -o2 -o mainprogram.obj $(mysqlcflags)
complete output when building scratch:
g++ -c ./ftpclient/blockingsocket.cpp -o2 -o blockingsocket.obj g++ -c ./ftpclient/ftpclient.cpp -o2 -o ftpclient.obj g++ -c ./ftpclient/ftpdatatypes.cpp -o2 -o ftpdatatypes.obj g++ -c ./ftpclient/ftpfilestatus.cpp -o2 -o ftpfilestatus.obj ./ftpclient/ftpfilestatus.cpp:136:2: warning: no newline @ end of file g++ -c ./ftpclient/ftplistparse.cpp -o2 -o ftplistparse.obj g++ -c mystringansi.cpp -o2 -o mystringansi.obj in file included mystringansi.cpp:1: mystring.h:257:7: warning: no newline @ end of file in file included mystringansi.cpp:3: ./macros.h:22:7: warning: no newline @ end of file mystringansi.cpp:1350:2: warning: no newline @ end of file mystringansi.cpp: in member function â€void mystringansi::operator+=(char)’: mystringansi.cpp:1102: warning: null used in arithmetic g++ -lstdc++ -c mainprogram.cpp `mysql_config -–libs` -o2 -o mainprogram.obj `mysql_config –-cflags` g++ (gcc) 4.1.2 20080704 (red hat 4.1.2-54) copyright (c) 2006 free software foundation, inc. free software; see source copying conditions. there no warranty; not merchantability or fitness particular purpose. g++ -lm -lstdc++ -wall -o2 blockingsocket.obj ftpclient.obj ftpdatatypes.obj ftpfilestatus.obj ftplistparse.obj mystringansi.obj mainprogram.obj -o my_program g++: mainprogram.obj: no such file or directory make: *** [mainprogram] error 1
ok.. solved problem. first, joachim suggested in comment, removed librarries build object second, instead of using mysql_config --libs, put path manually
now makefile edited belows:
cflags = -lm -lstdc++ -wall -o2 -l/usr/lib/mysql/ -lmysqlclient $(cc) -c mainprogram.cpp -o2 -o mainprogram.obj -i/usr/include/mysql/