News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

Custom value for a variable depending on the current platform

Started by MrPrise, June 10, 2008, 02:37:37 PM

Previous topic - Next topic

MrPrise

What is the suggested / ideal method to maintain a cross-platform project?
I have problem with the included libraries. On Windows I need to include the mingw32 lib, but on Linux I don't need that.
I use a custom variable on the linker settings page, but I don't know how can I change the value of that variable depending on the actual platform. How can I do this? Thanks.

mariocup

Hi MrPrise,

you could attach a script to your build targets e.g. settings.script. Here an example that could do the job.


function SetBuildOptions(base)
{
        if(PLATFORM == PLATFORM_MSW)
        {
                 base.AddLinkLib(_T("name"));
        }
} // end of SetBuildOptions


Bye,

Mario

MrPrise

That is exactly what I need! Thank you very much!

Update: I still have a little issue with that solution. I need to add mingw32 as the first library, else I get "undefined reference to `WinMain@16'"

MrPrise

I found the solution to my problem. I post it in case someone else have this problem.
Mariocup's solution was good in general, but for mingw32 it needs a little tunning, since I need to add mingw32 as the first library.
Here is my solution:
local libs_bk = base.GetLinkLibs();
base.SetLinkLibs(_T("mingw32"));
base.AddLinkLib(&libs_bk);

First, we get the current list of libraries (specified on the linker settings page). We replace the list of libraries with mingw32, than we append the original list of the libraries to the list.

mariocup

Hi MrPrise,

you could even surround your libraries with the linker options


-Wl,--start-group <list of libs> Wl,--end-group


then the order of libs is not relevant, as the linker will solve cyclic references.

Bye,

Mario

MrPrise

Thanks! Can I define custom variables in the build script?


MrPrise