EvilZone

Programming and Scripting => Projects and Discussion => Topic started by: kenjoe41 on August 15, 2013, 12:27:42 PM

Title: OS auto detection - project feature
Post by: kenjoe41 on August 15, 2013, 12:27:42 PM
I am working on a project now in C++ which i want to be portable for windows, Linux and Macos.
Problem is the auto detection of the os so as to locate certain file which are stored in different paths as per the OS.

Right now the project works just fine but it requires the file path as an arg which might be pretty difficult for non-experienced users.
Am trying to stay away from the #include <windows.h> header which might restrict the code to windows and environ() isn't working its magic to my liking.

Any code snippet is welcome.
Title: Re: OS auto detection - project feature
Post by: Ragehottie on August 16, 2013, 11:49:04 PM
That's very poor practice with compiled languages.


Try detecting the os at compile time, or distribute 3 separate source codes/binaries
Title: Re: OS auto detection - project feature
Post by: Kulverstukas on August 17, 2013, 07:26:46 AM
It is impossible to make a compiled program portable on run time. It can only be done in compile time, bro.
Different systems have different executable structures. What is compiled for windows, will not work for linux and vice versa, even if you don't use <windows.h>.
However, scripts, such as Python, can be portable between systems.

You will have to think of something better.
Title: Re: OS auto detection - project feature
Post by: kenjoe41 on August 19, 2013, 02:50:47 PM
My only solution is to try code something for each OS then distribute different binaries.
OR better just distribute the source code for the different OS so people can compile it themselves.

Thanks.
Title: Re: OS auto detection - project feature
Post by: WirelessDesert on August 19, 2013, 03:15:19 PM
Google "premake4" or "CMake" for a good compile time multi OS thingy :).
do some compiler commands to see if the build is OSX, Win, *nix or whatever.
CMake is also implemented for most IDE's
Title: Re: OS auto detection - project feature
Post by: kenjoe41 on August 19, 2013, 03:59:03 PM
CMake is also implemented for most IDE's
If you mean most IDEs like Code::Blocks, am right on it now.
Title: Re: OS auto detection - project feature
Post by: bluechill on August 19, 2013, 11:00:00 PM
It is impossible to make a compiled program portable on run time. It can only be done in compile time, bro.
Different systems have different executable structures. What is compiled for windows, will not work for linux and vice versa, even if you don't use <windows.h>.
However, scripts, such as Python, can be portable between systems.

You will have to think of something better.

Wrong I did it in OLink.  But it is a bit of a pain and probably too much trouble for most things.  But you can do it.  It just requires writing your own binary loader for say, ELF binaries, and then loading them yourself on each platform.  You will need a slight bit of start up code on each platform though.
Title: Re: OS auto detection - project feature
Post by: Kulverstukas on August 20, 2013, 07:41:50 AM
Wrong I did it in OLink.  But it is a bit of a pain and probably too much trouble for most things.  But you can do it.  It just requires writing your own binary loader for say, ELF binaries, and then loading them yourself on each platform.  You will need a slight bit of start up code on each platform though.
Doable while not very practical.
Title: Re: OS auto detection - project feature
Post by: kenjoe41 on August 20, 2013, 02:22:34 PM
For the project am working on, it's just not worth the sweat as of now.
Just gonna bundle install scripts with the source code for both Os x and Linux.
I will try that with a more promising project and alot of time on my hands.