Reputation: 27200
see if i have made one c program in c on linux machine now if i want to compile that program on other os or lets say on windows how can i do that.?
what if i have used os specific things like pthread.h, in that program.?
Is there any direct way to do so.?
Upvotes: 0
Views: 283
Reputation: 67479
If your program depends on Unix libraries your best bet is to use Cygwin. Cygwin is a Unix compatibility layer on top of Windows, and comes with a collection of ported software, including bash, gcc, make and most other utilities you find on a Linux box. A port of pthreads is also available.
Upvotes: 0
Reputation: 11912
Yes, there is a direct way: try to compile, if something fails, try to find out why: is it a compiler-related difference or OS-related. If it's compiler-related, modify source code for your new compiler (VS probably, or you can just use mingw). If it's OS-related, you'll need to port the code, i.e. modify it to fit the new OS.
In case of pthread.h
, there's a Pthreads-w32 port of pthreads to windows, you can take a look at it.
Upvotes: 1
Reputation: 33167
see if i have made one c program in c on linux machine now if i want to compile that program on other os or lets say on windows how can i do that.?
Then I hope you were paying attention which APIs are available on Windows and which are not. This is not an easy problem to solve.
As you have used pthreads
, there is no API-compatible replacement on Windows. The native API is CreateThread
and its children. If you must maintain source level compatibility, you either create your own #ifdef
rules, wrapper, or use a third party library like APR.
Upvotes: 3
Reputation:
You can't use any libraries that don't come with Windows, or that you can't use with Windows. But it looks like there are implementations of pthread for Windows. You should check to see what the Windows equivalent is of whatever libraries you use.
Upvotes: 0