Building Custom DLL using MinGW for MetaTrader

I use MinGW gcc compiler on a Ubuntu system, I faced bugging issues when loading DLL on MetaTrader without much clue what was wrong. After getting this solved, now I am now sharing steps required for everyone.

First of all you need to place your dll into Metatrader MQL5/Libraries folder and allow DLL import from Tools -> Options -> EA, thats easy.

Second no “.def” files are required as mentioned by many peoples, also no used of inspecting problem with dependency walker tool, which gives errors unncessarity but it works anyway.

I built a working DLL using both Visual C++ 2010 and MinGW32 compiler and they both worked

Typical eerors you will get on mt4 when launching a dll based EA/Indicator is
– cannot load DLL – 126
– unresolved import function call

First error means DLL was not found in required path, so you need to place it under MQL5/Libraries directory. then this error should go away. when compiling script further you will get second error which is nasty.

This has to do with exported function name mangling and not at all with dependent dlls as anyone might suspect, it works easier in Visual C++ but in MinGW it creates problem so to fix that you simply use

extern "C" {
//// your function here

Next remove any __stdcall declartion from function signature.

for example, keep only

extern "C" {
__declspec(dllexport) int TestDLL() {
return 1234;


Cross compile boost library on Linux using mingw


1. unpack boost archieve file and cd to that
2. run ./
or better ./ --prefix="/installpath" ( NOTE: remove –prefix from later command )
3. edit project-config.jam
using gcc : mingw : i586-mingw32msvc-g++ ;
4. now run the command
./bjam toolset=gcc-mingw target-os=windows install --prefix='/mnt/boost' --with-random link=shared threading=multi variant=release address-model=32 architecture=x86

Specified boost library will get compiled and copied to /mnt/boost path