getopt() in VC++ - c++

I'm quite fond of using GNU getopt, when programming under Linux. I understand, that getopt(), is not available under MS VC++.
Note:
Win32 environment
using Visual Studio
No Boost
No MFC
Not concerned with portability
Question:
How can I then port getopt() accordingly?
What guidelines should I be aware of while porting?
Known port with same features?

This may help, it's also very easy to integrate
http://www.codeproject.com/KB/cpp/xgetopt.aspx

There is some old code originally by IBM that is available as-is. It only has implementation for getopt, not the _long variants.
It's available on http://plexfx.org/news/files/70411c2c371bd686273a8bebc42c45c5-3.html

You will have to check out the license requirements, but the source to the GCC libraries is freely available. Just grab getopt() from there.

Related

How do I determine which C/C++ compiler to use?

I am trying to figure out which C/C++ compiler to use. I found this list of C/C++ compilers at Wikipedia:
http://en.wikipedia.org/wiki/List_of_compilers#C.2FC.2B.2B_compilers
I am fairly certain that I want to go with an open source compiler. I feel that if it is open source then it will be a more complete compiler since many programmer perspectives are used to make it better. Please tell me if you disagree.
I should mention that I plan on learning C/C++ mainly to program 2D/3D game applications that will be compatible with Windows, Linux, MAC and iPhone operating systems. I am currently using Windows Vista x64 OS.
First of all, IMHO as a beginner your development environment (IDE) matters a lot more than the compiler.
I think that people place too much emphasis on compiler choice early on. While it is not Java, C++ is meant to be portable.
If the program you're writing only works with specific compilers, you're probably doing the wrong thing or can work a little on making it more portable.
If you get to a point where compiler choice makes a significant performance impact for you, then you've already perfected everything else in your program and you're in a good state and you are also quite advanced in your abilities. We used to teach the differences between compilers at fairly advanced stages in the CS curriculum.
If you use a UNIX based machine (Linux, Mac, actual Linux), then pretty much GNU (g++) is the way to go and is fairly much standard. If it's good enough to compile your OS, it's probably good enough for you. On a mac you can use XCode as your IDE, and it interfaces well with g++. On Linux some people prefer command line tools, though you might like the Eclipse C++ support, it is much better today than it was 3-4 years ago.
Things on Windows are trickier. If you can afford it, have access to, or are eligible for one of the free editions (e.g., via a school), I think the Microsoft Visual C++ Environments (or whatever they are called now) are pretty good for learning and they are used in production. I think there's actually a lightweight visual studio now with an emphasis on C++ that could be a good start. If you don't, you can probably find a distribution of Eclipse that is specific for C++ and includes an implementation of the GNU compilers.
Use gcc and g++ while you're still learning these languages, a big enough task for now. If you need a specialized compiler down the road, you'll want to have much deeper understanding of the language and your problem domain to properly evaluate candidates.
I feel that if it is open source then it will be a more complete compiler since many programmer perspectives are used to make it better.
That's not necessarily true. You could also say that if you use Microsoft's compiler, it will be optimal for Windows, since Microsoft knows best how to optimize a compiler for Windows.
Microsoft has Visual C++ Express Edition which is free and ofcourse includes a nice IDE that's very well suited for Windows development.
But if you're interested in making portable software, look at GCC, which is the default compiler on Linux and which is also available on the Mac. (The iPhone works totally different and requires special tools that only run on Mac OS X). You can get GCC for Windows with Cygwin or MinGW.
Get the Visual Studio Express (easier and quicker IMO, to setup) and learn with it; when you think you know enough about C++ and how "things" work, you could start using something like QT or GCC (with cygwin) and learn to port to different platforms.
For windows u can use CodeBlocks I believe it uses gcc and its pretty user friendly
I strongly suggest going with MinGW.
It is:
Open-source
Available on all major platforms
Comes with standard Win32 headers and libraries
The key to writing portable C++ code is:
Use a cross-platform version control system (subversion is a great choice), because this makes it easier to
Compile and test your code on other platforms early and often

Which library would you consider on linux for DEA (Data Encryption Algorithm)?

I need a 3DES encrypt/decrypt library for my project.
Do you know an implementation working on linux ?
Linux is the target platform, but I essantially compile/debug on Windows. Therefore it could be really appreciated if it could work on Windows, while not mandatory.
OpenSSL is a very reputable, well tested open source security library. It's available for *nix and Windows. You can find it here
Edit, can't find a simple example right now. The API documentation is pretty good though.
There's a pre-compiled version for windows available for download from the openssl site. Most package managers will have a pre-packaged version of OpenSSL for Linux boxes, so you shouldn't have to compile your own version.
Look for Eric Young's "libdes".
This library can be also used on Windows as well as on Linux.
I have used botan before and I really like it. It has an implementation of not only 3DES but a lot of others algorithm. It is C++ so their API is Object Oriented (I like this feature while other might disagree). It supports a lot of systems (Windows, Linux, FreeBSD, etc), a lot of processors (x86, x86-64, IA-64, PowerPC and so on) and compilers. It seems to have a very good performance. Finally its license allows commercial developments.
At least it's Worth to have a look ;-)
you can compile libcrypto (openssl) for windows but I wouldn't recommend it:
http://www.pixelbeat.org/programming/lib_crypto.html
Maybe NSS used by firefox would be useful?
http://www.mozilla.org/projects/security/pki/nss/
Though I'd probably try something simple like:
http://www.lysator.liu.se/~nisse/nettle/nettle.html

Which IDE for C++ software can I use for targeting Windows, Linux and OSX?

I was reading today question on IDEs fo C++, and there are very good ones like Netbeans.
My question is about creating a software in C++ on Windows Environment, but let users install and run my software also on Linux and OSX.
Does netbeans has a compiler to do the job, or is there any good IDE which has a compiler for targeting my c++ code to these other environments?
thank you
QtCreator. It's awesome, slick and everything.
While it is not as feature rich as some competitors, it does many things just right that others don't.
I would say it is the one truly cross-platform IDE that is competitive to single-platform solutions. And it comes with tight integration of a very powerful and clean cross-platform toolkit. Something that you need for most cross-platform applications by itself.
I use Eclipse CDT and have had some degree of success. But I'm a Java programmer, so it's what I'm used to. It's worth checking out, and the extensions are quite cool.
Many people like Code::Blocks and it is cross-platform, with integrated debugging, code completion, etc. Qt Creator is also good and at least still very minimalistic.
Without a doubt VisualStudio with gnu make.
I've found Visual Studio to have the best IDE for C++. In addition, it's debugger and the way it handles multi-threaded applications is excellent.
And you can tweak the properties for your project to use different compilers and compiler flags of your choice, so it can build to any target.
You're talking about cross-compiling as GMan said, that's a compiler job, not IDE's and itu's kind of hard to make C++ software that runs well on Linux/Windows/MacOSX, C++ isn't a cross plataform language beacuse of its ABI, so you should try to use C++ standart code.
If you're making a consloe application there's no much problem just be care not to use system interface, but if you're planning to do some kind of graphics app then C++ it not the better choice for your purpose. Try some design that split the view from the controller/model of the app.
You can use QtCreator or NetBeans. First on C++ secord on Java. Both use MinGW g++.
Just a thought: you don't need to use a single IDE for all platforms. It is very common, for example, to use Visual Studio on Windows and Xcode on Mac OS X for cross-platform projects. I'm not familiar with Linux IDEs thought so couldn't recommend anything there.
Write makefiles for each OS? Simple enough seems to me.
Concerning cross plattform development it doesn't make a difference which IDE you use. Just make sure you use a cross platform (and possibly IDE independent) build system like SCons or cmake.

Setting up windows for C++

To quote the FAQ, 'No question is [...] too "newbie"'
What is the best way to set up an Windows system (vista, if that matters) to work with C++?
Preferably with a nice IDE, easy compiling of software (support for make files, etc.), but suitable for a beginner.
I would quite like the IDE to use a relatively portable format, such as makefiles and configure scripts, nothing too proprietary.
I would also like the ability to add new libraries etc. without much hassle, and work with the majority of C++ code others have written.
I am comfortable using the command line.
Thanks for the help, hopefully the question is clear. And apologies if it's already been answered, i did have a look for similar questions.
I know this is not exactly 'nothing to proprietary' but you should give a look at the free Express Edition of Visual C++. Under its covers you'll get all the familiar make and command line tools, but wrapped in a polished IDE.
If you're really comfortable with the command line then you can make an IDE from code editor on top of a compiler/debugger suite. MS's own command line tools come with the platform SDK (free) and you get an awesome debugger in Windbg. My personal favorite code editor is Code Insight. I wish so hard for a Mac version /sigh.
Microsoft's Visual Studio has a free express edition which contains pretty much everything you need to program c++.
For a Gui, the main choices are probably, MFC (old and ugly), CLR/.Net (new and confusing) or look at Qt(now LGPL) or wxWigets
There are quite a few good IDEs for C++ available on Windows.
The de-facto standard for professional software development is Microsoft's Visual Studio, which is available in different versions, like the free Express Editions. This will give you a great tool-chain for Windows development.
However, for a more "cross-platform" approach, you should have a look to the free Eclipse C++ Development Tooling, which is available for many platforms. As long as your own code is platform-independent, the whole project can be shared between Windows, Linux, Mac, etc.
Other alternatives are MinGW or CygWin that both allow to use the GCC toolchain on Windows.
Try the MinGW compiler, it will come with a C and C++ compiler, Make, etc--among many others. This can be used from the command line, pretty easily: g++ -o someprogram.exe somecode.cpp
As for an IDE, there are lots out there. Right now I am using Code::Blocks, and so far it's been really nice. As well, it already supports the GCC compiler, and sets many of the appropriate flags for you, so all you'll really need to do is hit the "build" button.
Some others you might want to try are Eclipse, which is really powerful, but lots of its "power" will be really confusing and difficult to use until you start getting used to it. Visual C++ is another one, which (obviously) would integrate very nicely into Windows. Of course, you could always use emacs :)
I suggest you evaluate CodeBlocks.
Microsoft's Visual Studio is powerful but rather proprietary. If you prefer open/portable stuff, I recommend Dev-C++ and Cygwin.
FWIW, I recently went through this and tried the VC++ Express and QT Creator based stuff. Coming from a linux/unix background I found that QT was a little better since it was using the Ming compilers and some make based constructs.
If you will only be hacking for windows I would go for Visual Studio. It will definitely save you time you can spend on coding instead. Most open source out there for windows either already have VC project, and if they don't it is usually very simple to set one up. And normally they have either make or nmake files for you to build VC compatible libararies to link with.

I'm starting my C++ learning, using CodeBlocks and windows, what compiler should I use?

I'm under the impression certain compilers only work for making windows applications.
If you want to develop GUI applications and/or go for maximum portability, go for MinGW for compiler, and Qt Creator for IDE (it comes with MinGW bundled).
If you want to stick to Windows, and don't mind coding UI directly using Win32 API, then Visual C++ Express would do the trick.
If you care about portability to Unix, use the mingw compilers which are based on gcc. Gcc is widely available on a lot of architectures and OS. If you only work for Windows, Visual Studio Express might be a better choice in comparison to Codeblocks.
How about Visual Studio Express? This is a complete package with a very nice IDE.
Codeblocks supports many compilers. I recommend using CB with mingw for general purpose usage.
Depends what you want to do. If you want to use POSIX APIs you may want to use mingw. If you distribute to Windows folks, you probably want to use Visual Studio since its compiler is usually better at producing optimized code.
CMake might be something you want to use if you want multiple platforms - it'll create your CodeBlocks/Eclipse/Visual Studio/GNU Make projects for you w/ all the correct settings.
If you are keen on using Codeblocks mingw is a good choice. But C++ is not like Java. It is not write once run everywhere. Also it is not write once compile on different platforms and run everywhere.
You have to change your code for different platforms (win/unix etc...) (eg: socket programming differs on Windows and Linux)
This means that you are not platform independent. So I recommend you to go for a better one. Eclipse is good, community is great but for me QT or Visual Studio (6.0 or 2008 for .Net) would be better.