From 4fa1e91e9598ffd4e63829b785102efa778b93a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Sun, 20 Dec 2015 16:22:14 +0000 Subject: [PATCH] Allow compiling with clang Added C++ headers file in cpp.h bug fix in xchg_32 : gcc ignores it, clang doesn't Replaced -rdynamic with --export-dynamic Removed the override of env variables CC , CXX , CFLAGS , CPPFLAGS and LIBS Fixed definition in MySQL_Monitor.cpp : gcc ignores it, clang doesn't Added a compile example text file --- compile_examples.txt | 8 ++++++++ include/cpp.h | 15 +++++++++++++++ include/proxysql_atomic.h | 2 +- lib/Makefile | 19 +++++++++++-------- lib/MySQL_Monitor.cpp | 6 +++--- src/Makefile | 12 +++++++----- 6 files changed, 45 insertions(+), 17 deletions(-) create mode 100644 compile_examples.txt diff --git a/compile_examples.txt b/compile_examples.txt new file mode 100644 index 000000000..fd3c31d42 --- /dev/null +++ b/compile_examples.txt @@ -0,0 +1,8 @@ +## On Linux +## compile using gcc 4.8 +time CXX=g++-4.8 CC=gcc-4.8 make -j 5 build_deps + +## On Linux +## compile using clang 3.6 and stdc++4.8 +CXX=clang++-3.6 CC=clang-3.6 CPPFLAGS="-I/usr/include/c++/4.8/ -I/usr/include/x86_64-linux-gnu/c++/4.8" LDFLAGS="-L/usr/lib/x86_64-linux-gnu/ -L/usr/lib/gcc/x86_64-linux-gnu/4.8" make -j 5 build_deps +CXX=clang++-3.6 CC=clang-3.6 CPPFLAGS="-I/usr/include/c++/4.8/ -I/usr/include/x86_64-linux-gnu/c++/4.8" LDFLAGS="-L/usr/lib/x86_64-linux-gnu/ -L/usr/lib/gcc/x86_64-linux-gnu/4.8" make -j 5 diff --git a/include/cpp.h b/include/cpp.h index 90cc74305..85f997fb9 100644 --- a/include/cpp.h +++ b/include/cpp.h @@ -18,4 +18,19 @@ #include "proxysql_admin.h" #include "MySQL_HostGroups_Manager.h" #include "MySQL_Logger.hpp" +#undef swap +#undef min +#undef max +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include //#endif /* __cplusplus */ diff --git a/include/proxysql_atomic.h b/include/proxysql_atomic.h index a2cdaee8a..7d244c0d2 100644 --- a/include/proxysql_atomic.h +++ b/include/proxysql_atomic.h @@ -22,7 +22,7 @@ struct _rwlock_t { static inline unsigned xchg_32(void *ptr, unsigned x) { __asm__ __volatile__("xchgl %0,%1" - :"=r" ((unsigned) x) + :"=r" (x) :"m" (*(volatile unsigned *)ptr), "0" (x) :"memory"); return x; diff --git a/lib/Makefile b/lib/Makefile index c3314c8cf..4ad98da85 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -32,16 +32,19 @@ IDIRS=-I$(IDIR) -I$(JEMALLOC_IDIR) -I$(MARIADB_IDIR) $(LIBCONFIG_IDIR) -I$(RE2_I LDIRS=-L$(JEMALLOC_PATH)/lib -L$(RE2_PATH)/obj -L$(INJECTION_PATH) -LIBS=-rdynamic -Wl,-Bstatic -ljemalloc_pic -lre2 -Wl,-Bdynamic -ldl -lpthread -lm -lz -lrt $(EXTRALINK) +#LIBS=-rdynamic -Wl,-Bstatic -ljemalloc_pic -lre2 -Wl,-Bdynamic -ldl -lpthread -lm -lz -lrt $(EXTRALINK) +#LIBS=-Wl,--export-dynamic -Wl,-Bstatic -ljemalloc_pic -lre2 -Wl,-Bdynamic -ldl -lpthread -lm -lz -lrt $(EXTRALINK) ODIR= obj -CC=gcc -CPP=g++ +#CC=gcc +#CPP=g++ #CC=clang -CFLAGS=$(IDIRS) $(OPTZ) $(DEBUG) -Wall #-lcrypto -CPPFLAGS=-std=c++0x $(CFLAGS) $(LDIRS) $(LIBS) +#CFLAGS=$(IDIRS) $(OPTZ) $(DEBUG) -Wall #-lcrypto +#CPPFLAGS=-std=c++11 $(CFLAGS) $(LDIRS) $(LIBS) +MYCFLAGS=$(IDIRS) $(OPTZ) $(DEBUG) -Wall +MYCPPFLAGS=-std=c++11 $(MYCFLAGS) default: libproxysql.a .PHONY: default @@ -52,13 +55,13 @@ _OBJ_CPP = ProxySQL_GloVars.oo network.oo debug.oo configfile.oo Query_Cache.oo OBJ_CPP = $(patsubst %,$(ODIR)/%,$(_OBJ_CPP)) %.ko: %.cpp - $(CPP) -fPIC -c -o $@ $< $(CPPFLAGS) + $(CXX) -fPIC -c -o $@ $< $(MYCPPFLAGS) $(CPPFLAGS) $(ODIR)/%.o: %.c - $(CC) -fPIC -c -o $@ $< $(CFLAGS) + $(CC) -fPIC -c -o $@ $< $(MYCFLAGS) $(CFLAGS) $(ODIR)/%.oo: %.cpp - $(CPP) -fPIC -c -o $@ $< $(CPPFLAGS) + $(CXX) -fPIC -c -o $@ $< $(MYCPPFLAGS) $(CPPFLAGS) libproxysql.a: $(ODIR) $(OBJ) $(OBJ_CPP) $(INJECTION_PATH)/libinjection.a $(RE2_PATH)/obj/libre2.a $(LIBEVENT_PATH)/.libs/libevent.a $(PROTOBUF_IDIR)/.libs/libprotobuf.a ar rcs $@ $(OBJ) $(OBJ_CPP) $(INJECTION_PATH)/libinjection.a $(RE2_PATH)/obj/libre2.a $(LIBEVENT_PATH)/.libs/libevent.a $(PROTOBUF_IDIR)/.libs/libprotobuf.a diff --git a/lib/MySQL_Monitor.cpp b/lib/MySQL_Monitor.cpp index c6d1fd4f6..4198a32c6 100644 --- a/lib/MySQL_Monitor.cpp +++ b/lib/MySQL_Monitor.cpp @@ -62,7 +62,7 @@ static int total_read_only__num_active_connections=0; struct cmp_str { - bool operator()(char const *a, char const *b) + bool operator()(char const *a, char const *b) const { return strcmp(a, b) < 0; } @@ -88,7 +88,7 @@ MySQL_Monitor_Connection_Pool::~MySQL_Monitor_Connection_Pool() { } MYSQL * MySQL_Monitor_Connection_Pool::get_connection(char *hostname, int port) { - std::map* >::iterator it; + std::map* , cmp_str >::iterator it; //it = my_connections.find(std::make_pair(hostname,port)); char *buf=(char *)malloc(16+strlen(hostname)); sprintf(buf,"%s:%d",hostname,port); @@ -108,7 +108,7 @@ MYSQL * MySQL_Monitor_Connection_Pool::get_connection(char *hostname, int port) void MySQL_Monitor_Connection_Pool::put_connection(char *hostname, int port, MYSQL *my) { size++; - std::map* >::iterator it; + std::map* , cmp_str >::iterator it; char * buf=(char *)malloc(16+strlen(hostname)); sprintf(buf,"%s:%d",hostname,port); it = my_connections.find(buf); diff --git a/src/Makefile b/src/Makefile index b3ec80482..42b7d275f 100644 --- a/src/Makefile +++ b/src/Makefile @@ -54,8 +54,10 @@ LDIRS=-L$(LDIR) -L$(JEMALLOC_LDIR) $(LIBCONFIG_LDIR) -L$(RE2_PATH)/obj -L$(INJEC #LDIRS=-L$(LDIR) -L$(JEMALLOC_LDIR) -L$(MARIADB_LDIR) $(GLIB_LDIRS) $(LIBCONFIG_LDIR) -CFLAGS=-std=c++0x $(IDIRS) $(OPTZ) $(DEBUG) -LIBS=-rdynamic -Wl,-Bstatic -lconfig -lproxysql -ldaemon -ljemalloc -lconfig++ -lre2 -linjection -levent -lmariadbclient -lprotobuf -Wl,-Bdynamic -lpthread -lm -lz -lrt -ldl -lcrypto -lssl $(EXTRALINK) +MYCPPFLAGS=-std=c++11 $(IDIRS) $(OPTZ) $(DEBUG) +LDFLAGS+= +#LIBS=-rdynamic -Wl,-Bstatic -lconfig -lproxysql -ldaemon -ljemalloc -lconfig++ -lre2 -linjection -levent -lmariadbclient -lprotobuf -Wl,-Bdynamic -lpthread -lm -lz -lrt -ldl -lcrypto -lssl $(EXTRALINK) +MYLIBS=-Wl,--export-dynamic -Wl,-Bstatic -lconfig -lproxysql -ldaemon -ljemalloc -lconfig++ -lre2 -linjection -levent -lmariadbclient -lprotobuf -Wl,-Bdynamic -lpthread -lm -lz -lrt -ldl -lcrypto -lssl $(EXTRALINK) #LIBS=-rdynamic -Wl,-Bstatic -lproxysql -ljemalloc -levent $(GLIB_LIB) -Wl,-Bdynamic -ldl -lpthread -lm -lz -lrt LIBPROXYSQLAR=$(LDIR)/libproxysql.a @@ -63,7 +65,7 @@ LIBPROXYSQLAR=$(LDIR)/libproxysql.a ODIR= obj #CC=gcc -CC=g++ +#CC=g++ #CC=clang @@ -73,12 +75,12 @@ _OBJ = main.o proxysql_global.o OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ)) $(ODIR)/%.o: %.cpp - $(CXX) -c -o $@ $< $(CFLAGS) -Wall + $(CXX) -c -o $@ $< $(MYCPPFLAGS) $(CPPFLAGS) -Wall proxysql: $(ODIR) $(OBJ) $(LIBPROXYSQLAR) - $(CXX) -o $@ $(OBJ) $(LIBPROXYSQLAR) $(CFLAGS) $(LDIRS) $(LIBS) + $(CXX) -o $@ $(OBJ) $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS) $(ODIR): mkdir $(ODIR)