Author Topic: Custom value for a variable depending on the current platform  (Read 4136 times)

Offline MrPrise

  • Single posting newcomer
  • *
  • Posts: 8
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

  • Guest
Re: Custom value for a variable depending on the current platform
« Reply #1 on: June 10, 2008, 04:02:32 pm »
Hi MrPrise,

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

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

Bye,

Mario

Offline MrPrise

  • Single posting newcomer
  • *
  • Posts: 8
Re: Custom value for a variable depending on the current platform
« Reply #2 on: June 10, 2008, 04:10:56 pm »
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'"
« Last Edit: June 10, 2008, 04:29:52 pm by MrPrise »

Offline MrPrise

  • Single posting newcomer
  • *
  • Posts: 8
Re: Custom value for a variable depending on the current platform
« Reply #3 on: June 10, 2008, 04:55:01 pm »
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:
Code
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

  • Guest
Re: Custom value for a variable depending on the current platform
« Reply #4 on: June 10, 2008, 10:12:33 pm »
Hi MrPrise,

you could even surround your libraries with the linker options

Code
-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

Offline MrPrise

  • Single posting newcomer
  • *
  • Posts: 8
Re: Custom value for a variable depending on the current platform
« Reply #5 on: June 10, 2008, 11:33:50 pm »
Thanks! Can I define custom variables in the build script?

mariocup

  • Guest

Offline MrPrise

  • Single posting newcomer
  • *
  • Posts: 8
Re: Custom value for a variable depending on the current platform
« Reply #7 on: June 11, 2008, 12:28:41 pm »
Thank you for your help!