User forums > Using Code::Blocks

Custom value for a variable depending on the current platform

(1/2) > >>

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.


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

--- End code ---

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:

--- Code: ---local libs_bk = base.GetLinkLibs();
base.SetLinkLibs(_T("mingw32"));
base.AddLinkLib(&libs_bk);

--- End code ---
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


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

--- End code ---

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

Bye,

Mario

Navigation

[0] Message Index

[#] Next page

Go to full version