Moving away from DevC++ to command line compiling - c++

I've inherited a large volume of C++ code for running & monitoring laboratory equipment. Currently the deployment is managed by compiling all of the individual modules (each it's own program) using DevC++, manually moving all the .exe files to a Dropbox folder, and then running them on the host machine manually.
I'm trying to automate this process somewhat to make rolling out an implementation on a new machine simpler and making sure the most up to date binaries are what is running on any given machine quickly. However, I don't know anything about deploying software in a Windows environment (I'm used to working on linux systems where a simple makefile would suffice) What tools (preferably command line) are available to compile & organize binaries in a portable way on windows systems?

Assume that you have a C++ compiler usable on the command line, on one translation unit. For example, GCC is such a compiler (and mingw is or contains a variant of GCC). Assume also that it is capable of linking (e.g. by driving the system linker).
Then you need to use some build automation tool to drive such compilation commands. For example GNU make or ninja (but there are many others). AFAIK they exist on Windows (so you could port your Makefile on Linux to Windows).
Once you have chosen your build automation tool, studied its documentation and understood how to use it, you'll write the relevant configuration file for it. For make, you'll write a Makefile (caveat : tab characters are significant). For ninja, you'll write some build.ninja files (but you'll probably generate it, perhaps with meson).
Notice that some build tools (e.g. cmake) are cross-platform.
BTW, DevC++ is an IDE, not a compiler.

Related

cmake vs waf for C++ project

I found similar topic: What are the differences between Autotools, Cmake and Scons? , but my question is a little bit other and I think the answers could be other too.
I found a lot of articles telling that waf is unstalbe (API changes), is not yet ready for production etc (but all of these articles are 2 or 3 years old).
Which of these build tools should be used if I want to:
create big C++ (11) project - lets say a complex compiler
use with LLVM
be sure it will be flexible and simple to use
be sure it will be fast enought
compile under all standard platforms (the base platform is Linux, but I want to compile under Windows and MacOSX also)
Reading a lot of articles I found out Cmake and waf the "best" tools available, but I have no expirence with them and it is really hard to find out any comparison, which is not very biased (like comparison of the scons author) and not very old.really
waf covers nearly all your requirements ...
API change: not a problem as waf shall be included in the source tarball (<100Ko)
big project: you can split your configuration in subdirectories (the contexts could be inherited). I've worked on projects with more than 10k files in C/C++/fortran77/fortran90/python/Cython including documentation in doxygen/sphinx.
flexibility and easyness: you can add extra modules en python (http://code.google.com/p/waf/wiki/AddingNewToolsToWaf)
fast: the tasks could be run in parallel: http://www.retropaganda.info/~bohan/work/psycle/branches/bohan/wonderbuild/benchmarks/time.xml
multi plat-form: you can run Waf everywhere python is available, that includes Windows and MacOs. Waf is compatible with mscvc, gcc, icc, and other compilers. You can produce visual/eclipse projects.
... but waf seems to have an issue with llvm: http://code.google.com/p/waf/issues/detail?id=1252
EDIT: as said by Wojciech Danilo, LLVM issue has been fixed
I'm currently using CMake for my own language implementation via C++11 and LLVM.
I like CMake for it's easy to use syntax. LLVM can be loaded with an easy 'load_package' command. After that you can use all the headers and libraries you need. CMake lets child scripts inherit variables from parent scripts. So you do not need to set variables and load packages in every sub directory.
The C++11 support depends on your compiler you want to use. All in all CMake is just a layout to create your 'real' build script.
When you're using make you can use make's --jobs=N to speed up compilation on multicore-platforms. On Windows you could generate Visual Studio 2012-project files and use Microsoft's build system and use their build-jobs to speed up the compilation process.
You should always create a subfolder for build-files (myproject/build or something). This way you keep your source tree clean (cd build; cmake ..; cd ..).
I can't speak for all the other tools out there.

What is MakeFile in Eclipse?

What is MakeFile in Eclipse? From the documentation:
A makefile is a text file that is referenced by the make command that
describes the building of targets, and contains information such as
source-level dependencies and build-order dependencies. The CDT can
generate a makefile for you, such projects are called Managed Make
projects. Some projects, known as Standard Make projects, allow you to
define your own makefile.
But the explanation does not help me understand what a MakeFile is. I am moving from VisualStudio/C# to Eclipse/C++. Is MakeFile analogous to Visual Studio's Metadata? When do I need to write a MakeFile, and why do I need it besides the C++ code?
[EDIT]
I used to develop on Windows with VS and C#. And now trying Eclipse/C++ on a Mac. I have never build anyone on Linux. So the answer I have read so far does not help explain anything at all.
A makefile in the simplest terms is a file that builds a program. These are normally used from the command line. If you have ever built something on linux you may have run ./configure ; make ; make install. You are using a makefile there.
More info...
https://en.wikipedia.org/wiki/Make_(software)
In simple terms: Make helps you create cross-platform configuration settings in one file, and it will work on surprisingly many platforms, including Windows or Mac OS-es.
Mentioning Windows, you should have Make installed on the computer you're installing on (on Windows, Cygwin and MinGW include Make). It's required only if the user will actually build the code from the source.
But of course, you should include Make code for each different platform (e.g. one for Unix-like, one for Windows, etc.)

Installation Script for simple c++ command-line tool, tutorial?

I'm working on a simple command line tool in c++. Half as a fun learning-process thing, and half to distribute to friends/colleagues etc.
I assume the easiest way to make it distributable is just packaging the source code with an installation script---can anyone point me to a good tutorial for setting that up?
In other words, what must a script include to compile the program, put the files in good places*, and make it executable from any directory from the command line?
E.g. I know the compiled binary should go in /usr/local/bin/ , but if I'm writing-to and accessing a text file (for instance), where should that go? What about a file that stores settings/configuration-parameters?
I'm on mac osx, so that would be the starting point, but portability to windows, linux, etc would be great.
You can use CMake to make a cross platform build system, and you can use it's CPack (Wiki here) feature in order to generate binary only packages. First you create a build script that runs and installs on each platform (which CMake makes as easy as can be expected). You then run CPack to generate a package which just includes your binaries.
There is a good tutorial that covers the basic cmake process (including install commands) here.
CMake is generally considered simpler then autoconf (and has better windows support), but each has it's own strengths.
Do not assume that the user installing the program has root access. Prompt, or provide a command-line option, like --install-prefix=/home/user/apps, to specify where to install.
I HATE programs that install shit in /usr/local. If you do that, you'd best wrap it up in an .rpm or .deb or whatever the platform package is so that your app can be cleanly uninstalled.
I would suggest checking out autoconf

How to prepare a codebase for compiling on both Windows and Unix-based systems

I am wondering about different solutions to easily compile my cross-platform application for both windows and unix.
Right now I am using a makefile on Ubuntu, but before my codebase grows larger I'd like to perform the steps necessary to compile it on Windows, and then continue doing so regularly to see that it still works.
I'd preferably not contaminate my SVN codebase repository with multiple "makefile" solutions, such as VC++ solutions and so on, I'd like a more automatic way. I tried using mingw with make for windows, but it seems my secondexpansion awesomeness doesn't work on the Windows version (or something like that). It wouldn't compile, and also complained about _winNT or something like that not being defined.
How should I prepare my codebase for cross-platform easy compiling? Things like buildtools, perhaps autogenerate VS file from makefile, or something similar. Some preprocessor magic in a stdinc file perhaps?
Thanks!
I will point you to CMake which is used by high-profile projects, such as MySQL, KDE, or Compiz.
It has the ability to generate native build files for the target system, such as Makefiles for Unix-based platforms, and Visual C++ project and solution files for Windows.
In order to deal with platform differences, I invite you to see my previous post on this subject: C++: Platform dependent types - best pattern
I would go for boost build: http://www.boost.org/doc/tools/build/doc/html/index.html
You can choose your platform and your compiler from the command line (dos command prompt on Windows) and everything else works.
e.g
bjam release gcc,
or
bjam debug msvc
You can add extra flags for each compiler (if you so wish) or different versions of the compiler.

How are open source projects in C/C++ carried out exactly without .sln/.project files?

Seems most open source projects in C/C++ only provide the source code,i.e. nginx
Is this a convention that anyone interested in joining the developing team should figure out the .sln/.project files himself to qualify??
most open source projects are coming from the linux side of computing. thus, they are mainly using unix style build tools, as well as open source compilers.
the main build tool is make, which uses a makefile to know how to build a project. on Windows, the main open source compiler is MinGW which is a win32 port of gcc. the use of those tools allows to keep a maximum of common things between unix and windows.
note that .sln files are specific to microsoft compilers which are not free to use (and are rather costly), they are not portable and so are not suitable for multi-platform programming.
Some projects use CMake, which can generate project files for Your Favourite Build System, but as mentioned above, you don't need to use .sln and pro files, even if a project is built with the MSVC compiler, MinGW + makefiles, or scons, or CMake, or any other number of scripty methods to invoke the right commands to compile the program will work just fine.
Don't confuse the IDE with the compiler!
No, most opensource project do not use MSVC solutions as they not portable and very weak in terms of features.
In most cases they use what is called "build-system" like autotools, CMake or SCons.
These build systems include information about:
source code and how to build it
various system checks that should be done (like find various 3rd part libraries)
How to build and run unit-tests
How to install application
They also allow important tasks like cross compilation and packaging for deploy.
These task done via specific build system scripting language that allow you big flexibility.
So, these build systems generally much more powerful then typical "project files" and they
generally work with multiple compilers on different platforms and operating systems.
Some of build systems (like CMake) allow as one of the options to generate MSVC solutions as well as one of optional ways to build application.