[NTLUG:Discuss] OT: Porting Question
Greg Edwards
greg at nas-inet.com
Mon Aug 16 11:17:42 CDT 2004
> I realize now I should have given a good bit more information. I am
> wanting to take a program written in C, and built to run on x86 Linux,
> and port it to Windows/NT/2000, in the C language. I am wanting to,
> eventually, be able to go from Windows to Linux, but in this
> particular instance I need to go from Linux to Windows.
>
> Thanks,
> Dennis
Dennis,
This is how I approach ports with a C code base.
First make sure the entire code base is ANSI compliant. The fastest way
to do this is to turn on the ANSI standard compiler option, set the
warnings to their highest level, and set all warnings to be treated as
errors. Recompile all of the modules and fix every error to comply with
ANSI standards. Do not ignore even the slightest warning. If you are
using complier dependent functions either get rid of them or include
them in the next step.
Once the ANSI issues have been taken care of, find all of the OS (and
compiler) dependent functions and move them to either object files or
libraries. Libraries with well defined APIs is the better choice.
Next find all of the I/O that is being done with non standard functions
or tools and move that to objects or libraries. This would include non
console user I/O, database, graphic libraries, etc. Use generic APIs to
feed these objects and libraries from your main code base.
Now that your OS and machine dependent code has been isolated you can
move to the next platform and only have to deal with a small subset of
functions. Your platform dependent libraries and objects only need to
share API definitions. This approach makes it easy to change database
engines, graphic engines, compilers, and hardware platforms no matter
what the core program is intended to do. Once you've done the initial
port, most of your ongoing target builds can be controlled from your
makefiles.
Good luck,
--
Greg Edwards
Software Engineering Services - http://consult.nas-inet.com
Custom Hosted Websites - http://www.nas-inet.com
More information about the Discuss
mailing list