packaging libraries in c++ - c++

I am a java developer for last four years . I am planning to develop an c++ application which uses the library like boost etc.
In java we can add the libraries in class path and export as single jar and distribute it .
I am not sure how to do this in c++ and more over i use ant for build too in java.
Do we have any build too like ant for c++.
What are the things we need to consider while developing an c++ application in terms for supporting different operating systems and some general things.
Do c++ have some thing like maven in java?

There is no such thing like Maven for C++. Dependency Management is usually done either by your operating system (Unix package manager like apt-get or yum) or by Hand (Windows ;)).
For multi platform environments I would recommend CMake as it can generate Project files for Visual Studio, Eclipse, XCode, Unix Makefiles etc. CMake can provide you with a lot of tool functions like find_package (XXXXX) which make life a lot easier.
IMHO the best way to learn it is to read documentation of your compiler, your build tool (e.g. CMake) and some sample code. Some keywords are 'static library', 'dynamic library' (like DLLs, 'linking'), include path. Start with something simple like a small program which uses Boost and maybe the CURL library and try to build it on multiple platforms.

Related

Build Tools vs Package Manager

I am very much confused between these two terms Build tools and Package Manager. According to my current knowledge, Package managers are the ones use to install dependencies required for the code to execute while Build tools are used to Package the code plus dependencies into single file i.e. building the code. Building our application will enable to make it production ready.
Am I right???
Short answer
Build systems/tools manage your compilation requirements.
Package managers/tools manager your library requirements.
A build tool may have integrated package management.
For example, in both C++ and Java you can directly call the compiler and provide all the include, source and library paths manually or you can use a build system (make/cmake... for c++, maven/gradle/ant... for java).
When you link external libraries with your build system it will do its best to find them in its search path, and will link with the first version that meets its requirements or tell you that it couldn't find it. Adding libraries manually is fairly easy, but sometimes each library you add will require another library with it.
A package manager would make sure that your libraries are downloaded, are the right version, and all the libraries they depend on are downloaded. some examples are maven and gradle which have integrated package managment for java, and conan is a fairly popular option to combine with cmake.
So ideally you would use both, but it can be more work setting them up than you save not doing things manually. It depends on your programming language, if you need multiple versions of something, and your OS.

Creating a clean isolated compile environment for Linux C++ builds

Trying to bring some more quality into our build system and porting software recently to Android made me think that i do want a clean build environment where i don't accidently use dependencies to libraries and include files i do not want.
Is there something like Androids "make_standalone_toolchain.py" script which just creates a clean directory structure and provides the linux system headers and base libraries (like defined in Linux Standard Base LSB) and C and C++ runtimes?
You might want to consider using a Docker container for it. I believe it will fully give you what you want since you'll have a clean Linux image.

How to manage and migrate C++ libraries?

I am learning C++, is there something like python-pip in C++? I am uing json/YAML packages in my 1st project, I want to know which is the correct way to manage dependencies in my project, and after I finished developing, which is the correct way to migrate dependencies to production environment?
C++ doesn't have a standard package manager or build system: this is one of the major pain points of the language. You have a few options:
Manually install dependencies when required.
Use your OS's package manager.
Adopt a third-party package manager such as conan.io.
None of the above solutions is perfect and dependency management will likely always require some more effort on your part compared to languages such as Python or Rust.
As far as I know, there is no central library management system in C++ similar to pip. You need to download and install the packages you need manually or through some package manager if your OS supports it.
As for managing multiple libraries in a C++ project, you could use CMAKE or something similar. If you link your libraries dynamically (i.e., though .dll or .so files), then you need to supply these dynamic library binaries along with your application. To find out which dll files may be needed, you could something like the Dependency Walker or ELF Library Viewer.
Personally, I use a development environment - specifically Qt (with the QtCreator), containing many of these components like qmake etc. - which simplifies the process of development and distribution.

C++ Build Process

I am currently working on an opensource C++ project. I don't have much experience in C++ as my daily job mainly involves with Java. I am now planning to release my C++ project and I would like to know how should I should I arrange the packaging of my project. E.g, in Java, all the class files are packaged into jar file. So what is the equivalent approach in C++? Is there any good practise for organizing the source code/binary? My target platform is Linux by the way.
Another question is I am currently using Eclipse CDT plugin for development and building. So is there anyway that I can extract build script from Eclipse project and use it as generic build script? Is there any good reference regarding C++ build/packaging? Thanks in advance.
Edited
To clarify a bit more, I think the release of my project can be considered as an application. It's a command line tool for software configuration management.
I am currently working on an opensource C++ project.
That simplifies many things. You should supply the build scripts for you project and support them for different use cases (learn about Makefiles, there are similar concepts like "target").
I don't have much experience in C++ as my daily job mainly involves with Java.
Most of the things you're used to have (and ask for right now) in Java are invented because they lack in C/C++. Learn at least something about dynamic(shared)/static libraries (.so and .a files to be simple).
I am now planning to release my C++ project and I would like to know how should I should I arrange the packaging of my project.
The "packaging of a C++ project" is something informal. You may supply the sources, build scripts and some project-files for the well-known IDEs.
EDIT: you've specified that you're building the command-line application. I believe all you need is to start from a simple Makfile for that application. The reference Makefile can be automatically generated by Eclipse. If you are planning to deploy your application as a stand-alone software, then you have to earn about packaging (rpm, deb, tgz).
E.g, in Java, all the class files are packaged into jar file.
There are no such thing as a C++ "package" compatible accross compilers (even the "modules" were rejected in the latest C++11 standard)
because there is no binary standard to encode C++ classes (ABI). On linux you're most likely going to use GCC (or Intel's compiler, or LLVM's CLang, or custom build of OpenWatcom or...),
but the version of standard library you are linking to makes the release of binary builds close to useless.
That is the reason for redistibuting source code.
So what is the equivalent approach in C++?
No clear answer here.
Is there any good practise for organizing the source code/binary?
Look at the large-scale projects, see the way they organize their builds. The term "build engineer" as an occupation emphasizes the difficulties of large-scale projects compilation/linking.
My target platform is Linux by the way.
This is also something of an incomplete description. "Linux" is a blurry term. You should speak about the Linux distribution, compiler toolchain and package manager. E.g., Ubuntu 12, amd64, GCC 4.6 toolchain, APT package manager.
There are different "linuxes" built around the same kernel source. There are different compilers. There are at least three major package managers to consider: Debian/Ubuntu(deb,apt), Red Hat(rpm), Slackware(tgz).
Another question is I am currently using Eclipse CDT plugin for development and building. So is there anyway that I can extract build script from Eclipse project
There's a sort of "meta-technique": you write a "description" of your project and then a tool generates the project-file and build scripts for your sources. Have a look at CMake. Since you're on "linux", try looking at the somewhat standard way of autotools (autoconf).
Is there any good reference regarding C++ build/packaging?
You should start by building your application and then move on to the deployment issues. C/C++ is a hard-to-learn legacy with a lot of subtleties which are avoided in Java.

How should a build environment look like for a cross-platform, multi-language library with external dependencies?

I'm researching into starting a small library with the following desired requirements:
builds natively on 3 platforms: Linux, Windows, OS X
has bindings for 3 dynamic languages: Python, Ruby, Lua
relies on code from external projects: clutter, cairo, pango
Is there a way to create a build environment that will somehow bypass the external libraries build system?
The naive use case would be to just download the library source code, have a script inside the source code download the dependencies' source code and patch things if need be, then just build everything in one command using the native environment (XCode on OS X, Visual Studio Express on Windows and GCC on Linux).
The final library should have all the dependencies statically linked.
What are my options? How should I best approach this?
Any tutorials or useful links are appreciated.
Thank you in advance! :)
I would take a look at http://jenkins-ci.org/ (formerly Hudson).
Its designed for continuous integration, but as a side effect have a tremendously flexible build job configuration engine that can invoke a variety of build tools.
It also has the concept of slave nodes and associating specific jobs with those nodes, so you can put together a sequence of build jobs that are associated with slave nodes on the appropriate OS's that use best of breed build tools for each language.