User forums > Using Code::Blocks
OS-dependent library linking?
(1/1)
mkaut:
Hello,
I have a project that I build on Windows and Linux. Most of the targets work for both platforms, but one of them needs winsocks when compiled on Windows.
I want to avoid having two targets, so I wanted to ask what is the best/recommended way of dealing with this situation?
I tried adding the winsocks to "Other linker options" using the $if(){}{} command:
$if("OS == Windows"){-lws2_32}{}, but did not find any way to write the OS == Windowscondition.
At the end, I just created a custom compiler variable WINSOCKS=ws2_32 in my Windows installation of C::B and use the following test:
$if($WINSOCKS){-l$WINSOCKS}{}. This works for me, but it will fail for anyone else who will try to build the project on Windows, without the variable defined..
So, my question is, is there a better way?
As a side note, the target file prepends three libraries to the project settings:
PocoDataMySQL, mysqlclient, and ws2_32 (in this order). If I have the first two as "Link libraries" and winsocks in "Other linker options", the linker gets
-lws2_32 -lPocoDataMySQL -lmysqlclient, i.e., winsocks goes first ... which does not work. As a result, I have to move the other two libraries to "Other linker options" - not really an issue, just that I would expect "other options" to go at the end.
BlueHazzard:
You can add a squirrel script in the build process:
Add this in the linker settings, other linker options
--- Code: ---[[if(PLATFORM == PLATFORM_MSW) {print("-lws2_32"); };]]
--- End code ---
more information about build scripts and squirrel:
http://wiki.codeblocks.org/index.php?title=Scripting_commands
http://wiki.codeblocks.org/index.php?title=Variable_expansion#Script_expansion
greetings
BlueHazzard:
or you use build scripts http://wiki.codeblocks.org/index.php?title=Build_scripts but for this you need a additional file
mkaut:
--- Quote from: BlueHazzard on March 31, 2014, 11:10:26 am ---You can add a squirrel script in the build process:
Add this in the linker settings, other linker options
--- Code: ---[[if(PLATFORM == PLATFORM_MSW) {print("-lws2_32"); };]]
--- End code ---
--- End quote ---
This worked, thanks a lot! :)
mkaut:
--- Quote from: BlueHazzard on March 31, 2014, 11:13:47 am ---or you use build scripts http://wiki.codeblocks.org/index.php?title=Build_scripts but for this you need a additional file
--- End quote ---
Thanks.
I think I will go with the first/easier solution, but good to know about this approach..
Navigation
[0] Message Index
Go to full version