• Freedom at last, Linux + MingW cross compiler’s endless possibilies

    Having worked on an RTS (real time strategy) open source game at sourceforge.net, I came across many challenges but also learned many things related to the world of open source. This article will attempt to discuss some of those things in the hope that the information helps other developers in the open source realm. I will attempt to share this in 2 parts, part 1 will be the ultimate way to freedom, while part 2 will discuss things encountered along the way and will act almost as a kind of story.

    Part 1: Cross compiling your C/C++ open source project in Linux, for Linux and Windows.

    The basic recipe that I used to accomplish this involves the following:

    – CodeBlocks IDE (you could likely use eclipse too)
    – MingW cross compiler
    – All the source code for your project (and its dependencies)
    – time (the precious commodity that everyone wants from you)

    For the first 2 items (CodeBlocks and MingW) got the following links:

    CodeBlocks
    MingW

    Now, a few things to keep in mind as you travel through the compilation process:

    – you MUST recompile all dll’s and libs within MingW (VC++ and other compilers are NOT compatible with MingW)

    Take for example compiling OpenAL (Open Audio Library) from Creative that many open source projects use. Compiling this library includes a few challenges, including the need to fix dsound.h from the DirectX SDK to compile with MingW.

    edit dsound.h and comment out line 1899:

    //typedef struct IDirectSoundFullDuplex *LPDIRECTSOUNDFULLDUPLEX;

    next edit the file included in the OpenAL SDK named XCompile.txt so its looks something like the following:

    # Cross-compiling requires CMake 2.6 or newer. To cross-compile, first modify
    # this file to set the proper settings and paths. Then use it from build/ like:
    # cmake .. -DCMAKE_TOOLCHAIN_FILE=../XCompile.txt \
    #          -DCMAKE_INSTALL_PREFIX=/usr/mingw32/mingw
    # If you already have a toolchain file setup, you may use that instead of this
    # file.

    # the name of the target operating system
    SET(CMAKE_SYSTEM_NAME Windows)

    # which compilers to use for C and C++
    SET(CMAKE_C_COMPILER i586-mingw32msvc-gcc)
    SET(CMAKE_CXX_COMPILER i586-mingw32msvc-g++)

    # here is the target environment located
    SET(CMAKE_FIND_ROOT_PATH /usr/i586-mingw32msvc)

    # adjust the default behaviour of the FIND_XXX() commands:
    # search headers and libraries in the target environment, search
    # programs in the host environment
    set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
    set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
    set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

    Next edit CMakeLists.txt to tell it where to find your DirectX SDK files adding something like the following BEFORE the section:

    # Check DSound/MMSystem backend
    IF(DSOUND)

    Add the following:

    SET (DXSDK_DIR "/home/softcoder/Code/megaglest/trunk/source/win32_deps/Microsoft DirectX SDK (November 2007)")
    SET(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} "${DXSDK_DIR}/Include")
    INCLUDE_DIRECTORIES("${DXSDK_DIR}/Include")
    LINK_DIRECTORIES("${DXSDK_DIR}/Lib")

    Next run cmake to produce the makefiles for OpenAL which should now properly find direct sound from DirectX:

    cmake .. -DCMAKE_TOOLCHAIN_FILE=../XCompile.txt -DCMAKE_INSTALL_PREFIX=/usr/i586-mingw32msvc

    make

    after running this you should get OpenAL lib’s / DLL’s produced for MingW.

    As a general rule you simply need to point the compiler etc.. the MingW’s and any dependencies need to find your MingW compiled libs.

    For example Compiling lobogg and libvorbis:

    ./configure --host=i586-mingw32msvc --build=i686-pc-linux-gnu --enable-shared --disable-static --libdir=./lib

    make

    LDFLAGS="-L/home/softcoder/Code/megaglest/trunk/source/win32_deps/lib" ./configure --host=i586-mingw32msvc --enable-shared --disable-static --with-ogg-libraries=../lib --with-ogg-includes=../libogg-1.2.1/include

    make

    What should you do if you get lots of:

    undefined reference to x

    linker errors? This typically means you need to order the libs in your project in proper order! Here’s an example from my codeblocks project file (the order does matter):

    <Linker>
              <Add option="-Wl,-subsystem,console" />
              <Add option="-mconsole" />
              <Add library="mingw32" />
              <Add library="ddraw" />
              <Add library="dsound" />
              <Add library="dxguid" />
              <Add library="ws2_32" />
              <Add library="iphlpapi" />
              <Add library="wsock32" />
              <Add library="liblibogg" />
              <Add library="liblibvorbis" />
              <Add library="liblibvorbisfile" />
              <Add library="zlib" />
              <Add library="jpeg" />
              <Add library="liblibpng" />
              <Add library="xerces-c" />
              <Add library="OpenAL32" />
              <Add library="liblibcurl" />
              <Add library="winmm" />
              <Add library="gdi32" />
              <Add library="opengl32" />
              <Add library="glu32" />
              <Add library="SDL" />
              <Add library="SDLmain" />
              <Add library="lua5.1" />
              <Add library="streflop" />
              <Add library="glest" />
              <Add directory="../../source/win32_deps/lib" />
              <Add directory="../../source/win32_deps/xerces-c-src_2_8_0/lib" />
    </Linker>

    Also what should you do if you program always produces stdout.txt and stderror.txt even though the application is a console application? It appears that this can happen due ti SDL taking convtrol of these streams. You can recompile SDL with:

    ./configure --disable-stdio-redirect

    For more details check out: here

    Another item that caused trouble was wxWidgets. I kept getting the following error after running configure:

    ./configure --target=i586-mingw32msvc --host=i586-mingw32msvc

    /home/softcoder/Code/megaglest/trunk/source/win32_deps/wxWidgets-2.8.10/bk-deps i586-mingw32msvc-gcc -c -o wxexpat_xmlparse.o -I./src/expat   -I/home/softcoder/Code/megaglest/trunk/source/win32_deps/wxWidgets-2.8.10/lib/wx/include/i586-mingw32msvc-msw-ansi-release-2.8 -I./include -mthreads -Wall -Wundef -O2 -fno-strict-aliasing -mthreads ./src/expat/lib/xmlparse.c
    ./src/expat/lib/xmlparse.c:97:2: error: #error memmove does not exist on this platform, nor is a substitute available
    ./src/expat/lib/xmlparse.c: In function ‘XML_SetEncoding’:
    ./src/expat/lib/xmlparse.c:888: error: ‘isParamEntity’ undeclared (first use in this function)
    ./src/expat/lib/xmlparse.c:888: error: (Each undeclared identifier is reported only once
    ./src/expat/lib/xmlparse.c:888: error: for each function it appears in.)
    ./src/expat/lib/xmlparse.c:888: error: ‘externalParEntInitProcessor’ undeclared (first use in this function)
    ./src/expat/lib/xmlparse.c: In function ‘XML_SetReturnNSTriplet’:
    ./src/expat/lib/xmlparse.c:1110: error: ‘isParamEntity’ undeclared (first use in this function)
    ./src/expat/lib/xmlparse.c:1110: error: ‘externalParEntInitProcessor’ undeclared (first use in this function)
    ./src/expat/lib/xmlparse.c: In function ‘XML_SetParamEntityParsing’:
    ./src/expat/lib/xmlparse.c:1362: error: ‘isParamEntity’ undeclared (first use in this function)
    ./src/expat/lib/xmlparse.c:1362: error: ‘externalParEntInitProcessor’ undeclared (first use in this function)
    make: *** [wxexpat_xmlparse.o] Error 1

    To fix this issue I had to edit the configure script and add the following:

    ORIGINAL:

    OPTIMISE_CFLAGS=
    if test "$wxUSE_OPTIMISE" = "no" ; then
        if test "$GCC" = yes ; then
                            OPTIMISE_CFLAGS="-O0"
        fi
    else
        if test "$GCC" = yes ; then
            case "${host}" in
                *-pc-os2_emx | *-pc-os2-emx )
                                                    OPTIMISE_CFLAGS="-O2"
                ;;
                *)
                                                                    OPTIMISE_CFLAGS="-O2 -fno-strict-aliasing"
                ;;
            esac
        else
            OPTIMISE_CFLAGS="-O"
        fi
    fi

    FIXED:

    OPTIMISE_CFLAGS=
    if test "$wxUSE_OPTIMISE" = "no" ; then
        if test "$GCC" = yes ; then
                            OPTIMISE_CFLAGS="-O0"
        fi
    else
        if test "$GCC" = yes ; then
            case "${host}" in
                *-pc-os2_emx | *-pc-os2-emx )
                                                    OPTIMISE_CFLAGS="-O2"
                ;;
                *-*-cygwin* | *-*-mingw32* )
                    OPTIMISE_CFLAGS="-O2 -fno-strict-aliasing -DHAVE_MEMMOVE=1 -DXML_DTD"
    
                    echo "=====================> MingW Fix Setup"
                ;;
    
                *)
                                                                    OPTIMISE_CFLAGS="-O2 -fno-strict-aliasing"
                ;;
            esac
        else
            OPTIMISE_CFLAGS="-O"
        fi
    fi

    I re-ran configure and then make compiled everything properly.

    For my project I successfully compiled:

    xerces-c
    lua5.1
    sdl
    opengl
    curl
    openal
    libpng
    jpeg
    zlib
    libogg
    libvorbis


    Part 2: Why is it a good idea to cross compile?

    If your software supports multiple platforms (like many “good” open source projects do), then you already know the answer. It can be a very tedious task to try to maintain code for multiple platforms especially if you cannot easily, quickly compile your code changes for the target platform in one development environment (and operating system). Some people use Virtual Machine Software (Like the highly recommended Virtual Box) but even this approach often leaves you feeling dirty, having to load up some version of Windows in your VM (assuming of course that you have a legit license, etc). All to offer a binary for those poor “entangled” windows users!

    No more! Now we simply target the same code to the Windows platform and it builds the binaries using the MingW cross compiler! Now developers can focus on cross platform code with a purpose, and not worry so much about how to compile for those other platforms. This should open the doors for a broader audience for numerous open source projects (especially where build resources are limited). Add to this the installation of WINE (here) and you can also test the windows binary from your Linux environment. Lovely! This means you may support more users without compromising your coding morals.

    Thanks, and I hope this helps others.


  • God among the Zulu’s – a report from South Africa

    It is amazing how we find ourselves ending up in the most unexpected places in life! It was years ago (in the 1990’s) that a friend of mine had passed on some tapes which contained preaching by Erlo Stegen and Trevor Dahl (of which both are ministers in South Africa). I remember the spiritual challenges they laid out in their messages and how they persistently gave a call for a holy, Spirit filled life in Christ. Over the years I had searched to come in contact with these men to see where they are spiritually speaking today? There had been reports about God working among the Zulu people in the early 1960’s through the ministry of Erlo Stegen and I was curious about the state of the community today. Ultimately God would work out events in my life that lead to a trip to Tugela Ferry, South Africa in March of 2010.

    It was a long journey (36+ hours by plane) but eventually we landed in Durban, South Africa. We were met by two members of the Tugela Ferry Rock of Life church and were kindly transported to Tugela Ferry. As we drove further from Durban and closer to Tugla Ferry it became obvious that the living standards in these communities were worlds apart. Here are a few facts taken from a newsletter by the Rock of Life Church in Tugela Ferry:

    Tugela Ferry is the largest populated area in the Msinga district of Kwa Zulu-Natal. The Tugela River flows through the Northern border of the rural village of Tugela Ferry. There is an estimated population of one million people.

    Rock of Life Christian Church started in 1964 as a very small local church. The congregation grew steadily and in 2000 the membership totaled 400.

    The church has on staff six full time pastors, ten elders, and seven deacons.

    Worship services are held on Sundays at 10:30am with Sunday School for the children. The church has twelve branches that serve the region.

    Below is a typical Sunday morning service at the Rock of Life Church:



    A typical Sunday morning service at Rock of Life Church

    This is perhaps the poorest region in South Africa and is literally the “heart” of Zulu-land.



    Overlooking the Tugela Ferry region
    This was a typical Zulu home from what I saw while in the area

    The needs in this region are great. There are souls at every mountainside, living vast distances away from civilization making it hard to reach many. AIDS is an unprecedented epidemic is this area where once the cycle begins, it is nearly impossible to stop. 4 out of every 5 children under 15 will die before they reach adulthood. Orphans are many and poverty is in the majority. I was completely overwhelmed by what I saw and I cried out to God for this people, that He would send labourers and indeed if it is His Will I would go.

    Elzeth Malherbe, a dear woman of God has given her life to care for orphans in the area having worked among this people for decades. She administers the Khayelisha Care Orphanage where children who would otherwise die are taken in and cared for.

    At the time of this writing I cannot say for certain in what way I will be involved with this need that would take many lifetimes to address, but I pray and cry out to the Lord for His Grace and His Church to get a feeling for the vast need. As the scripture says:

    Ephesians 4:16 From whom the whole body fitly joined together and compacted by that which every joint supplieth, according to the effectual working in the measure of every part, maketh increase of the body unto the edifying of itself in love.

    1 John 3:17 But whoso hath this world’s good, and seeth his brother have need, and shutteth up his bowels of compassion from him, how dwelleth the love of God in him?

    While the church body in Tugela Ferry is running full blast to help in every way they can (lead by Pastor Barney Mabaso), we the rest of the body of Christ should seek the Lord and ask Him in what way He would have us to help. Let me say that the greatest need (in my opinion) is NOT money. These people need help, prayer support, encouragement, intercessions and a fresh anointing of the Holy Spirit! Yes, God is among the Zulu’s and these people are WIDE OPEN to the gospel. They have many customs that in some ways prepare them for coming to Jesus.

    I recall a discussion with pastor Barney regarding musical instruments. Barney mentioned “we blacks don’t need them, God placed it in our mouths”. I must agree with this dear brother:

    The choir singing ‘repent’

    In conclusion I would love to answer any question that my readers may have regarding this people, just send me an email to (mark_vejvoda @ h o t m a i l . c o m ) but I will post contact information for the Christians working directly in this area. These people are trustworthy and very competent, God fearing servants of Christ:

    Rock Of Life Church
    Tugela Ferry Mission

    PO box 397, Tugela Ferry, 3010 email: tugmission @ x s i n e t . c o . z a
    Ph. 033 493 0087 FAX 033 493 0083

    For more photos of Tugela Ferry, check out my facebook photo album:

    here


  • VC++ 2008 express (vs2008) – fatal error C1085 … The parameter is incorrect.

    Recently while trying to compile wxWidgets for the open source project glest, I kept getting errors in VC++ 2008 express edition related to pre-compiled headers. The errors were:

    fatal error C1085 … The parameter is incorrect.

    In my case the solution was found here (see Gary Gilbreath’s comment.. especially item #3)

    I was compiling on a mapped network drive (in my case using VirtualBox’s shared folders) and VS2008 does NOT like working on pre-compiled headers on network drives. The solution was to change the path of the pre-compiled headers from pointing to my mapped drive (w:) to c:\xx.pch


  • A house of cards – The Canadian Financial System

    I have for some time had an interest and have studied financial systems for Canada and America. At first my interest came when I worked for an online stock trading company, at which time I took the Canadian Securities course (CSC) which I never completed.

    I learned so much about the “real” side of the system in those years (being included in conferences calls with brokers, etc). Since that time I have researched more heavily the history of the American and more recently the Canadian financial systems and have thus far concluded they are “By design” a disaster waiting to happen.

    First allow me to discuss the Canadian side, the “Bank of Canada”. Taken from the Bank of Canada website here are some facts (irrelevant points skipped):

    1.  What is the Bank of Canada?

    The Bank of Canada is the country’s central bank. Its role, as defined in the original Bank of Canada Act of 1934, is “to promote the economic and financial welfare of Canada.”

    3. Who owns the Bank of Canada?

    The Bank was founded in 1934 as a privately owned corporation. In 1938, the Bank became a Crown corporation belonging to the federal government. Since that time, the Minister of Finance has held the entire share capital issued by the Bank.

    4. Is the Bank of Canada a government department?

    No, it is a special type of Crown corporation. The Bank has considerable autonomy to carry out its responsibilities.

    5. Why do we need a central bank?

    The Bank of Canada was created to be the sole issuer of bank notes and to facilitate management of the country’s financial system.

    Having an independent monetary institution allows for the separation of the power to spend money from the power to create money.

    Separating the central bank from the political process enables it to adopt the medium- and long-term perspectives essential to conducting effective monetary policy.

    7. Can I file a complaint with the Bank of Canada regarding a bank?

    No. The Bank of Canada does not play any part in the regulation or daily administration of commercial banks. To file such a complaint, contact the Financial Consumer Agency of Canada.

    and last (but certainly NOT least)…

    8. How does the Bank of Canada pay its operating expenses?

    The revenues generated by the Bank each year greatly exceed its operating expenses.

    The revenues derive from the Bank of Canada’s role as the issuer of bank notes to Canada’s financial institutions. Institutions pay the Bank when they withdraw bank notes from it. The Bank then invests these funds in government bonds and treasury bills. The interest earned on these investments is the Bank’s main source of revenue.

    The difference between the interest the Bank earns and its operating expenses is its net profit, which is given to the federal government. In recent years this profit has averaged about $1.7 billion annually.

    This process, whereby a central bank earns revenue in exchange for its role as the issuer of a country’s currency, is called seigniorage.

    Here is some food for thought:

    The purpose of the central bank in Canada is “to promote the economic and financial welfare of Canada.”. In 1938, the Bank became a Crown corporation belonging to the federal government. Is the Central Bank a government run department? No, it is a special type of Crown corporation. The Bank has considerable autonomy to carry out its responsibilities. The Bank of Canada was created to be the sole issuer of bank notes and to facilitate management of the country’s financial system.

    In some ways this may sound very noble, but something just feels wrong. How does this central bank make money and how do the private banks make money and who is affected?

    The revenues derive from the Bank of Canada’s role as the issuer of bank notes to Canada’s financial institutions. Institutions pay the Bank when they withdraw bank notes from it. The Bank then invests these funds in government bonds and treasury bills. The interest earned on these investments is the Bank’s main source of revenue.

    So lets try to understand this. The central bank prints money (bank notes) and is the “sole issuer”. The more they print, the less each dollar is worth that is sitting in my bank account and my wallet (that is called inflation). Who creates inflation? The central bank does (not you and me). Why is our money worth less? Because each time they print notes, there is nothing backing the value of those notes (like gold or other real goods) so as they introduce more notes, it de-valuates the existing notes (like what happened in Germany during the world wars).

    So the bank “issues” bank notes to “financial institutions”. What did it cost the bank to print these notes, or rather “issue” notes (think of the cost of introducing numbers into a computer). Almost nothing compared to the value of that note. It was virtually “for free” to create that money and lend it to private banks.

    Now lets say the central bank lends $1.00 Canadian to a private bank and charges them $0.05 to do  so. In order for that bank to pay that fee and make profit, they lend it to you and me by charging the original fee of $0.05 + their profit margin (say $0.15) = the cost for you and I $1.20.

    My question is why should these banks essentially “for free” make money from us? Why can’t we get in at the $0.05 on the dollar? Why are we dealing with usury middle-men who get the privilege of charging us for something they didn’t earn, they got $0.15 on the dollar for doing nothing! Further more when these banks fail, it almost always ends up with a bail-out of some kind (it HAS to since there is nothing to back these notes in the first place, unless you count the fact they liquidate all of your assets when you declare bankruptcy).

    Next the central bank takes that $0.05 for each dollar lent to private banks and “invests” it in Bonds and T-Bills. These are primarily bought up my foreign investors and private banks. Essentially by design the central bank %100 relies on the private banks and the private banks %100 rely on the central bank. Each will NEVER allow the others to disappear. While the purpose of the central bank is to separate the politic process from the monetary system, its purpose is ALSO: Having an independent monetary institution allows for the separation of the power to spend money from the power to create money.

    This separation clearly DOES NOT EXIST!

    Perhaps another time I will discuss the American System, which might I say is “the cavalier of all systems”. Canada is quite mild in comparison to the American counterpart. For starters look here.