Jump to content

Compile with GCC48 / C++11 & Optimized Flags


Recommended Posts

Welcome to the second part of my guide series. This time I'll tell you how you can compile with gcc48 or even gcc49 like it's the case in vanilla and how you can use c++11 which will allow much more and faster instructions than the old one.

 

At first we need to have a look at our Makefile.

Make sure you edited the Line SVN_VERSION so you won't receive any errors. Try it e. g. to SVN_VERSION = mt2

 

Next, you'll have to declare what compiler you want to use.

Of course you first need to install the compiler, but I guess it's clear (if you haven't done so, just use cd /usr/ports/lang/gcc49 or even 48 and use make install clean).

The line normally say:

CC = g++

This is the standard compiler. You may want to change this line to:

CC = g++49

Or if you're using 48, change it to CC = g++48

 

Now before you compile it, you'd recompile all needed libs with gcc48/gcc49 too! So change the compiler in the makefile and recompile the sources in the following directories:

libgame/src

libpoly

libserverkey

libsql

libthecore/src

 

And then you need to recmopile cryptopp with the newer gcc version too! It's located in the Extern/cryptopp-directory.

 

Now you can compile your game and even your db source with the newer gcc version. You may experience a much smaller file size. The newer compilers will produce an even more faster and smaller gamefile than before.

Oh and if you want to carry out the lib-files you're using on your compiling machine (to make sure everything runs smoothly) you may use the following CFLAG:

 -Wl,-rpath,/usr/local/lib32/metin2

You can change the path to whatever you want! If you specify this, you instruct the linker to use this path so whenever you start your game/dbcache it'll first look in the given directory for the right libs and then, if it can't find the libs there, it'll look elsewhere.

 

 

Using c++11 is a must-have if you want to make new statements. The source code how to load the database without txt-files needs the newer c++ version, so you'll have to upgrade at least the dbcache for it. But you'll experience even more smaller file sizes with this change so it keeps up with more and more advantages.

 

First you may want to specify the new CFLAG. It's called:

 -std=c++11

This tells the compiler to use c++11. Keep in mind that not every compiler can use c++11! The newer gcc version can deal with it without any problems.

If you compile your source then, you may find a new error occuring!

Open every .cpp and .h-file in Notepad++ and do the following things (you can use the mass replacement of Notepad++):

replace typeof with __typeof

replace auto_ptr with unique_ptr

Watch out for the common-directory too!

Then you can recompile the source and it's done!

 

Oh and for this you don't need to compile every other sourcecode with c++11. You can e. g. only compile the dbcache with it.

 

 

Last small hint: You can play with the tuning flags to get even more optimization. -O2 can sometimes be good, but sometimes it's better to use others flags. You can even use -O3 or -Ofast. But be careful with this and consider using -fstrict-aliasing so the compiler won't optimize instructions that'd lead into a crash if it'd optimize them. And always: Pay attention to the warnings your compiler throws at you! They aren't there to just "hang out". They'd lead into crashes, so care about them.

 

Lastly I hope you enjoyed the guide. As in the last one, please tell me if it's good or not and if you have any questions: Feel free to ask.

  • Love 1
  • Love 33

We are the tortured.
We're not your friends.
As long as we're not visible.
We are unfixable.

Link to comment
Share on other sites

  • Bronze

 

Oo

I love it

 

My brings gcc48/49

 

You can provide more details on c++11 and CFLAG: -Wl,-rpath,/usr/local/lib32/metin2

 

 

Error


/lib/libstdc++.so.6: version GLIBCXX_3.4.11 required by /usr/Originale/Serveur/db/_db_r40146_32 not found

 

Build with the -static-libstdc++ CFLAG. It will produce a little bigger file size, but i don't think if it's really a problem.

 

Link to comment
Share on other sites

Also, do u have solutions for this warnings:

 

protocol.h: In function 'const char* encode_2bytes(sh_int)':
protocol.h:14:16: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  *((sh_int *) a) = ind;
                ^
 
config.cpp:493:22: warning: NULL used in arithmetic [-Wpointer-arith]
    if (NULL != line[0])
                      ^
 
In file included from item_manager_read_tables.cpp:19:0:
item_manager.h:268:70: warning: 'pkGroup' may be used uninitialized in this function [-Wmaybe-uninitialized]
   m_vec_items.push_back(SDropItemGroupInfo(dwItemVnum, dwPct, iCount));
                                                                      ^

 

Link to comment
Share on other sites

I don't really understand how cryptopp is compileable with g++49, 

 

Tqk5f.png

 

First i changed CXX = g++ to CSS = g++49, didn't work, than I changed all $(CXX) to g++49, also don't work, I don't see at the moment where the compiler in the Makefile from cryptopp is defined. :<

Edited by Metin2 Dev
Core X - External 2 Internal
Link to comment
Share on other sites

  • 5 weeks later...

install cryptopp from ports... is really better:

cd /usr/ports/security/cryptopp && make install clean

 

next you need to include in flags /usr/local/include/cryptopp.

 

take this opportunity to say if you use the boost from the ports is better... and avoiding the error "regex" if I'm not mistaken.

/usr/ports/devel/boost-libs/ && make install clean

 

again you need to add in flags: 

  • Inc: /usr/local/include/boost

-> https://wiki.freebsd.org/NewC%2B%2BStack kk

 

Sorry for my bad english.

Greetings!

  • Metin2 Dev 3
  • Dislove 1
  • Good 3
Link to comment
Share on other sites

  • 3 weeks later...
  • 2 months later...
  • Bronze

Nice tutorial, but I receive some errors:

config.cpp:570:3: error: 'unique_ptr' is not a member of 'std'
   std::unique_ptr<SQLMsg> pMsg(AccountDB::instance().DirectQuery(szQuery));
g++49: warning: '-mcpu=' is deprecated; use '-mtune=' or '-march=' instead

My Makefile:

PLATFORM = $(shell file /bin/ls | cut -d' ' -f3 | cut -d'-' -f1)

GCC_VERSION = $(shell $(CC) --version 2>&1 | grep "(GCC)" | cut -d' ' -f3  | cut -d'.' -f1)
BSD_VERSION = $(shell uname -v 2>&1 | cut -d' ' -f2 | cut -d'.' -f1)
#P4_VERSION = $(shell svnversion -n .)
P4_VERSION = 000
PUB_VERSION = dev

CC = g++49

INCDIR =
LIBDIR =
BINDIR = ..
OBJDIR = OBJDIR
$(shell if [ ! -d $(OBJDIR) ]; then mkdir $(OBJDIR); fi)

# Standard Setting
LIBS = -pthread -lm -lmd
# Removed -fno-rtti 
CFLAGS = -g -Wall -O2 -m32 -pipe -fexceptions -D_THREAD_SAFE -DNDEBUG # -D_USE_SERVER_KEY_ -Wl,-rpath,/usr/home/dev/share/libs -std=c++11

ifeq ($(GCC_VERSION), 4)
CFLAGS += -mtune=i686 -fstack-protector-all
else
CFLAGS += -mcpu=i686
endif

# boost
INCDIR += -I../../../Extern/include/boost

# DevIL
INCDIR += -I../../libdevil
LIBDIR += -L../../libdevil
LIBS += -lIL -lpng -ltiff -lmng -llcms -ljpeg

# MySQL
#ifeq ($(BSD_VERSION), 7)
INCDIR += -I../../libmysql/7.x-5.1.35
LIBDIR += -L../../libmysql/7.x-5.1.35
#else
#INCDIR += -I../../libmysql/5.x-5.1.35
#LIBDIR += -L../../libmysql/5.x-5.1.35
#endif

LIBS += -lmysqlclient -L/usr/local/lib/mysql -lz

# Miscellaneous external libraries
INCDIR += -I../../../Extern/include
LIBDIR += -L../../../Extern/lib
LIBS += -lcryptopp -lgtest

# HackShield
INCDIR += -I../../libhackshield/include
LIBDIR += -L../../libhackshield/lib
LIBS += -lanticpxsvr

# XTrap
INCDIR += -I../../libxtrap/include

# openssl
#INCDIR += -I/usr/include
#LIBS += -lssl
#LIBS += /usr/lib/libssl.a

# Project Library
INCDIR += -I../../liblua/include
INCDIR += -I/usr/local/include
INCDIR += -L/usr/local/lib/mysql
INCDIR += -I../../libserverkey
LIBDIR += -L../../libthecore/lib -L../../libpoly -L../../libsql -L../../libgame/lib -L../../liblua/lib -L../../libserverkey
LIBDIR += -L/usr/local/lib
LIBS += -lthecore -lpoly -llua -llualib -lsql -lgame -lserverkey
USE_STACKTRACE = 0
ifeq ($(USE_STACKTRACE), 1)
LIBS += /usr/local/lib/libexecinfo.a
endif

TARGET  = $(BINDIR)/game_r$(P4_VERSION)_$(PUB_VERSION)

CFILE	= minilzo.c

CPPFILE = BattleArena.cpp FSM.cpp MarkConvert.cpp MarkImage.cpp MarkManager.cpp OXEvent.cpp TrafficProfiler.cpp ani.cpp
		  arena.cpp banword.cpp battle.cpp blend_item.cpp block_country.cpp buffer_manager.cpp building.cpp castle.cpp
		  char.cpp char_affect.cpp char_battle.cpp char_change_empire.cpp char_horse.cpp char_item.cpp char_manager.cpp
		  char_quickslot.cpp char_resist.cpp char_skill.cpp char_state.cpp PetSystem.cpp cmd.cpp cmd_emotion.cpp cmd_general.cpp
		  cmd_gm.cpp cmd_oxevent.cpp config.cpp constants.cpp crc32.cpp cube.cpp db.cpp desc.cpp
		  desc_client.cpp desc_manager.cpp desc_p2p.cpp dev_log.cpp dungeon.cpp empire_text_convert.cpp entity.cpp
		  entity_view.cpp event.cpp event_queue.cpp exchange.cpp file_loader.cpp fishing.cpp gm.cpp guild.cpp
		  guild_manager.cpp guild_war.cpp horse_rider.cpp horsename_manager.cpp input.cpp input_auth.cpp input_db.cpp
		  input_login.cpp input_main.cpp input_p2p.cpp input_teen.cpp input_udp.cpp ip_ban.cpp
		  item.cpp item_addon.cpp item_attribute.cpp item_manager.cpp item_manager_idrange.cpp locale.cpp
		  locale_service.cpp log.cpp login_data.cpp lzo_manager.cpp marriage.cpp matrix_card.cpp
		  messenger_manager.cpp mining.cpp mob_manager.cpp monarch.cpp motion.cpp over9refine.cpp p2p.cpp packet_info.cpp
		  party.cpp passpod.cpp pcbang.cpp polymorph.cpp priv_manager.cpp pvp.cpp
		  questevent.cpp questlua.cpp questlua_affect.cpp questlua_arena.cpp questlua_ba.cpp questlua_building.cpp
		  questlua_danceevent.cpp questlua_dungeon.cpp questlua_forked.cpp questlua_game.cpp questlua_global.cpp
		  questlua_guild.cpp questlua_horse.cpp questlua_pet.cpp questlua_item.cpp questlua_marriage.cpp questlua_mgmt.cpp
		  questlua_monarch.cpp questlua_npc.cpp questlua_oxevent.cpp questlua_party.cpp questlua_pc.cpp
		  questlua_quest.cpp questlua_target.cpp questmanager.cpp questnpc.cpp questpc.cpp
		  refine.cpp regen.cpp safebox.cpp sectree.cpp sectree_manager.cpp sequence.cpp shop.cpp
		  skill.cpp start_position.cpp target.cpp text_file_loader.cpp trigger.cpp utils.cpp vector.cpp war_map.cpp
		  wedding.cpp xmas_event.cpp version.cpp panama.cpp threeway_war.cpp map_location.cpp auth_brazil.cpp
		  BlueDragon.cpp BlueDragon_Binder.cpp DragonLair.cpp questlua_dragonlair.cpp
		  HackShield.cpp HackShield_Impl.cpp char_hackshield.cpp skill_power.cpp affect.cpp
		  SpeedServer.cpp questlua_speedserver.cpp XTrapManager.cpp
		  auction_manager.cpp FileMonitor_FreeBSD.cpp ClientPackageCryptInfo.cpp cipher.cpp
		  buff_on_attributes.cpp check_server.cpp dragon_soul_table.cpp DragonSoul.cpp
		  group_text_parse_tree.cpp char_dragonsoul.cpp questlua_dragonsoul.cpp
		  shop_manager.cpp shopEx.cpp item_manager_read_tables.cpp


COBJS	= $(CFILE:%.c=$(OBJDIR)/%.o)
CPPOBJS	= $(CPPFILE:%.cpp=$(OBJDIR)/%.o)

MAINOBJ = $(OBJDIR)/main.o
MAINCPP = main.cpp

TESTOBJ = $(OBJDIR)/test.o
TESTCPP = test.cpp
TEST_TARGET = $(BINDIR)/test

default: $(TARGET) $(TEST_TARGET)

$(OBJDIR)/minilzo.o: minilzo.c
	@$(CC) $(CFLAGS) $(INCDIR) -c $< -o $@
	@echo compile $<

$(OBJDIR)/version.o: version.cpp
	#@$(CC) $(CFLAGS) -D__USER__="$(USER)" -D__HOSTNAME__="$(HOSTNAME)" -D__PWD__="$(PWD)" -D__P4_VERSION__="$(P4_VERSION)" -c $< -o $@
	@$(CC) $(CFLAGS) -D__P4_VERSION__="$(SVN_VERSION)" -c $< -o $@
	@echo compile $<

$(OBJDIR)/%.o: %.cpp
	@echo compile $<
	@$(CC) $(CFLAGS) $(INCDIR) -c $< -o $@

limit_time:
	@echo update limit time
	@python update_limit_time.py

$(TARGET): $(CPPOBJS) $(COBJS) $(MAINOBJ)
	@echo linking $(TARGET)....
	@$(CC) $(CFLAGS) $(LIBDIR) $(COBJS) $(CPPOBJS) $(MAINOBJ) $(LIBS) -o $(TARGET)

$(TEST_TARGET): $(TESTCPP) $(CPPOBJS) $(COBJS) $(TESTOBJ)
	@echo linking $(TEST_TARGET)
	@$(CC) $(CFLAGS) $(LIBDIR) $(COBJS) $(CPPOBJS) $(TESTOBJ) $(LIBS) -o ../test

clean:
	@rm -f $(COBJS) $(CPPOBJS)
	@rm -f $(BINDIR)/game_r* $(BINDIR)/conv

tag:
	ctags *.cpp *.h *.c

dep:
	makedepend -f Depend $(INCDIR) -I/usr/include/c++/3.3 -I/usr/include/c++/4.2 -p$(OBJDIR)/ $(CPPFILE) $(CFILE) $(MAINCPP) $(TESTCPP) 2> /dev/null > Depend

sinclude Depend

Somebody can help me?

 

Regards

Link to comment
Share on other sites

  • 5 months later...

 

Vanilla Quote

.

 

At first we need to have a look at our Makefile.

Make sure you edited the Line SVN_VERSION so you won't receive any errors. Try it e. g. to SVN_VERSION = mt2

Where are the Makefile?

Here? --> /usr/ports/lang/gcc49

In this makefile... I dont see the Line "SVN_VERSION"

 

=)))))))))))))))))))))))))))))))))))))))))))))

  • Love 1
Link to comment
Share on other sites

 

 

Vanilla Quote

.

 

At first we need to have a look at our Makefile.

Make sure you edited the Line SVN_VERSION so you won't receive any errors. Try it e. g. to SVN_VERSION = mt2

Where are the Makefile?

Here? --> /usr/ports/lang/gcc49

In this makefile... I dont see the Line "SVN_VERSION"

 

=)))))))))))))))))))))))))))))))))))))))))))))

 

 

 

Sorry.. I am a SUPER Noob xD

I dont see the line SVN_VERSION ..

Link to comment
Share on other sites

compile BattleArena.cpp
In file included from sectree_manager.h:4:0,
                 from BattleArena.cpp:7:
sectree.h:142:4: warnieng: identifier 'decltype' is a keyword in C++11 [-Wc++0x-compat]
    itertype(m_set_entity) it = m_set_entity.begin();
    ^
In file included from ../../../../extern/include/boost/tuple/tuple.hpp:33:0,
                 from ../../../../extern/include/boost/unordered/detail/allocate.hpp:27,
                 from ../../../../extern/include/boost/unordered/detail/buckets.hpp:15,
                 from ../../../../extern/include/boost/unordered/detail/table.hpp:10,
                 from ../../../../extern/include/boost/unordered/detail/equivalent.hpp:14,
                 from ../../../../extern/include/boost/unordered/unordered_map.hpp:17,
                 from ../../../../extern/include/boost/unordered_map.hpp:16,
                 from char.h:4,
                 from BattleArena.cpp:6:
../../../../extern/include/boost/tuple/detail/tuple_basic.hpp: In function 'typename boost::tuples::access_traits<typename boost::tuples::element<N, boost::tuples::cons<HT, TT> >::type>::const_type boost::tuples::get(const boost::tuples::cons<HT, TT>&)':
../../../../extern/include/boost/tuple/detail/tuple_basic.hpp:228:45: warning: typedef 'cons_element' locally defined but not used [-Wunused-local-typedefs]
   typedef BOOST_DEDUCED_TYPENAME impl::type cons_element;
                                             ^
In file included from stdafx.h:37:0,
                 from BattleArena.cpp:1:
sectree.h: In member function 'bool SECTREE::for_each_entity_for_find_victim(_Func&)':
typedef.h:105:41: error: there are no arguments to 'decltype' that depend on a template parameter, so a declaration of 'decltype' must be available [-fpermissive]
 #define itertype(v) decltype((v).begin())
                                         ^
sectree.h:142:4: note: in expansion of macro 'itertype'
    itertype(m_set_entity) it = m_set_entity.begin();
    ^
typedef.h:105:41: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
 #define itertype(v) decltype((v).begin())
                                         ^
sectree.h:142:4: note: in expansion of macro 'itertype'
    itertype(m_set_entity) it = m_set_entity.begin();
    ^
In file included from sectree_manager.h:4:0,
                 from BattleArena.cpp:7:
sectree.h:142:27: error: expected ';' before 'it'
    itertype(m_set_entity) it = m_set_entity.begin();
                           ^
sectree.h:144:11: error: 'it' was not declared in this scope
    while (it != m_set_entity.end())
           ^
In file included from stdafx.h:37:0,
                 from BattleArena.cpp:1:
sectree.h: In member function 'void SECTREE::for_each_entity(_Func&)':
typedef.h:105:41: error: there are no arguments to 'decltype' that depend on a template parameter, so a declaration of 'decltype' must be available [-fpermissive]
 #define itertype(v) decltype((v).begin())
                                         ^
sectree.h:189:4: note: in expansion of macro 'itertype'
    itertype(m_set_entity) it = m_set_entity.begin();
    ^
In file included from sectree_manager.h:4:0,
                 from BattleArena.cpp:7:
sectree.h:189:27: error: expected ';' before 'it'
    itertype(m_set_entity) it = m_set_entity.begin();
                           ^
sectree.h:190:12: error: 'it' was not declared in this scope
    for ( ; it != m_set_entity.end(); ++it) {
            ^
In file included from stdafx.h:37:0,
                 from BattleArena.cpp:1:
sectree.h: In instantiation of 'void SECTREE::for_each_entity(_Func&) [with _Func = FCollectEntity]':
sectree_manager.h:79:39:   required from 'void SECTREE_MAP::for_each(Func&) [with Func = FWarpToHome]'
BattleArena.cpp:180:28:   required from here
typedef.h:105:41: error: 'decltype' was not declared in this scope
 #define itertype(v) decltype((v).begin())
                                         ^
sectree.h:189:4: note: in expansion of macro 'itertype'
    itertype(m_set_entity) it = m_set_entity.begin();
    ^
Makefile:121: recipe for target 'OBJDIR/BattleArena.o' failed
gmake: *** [OBJDIR/BattleArena.o] Error 1 

my error

Link to comment
Share on other sites

compile BattleArena.cpp
In file included from sectree_manager.h:4:0,
                 from BattleArena.cpp:7:
sectree.h:142:4: warnieng: identifier 'decltype' is a keyword in C++11 [-Wc++0x-compat]
    itertype(m_set_entity) it = m_set_entity.begin();
    ^
In file included from ../../../../extern/include/boost/tuple/tuple.hpp:33:0,
                 from ../../../../extern/include/boost/unordered/detail/allocate.hpp:27,
                 from ../../../../extern/include/boost/unordered/detail/buckets.hpp:15,
                 from ../../../../extern/include/boost/unordered/detail/table.hpp:10,
                 from ../../../../extern/include/boost/unordered/detail/equivalent.hpp:14,
                 from ../../../../extern/include/boost/unordered/unordered_map.hpp:17,
                 from ../../../../extern/include/boost/unordered_map.hpp:16,
                 from char.h:4,
                 from BattleArena.cpp:6:
../../../../extern/include/boost/tuple/detail/tuple_basic.hpp: In function 'typename boost::tuples::access_traits<typename boost::tuples::element<N, boost::tuples::cons<HT, TT> >::type>::const_type boost::tuples::get(const boost::tuples::cons<HT, TT>&)':
../../../../extern/include/boost/tuple/detail/tuple_basic.hpp:228:45: warning: typedef 'cons_element' locally defined but not used [-Wunused-local-typedefs]
   typedef BOOST_DEDUCED_TYPENAME impl::type cons_element;
                                             ^
In file included from stdafx.h:37:0,
                 from BattleArena.cpp:1:
sectree.h: In member function 'bool SECTREE::for_each_entity_for_find_victim(_Func&)':
typedef.h:105:41: error: there are no arguments to 'decltype' that depend on a template parameter, so a declaration of 'decltype' must be available [-fpermissive]
 #define itertype(v) decltype((v).begin())
                                         ^
sectree.h:142:4: note: in expansion of macro 'itertype'
    itertype(m_set_entity) it = m_set_entity.begin();
    ^
typedef.h:105:41: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
 #define itertype(v) decltype((v).begin())
                                         ^
sectree.h:142:4: note: in expansion of macro 'itertype'
    itertype(m_set_entity) it = m_set_entity.begin();
    ^
In file included from sectree_manager.h:4:0,
                 from BattleArena.cpp:7:
sectree.h:142:27: error: expected ';' before 'it'
    itertype(m_set_entity) it = m_set_entity.begin();
                           ^
sectree.h:144:11: error: 'it' was not declared in this scope
    while (it != m_set_entity.end())
           ^
In file included from stdafx.h:37:0,
                 from BattleArena.cpp:1:
sectree.h: In member function 'void SECTREE::for_each_entity(_Func&)':
typedef.h:105:41: error: there are no arguments to 'decltype' that depend on a template parameter, so a declaration of 'decltype' must be available [-fpermissive]
 #define itertype(v) decltype((v).begin())
                                         ^
sectree.h:189:4: note: in expansion of macro 'itertype'
    itertype(m_set_entity) it = m_set_entity.begin();
    ^
In file included from sectree_manager.h:4:0,
                 from BattleArena.cpp:7:
sectree.h:189:27: error: expected ';' before 'it'
    itertype(m_set_entity) it = m_set_entity.begin();
                           ^
sectree.h:190:12: error: 'it' was not declared in this scope
    for ( ; it != m_set_entity.end(); ++it) {
            ^
In file included from stdafx.h:37:0,
                 from BattleArena.cpp:1:
sectree.h: In instantiation of 'void SECTREE::for_each_entity(_Func&) [with _Func = FCollectEntity]':
sectree_manager.h:79:39:   required from 'void SECTREE_MAP::for_each(Func&) [with Func = FWarpToHome]'
BattleArena.cpp:180:28:   required from here
typedef.h:105:41: error: 'decltype' was not declared in this scope
 #define itertype(v) decltype((v).begin())
                                         ^
sectree.h:189:4: note: in expansion of macro 'itertype'
    itertype(m_set_entity) it = m_set_entity.begin();
    ^
Makefile:121: recipe for target 'OBJDIR/BattleArena.o' failed
gmake: *** [OBJDIR/BattleArena.o] Error 1 

my error

 

 

Me too, some help?

Link to comment
Share on other sites

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.