这篇文章演示了Makefile使用mysqlpp库和lua库的写法。
test.cpp:
#include <iostream> #include <stdint.h> #include <mysql++.h> extern "C"{ #include <lua.h> #include <lualib.h> #include <lauxlib.h> }; int main() { mysqlpp::Connection link_gm(false); if(!link_gm.connect("gm", "127.0.0.1", "root", "123456", 3306)) { std::cout << "connect failed!" << std::endl; } lua_State* L = luaL_newstate(); luaL_openlibs(L); luaL_dofile(L, "test.lua"); lua_close(L); std::cout << "hello world" << std::endl; link_gm.disconnect(); }
test.lua:
print("hello world, lua")
Makefile:
CC = gcc GXX = g++ CFLAGS = -g -Wall INCPATH = -I/usr/include/mysql++ -I/usr/include/mysql -I/usr/local/include LIBS += -L/usr/lib -L/usr/local/lib -L/usr/lib64 -lmysqlpp -llua -ldl -lpthread TARGET = test.exe OBJS = test.o .PHONY : all clean all : clean $(TARGET) $(TARGET) : $(OBJS) $(GXX) -o $@ $(OBJS) $(LIBS) %.o : %.cpp $(GXX) $(CFLAGS) $(INCPATH) -o $@ -c $< clean : rm -f $(OBJS) $(TARGET)