I'd like to write and reuse same code in both Linux and Windows, especially the path constants.
fopen(base+"subfolder/abc.bin","wb")
The above code worked fine when I cross compiled for Windows in Linux.
But, I had to change the code to fopen(base+"subfolder\\abc.bin","wb")
to compile it in windows directly.
Now I have added many dependencies to the software which would require cross compilation if I cross compiled my software, which I don't wanna do, so, I use precompiled binaries in both Windows and Linux versions of the software.
The issue now, I face is if I wanted to compile in Linux, I'd have to change the path which I don't want to do, as I'd have to maintain, two different branches of the software. Is there a way, akin to Java using Paths.get("abcd/def/hij.bin").toString()
. I'm not just asking for a system call, a custom function which identifies underlying OS and changes the path string accordingly, will do.
I need both C and C++.