Author Topic: Linking SDL (and others) in a cross-platform way  (Read 5180 times)

Offline theOcelot

  • Multiple posting newcomer
  • *
  • Posts: 10
Linking SDL (and others) in a cross-platform way
« on: November 06, 2009, 03:15:57 am »
I'm trying to set up my programming project so that I can use the same CB project file on both Linux and Windows. It's in an SVN repo on sourceforge.net; you can browse it here: http://somnopatru.svn.sourceforge.net/viewvc/somnopatru/.

Anyway, I've moved to using global vars to represent library locations, and I can compile the simple static library sub-project that only requires headers. The problem is that linking an SDL application on Linux requires different (fewer) options than with MinGW. MinGW requires "-lmingw32 -lSDLmain -lSDL", while on Linux I don't need -lmingw32 (obviously).

Is there any way I can use the same project file on both platforms, or Some way to make Code::Blocks figure out when to add -lmingw32? Or am I barking up entirely the wrong tree?

I have a similar problem with Boost.FileSystem. On Windows I use -lboost_filesystem_mgw44-mt-d while on Linux it's just -lboost_filesystem. Does anyone have ideas for this? I know it's less of a Code::Blocks issue than a library setup one, but Code::Blocks may be able to help and I figured I may as well ask here.

Thanks.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Linking SDL (and others) in a cross-platform way
« Reply #1 on: November 06, 2009, 06:34:46 am »
Is there any way I can use the same project file on both platforms, or Some way to make Code::Blocks figure out when to add -lmingw32? Or am I barking up entirely the wrong tree?
A very convenient way would be to use C::B's platform option in the project options.
I do it as following:
1.) create a target for Windows, set the platform to windows
2.) create atarget for linux, set the platform to linux
3.) create a virtual target "all" that contains both of the above (that's the target I am compiling under all platforms)
4.) setup common options on project level
5.) setup platform specific options at project level.

That's all. If you compile the virtual target "all", C::B will skip the windows target on Linux and vice versa.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Linking SDL (and others) in a cross-platform way
« Reply #2 on: November 06, 2009, 06:43:27 am »
I guess
5.) setup platform specific options at project level.

should be:
5.) setup platform specific options at projecttarget level.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Linking SDL (and others) in a cross-platform way
« Reply #3 on: November 06, 2009, 08:46:20 am »
5.) setup platform specific options at projecttarget level.
Indeed. Copy&Paste error. :lol:
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline theOcelot

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Linking SDL (and others) in a cross-platform way
« Reply #4 on: November 06, 2009, 04:58:37 pm »
Perfect. Why didn't I think of that? Thank you both for your help.