Writing C/C++ with Unix Api in Visual Studio?
I'm a third year computer science student. I was raised on Visual C++ and have gotten quite proficient at using it. My school however, teaches primarily on Linux platforms. Up until now I have just programmed and debugged in Visual studio, then when I was certain I got every开发者_开发技巧thing working, I would recompile the source in Linux to make sure it work there.
Now however now my projects require use of the Unix API calls, Berkly sockets and sometimes pthreads.
Are there libraries available that give me access to the Unix API on windows? If so how would i go about using them Visual C++ 2010?
I really don't want to have devolve to using Gedit and Gdb for debugging complex(for me at least) code.
Typically, you would just use the platform-independent equivalents found in various libraries- usually Boost. However, if you must use the Unix-specific APIs, the only way to go will be to wrap their functionality for Windows. Likely, there already exist libraries that serve this purpose, much as you can use WINE and such for Unix, but as a Windows programmer myself I wouldn't really know.
You could try something like Cygwin to provide the Unix API in Windows, build and compile there, then make any minor adjustments to use the native API when you transfer to Linux.
You can also check each library to see if a Windows version is available. If no Win version is listed on the lib's site, Google around and see if someone has built it for Windows; that may provide you a usable version.
If you don't specifically need the Unix API, Boost or another cross-platform library is probably your best bet to provide the needed functions.
For non-Windows development, finding a replacement to VS is probably a good idea (unfortunately there's really no IDE that can compare, IMO). Code::Blocks is the nearest, but is still missing a lot of features. KDevelop has been recommended to me several times, seems nice at first glance. Eclipse is maybe the only IDE slower than VS2010, something to consider before using it.
Most Unix-only APIs aren't available for Windows. I suggest you switch to Code::blocks, which is cross-platform. It is pretty similar to VC++ in many ways, and it's easy to get used to it.
Either switch to Code::blocks, or switch to Eclipse - both of which are multi-platform. I can attest that Eclipse 3.6 works awesome debugging C++ Qt apps on Linux and Windows.
I know this is late, but a good answer is never too late! Hopefully mine is one.
The only thing I can think of is use the preprocessor.
#ifdef __unix__
...UNIX code here
#endif
and write the UNIX code in the block so that you can compile it on the UNIX system required. Then, outside those blocks you could use the WIN32 analogs inside a similar block
#ifdef _WIN32
...Windows code here
#endif
Such that an end result may look like
//Cross platform includes
//cross platform namespaces
#ifdef _WIN32
//Windows includes
//Windows namespaces
#else
//unix includes
//unix namespaces
#endif
int main()
{
DoCrossPlatformFunctions();
#ifdef _WIN32
DoWindowsFunctions();
#else
DoUnixFunctions();
#endif
DoMoreXplatformStuff();
return 0;
}
You could do some short research and find the analogs to the functions you require fairly easily and then be on your way. It's a bit cumbersome, but since you seem to have a vendetta against just writing it in a UNIX VM in the first place it's probably the best option. The best part is you don't have to step outside your Visual C++ comfort zone to do it. I hope this helps!!
精彩评论