aslain.dev
0%
01 Hizmetler 02 Hakkımda 03 Projeler 04 Stack 05 Blog 06 İletişim
← Tüm makaleler Metin2

Metin2 Server Source Compiling on FreeBSD

Metin2 server source compiling is one of those tasks that confuses almost everyone the first time around: the fact that the source was originally written for FreeBSD looks like an advantage, but the moment you put C++ code written for an old compiler next to modern libraries, the errors snowball. In this guide I share the steps I follow to build the game and db sources cleanly on FreeBSD, along with real fixes for the errors you are most likely to hit.

Why FreeBSD?

The server side of Metin2 was designed from the start to run on FreeBSD. The source depends on FreeBSD's kqueue-based networking model and on specific system headers. Compiling on Linux is possible but requires patching, so if your goal is a stable production server, keeping the build environment identical to the runtime environment brings the fewest surprises. In practice most people pick a version in the FreeBSD 10–12 range: on very old releases the package repositories are no longer reachable, while on very new ones clang is the default compiler, which introduces extra incompatibilities.

Preparing the environment and dependencies

Before you start, the system needs the basic development tools and the libraries the source expects. On FreeBSD you install these with pkg:

pkg install gcc gmake scons
pkg install mysql57-client
pkg install cryptopp devil lzo2 boost-libs

Key point: most Metin2 sources are written to build with GCC, not with the system's default clang. So you have to name the compiler explicitly. The dependencies that cause the most trouble are:

  • MySQL client: without libmysqlclient and its headers, the db part will not compile.
  • Crypto++ (cryptopp): the server key and encryption routines depend on it, and version mismatches are a serious source of errors.
  • DevIL: some builds expect it for image/atlas handling.
  • Boost: newer source revisions may require it; older ones build without boost.

Build order: libraries first, then game and db

The Metin2 source is not a single project but several interdependent static libraries plus two main executables. To avoid breaking the dependency chain you have to build in the correct order. The typical order is:

libthecore  ->  core system abstractions
libpoly     ->  geometry / collision
libsql      ->  database layer (MySQL)
libgame     ->  shared game-logic code
libserverkey / equivalent
db          ->  database process
game        ->  game process

Each library is built in its own directory. Most sources ship with a Makefile; some use scons through an SConstruct file. The safest way to force GCC is to fix the compiler via environment variables:

cd Srcs/Server/libthecore/src
gmake -j2 CC=gcc CXX=g++

Build all the lib* directories first, then move on to db and game. If you try to build a process before the library it depends on, the linker stops with "undefined reference" errors.

The most common errors and how to fix them

The real difficulty is not the compilation itself but the points where old code clashes with modern headers. Here are the errors I see again and again:

  • "error: 'NULL' was not declared" or missing-type errors: usually caused by a header (<cstring>, <cstdlib>) not being explicitly #included. Old GCC pulled these in implicitly; new versions do not. Add the missing header at the top of the affected source file.
  • cryptopp link errors: "undefined reference" on symbols like Integer or RSA. This usually means the headers are one version and the linked libcryptopp.a is another. Fix: match the cryptopp path in the Makefile to the actual installed version, or use the cryptopp that ships with the source.
  • MySQL header not found: mysql.h: No such file or directory. The Makefile often expects /usr/local/include/mysql; if pkg installed it elsewhere, fix the -I flag. You can find the correct path with mysql_config --include.
  • It tries to build with clang: if you see nonsensical template errors, clang is very likely running instead of GCC. Make sure you passed CXX=g++.
  • 32-bit / 64-bit mismatch: some old sources were written for 32-bit. If you hit warnings and crashes from pointer-size differences on 64-bit FreeBSD, the cleanest option is to use a source revision adapted to 64-bit; otherwise you need a 32-bit toolchain via -m32.

After the build: verification

When you get the db and game binaries, the job is not done. Even if the linker passed, dynamic library mismatches surface at runtime. Run these checks:

file game db          # 64-bit or 32-bit, correct architecture?
ldd game              # any missing shared libraries?

If ldd says "not found", the library is either not installed or not in your LD_LIBRARY_PATH. Before starting the server, make sure the database schema is loaded and that the port and path settings in your conf.txt / CONFIG files are correct. Watching the syserr and syslog files on first launch lets you catch most configuration errors in the first minute.

Practical tips

  • Redirect build logs to a file (gmake 2>&1 | tee build.log) — finding the first error in the stack is far more valuable than the hundreds of follow-up errors at the bottom.
  • When you fix something, rebuild from that library onward rather than from scratch; but if you changed a header, clean everything that depends on it (gmake clean).
  • When you find a working compiler/library combination, write the versions down. With Metin2 sources, "what it was built with" is the most valuable piece of information.

Frequently Asked Questions

Can I compile the Metin2 source on Linux too?

Yes, but not directly. Because the code depends on FreeBSD-specific kqueue and system headers, Linux needs an epoll adaptation and various patches. If your production server runs on FreeBSD, building on FreeBSD is the path with the fewest problems.

Which FreeBSD and GCC version should I use?

There is no single correct version; a toolchain close to the era the source was written for produces the fewest errors. In practice the FreeBSD 10–12 range with a GCC version installed from pkg works well. The important thing is to build with GCC rather than clang.

How do I read an "undefined reference" error?

This is a link error, not a compile error: the compiler understood the file, but the linker could not find the body of the called function. It usually means you have not built a required library yet, or a -l flag/path is missing during linking. Check your build order and the library paths in the Makefile.

Is your Metin2 server source refusing to compile? If you need help with a clean build, debugging, or server setup on FreeBSD, get in touch with me — let's work out a solution tailored to your source and environment.

Devamı için