Auto packgaing for applications in linux - c

It's my first time to try to get a distributed version of an application, I have a simple C application that uses GTK3 lib , when i compile this application and try to run the executable file on another Linux system that hasn't GTK lib installed of course it doesn't work !!
Is there a known and easy packaging method to get an executable file that works fine when distributed ?
Or i need to make my application installs needed libs to work and if so what is the best way to do this too ?
Note: i don't need a cross platform solution, i just want to run the application on another Linux system that hasn't GTK lib installed

In short: either you build in static or you do a package with the required dependencies.
The second solution is what I would recommend. You don't need to depend on the development files but only the library. Have a look to the documentation of your distribution in order to understand how to build a package.

Related

Cross-compiling Azure IoT SDK for C

I have successfully managed to cross-compile the C Azure IoT SDK for a target device running embedded Linux. The instructions are here : https://github.com/Azure/azure-iot-sdk-c/blob/master/doc/SDK_cross_compile_example.md
The next step is to get a basic application using the SDK running on the target device.
How would one go about doing this? Where are the generated libraries etc. to copy to the sysroot of the target device.
There seems to be only support for Rasberry Pi and generating a new firmware image.
I would recommend that you use the -DCMAKE_INSTALL_PREFIX=[output path] when you generate your makefiles. Once you have run cmake and make you can then run make install which will copy the generated libraries to the location you chose. You do NOT want to install them into your host's library search path since (presumably) they are built for an incompatible architecture. Having done that the /lib directory will have the libraries that you need to use to build your application. These are static libraries (unless you chose otherwise) so they only need to be linked to your application. They do not need to be on the device. Obviously you will also need to cross compile your application.
There are a couple of things you need to look out for though. Your device will need to have the same version of OpenSSL and curl that you used when you built the SDK. These are dynamic libraries so your application would likely fail at run time if you don't take care of that since there would be a version mismatch.
There is another example of cross-compiling here: https://github.com/Azure/azure-iot-sdk-c/blob/master/doc/Docker_SDK_Cross_Compile.md. This version also builds the prerequisite libraries and has suggestions about how you might also cross compile your application. It uses a Docker container to do this but, even if you don't want to use Docker, it may still help you with your process.

Installing a 3rd-party libraries to use in my C program

I'm very new to C programming and I'm trying to understand what is the "idiomatic way" to install a 3rd-part library that I'm planning to use in my project.
In the JVM world I came from we have a public repositories and a build system does all the dependency downloading for us. Is it the way to go when it comes to developing native application in C?
In my particular case it is libcurl and I want to make sure it is installed correctly. As a build system I use Make (not CMake).
Would it be correct to add a specific target (e.g. bootstrap which is to setup all the necessary dependencies) for that?
I'm strictly speaking not sure if such a "dependencies-installation" is a Makefile responsibility.
When you build on Linux using the autotools it will check if the given library is present on the System. If it is missing the configure will stop and notice the user. The user then has the Chance to install the Software library with the system's repository.
Same with cmake where you can define the dependency and when trying to build with the missing library, cmake will notify you.
This is somewhat different than e.g. Maven in the Java world which automatically downloads the dependencies. This is not the case with make or cmake.
If you are under the Linux that this might be helpful. There is a canonical way. This is “autotools”. It provides you with possibility to write some script to check that library exists and then use it. I’m not much familiar with this process, but it’s pretty configurable and you can find dozens of examples and tutorials regarding “autotools”. So, if this is a case of yours, I suggest you to check that.
In my experience, I always used CMake.

How to automatically find or build C library dependencies on Windows/MSVC?

I have a tool in C that needs libpng, zlib and lcms libraries. On unix I get these dependencies via pkg-config, but on Windows I can't rely on it, so for users building the library it's a massive hassle to obtain and build these dependencies manually.
How can I automate obtaining these dependencies in the most Windows-native way? I know MinGW helps, but that's a bit of a cop-out. I'd like to learn how to do it with the Microsoft toolchain.
Is there any point in searching for shared non-Microsoft libraries on Windows, or should I go straight for statically linking my own?
If I were to download and build the libraries as part of my build script, what should I use? (nuget? curl? ftp.exe?)
It seems like Microsoft is discouraging use of NuGet for C? https://github.com/Microsoft/vcpkg/blob/master/docs/about/faq.md#why-not-nuget
I recommend looking into Nuget. It's fast becoming the Microsoft standard for these sort of things. A lot of people think Nuget is just for .NET, but it works great for VC++ too. I have had a great deal of success setting up Nuget servers in my company to serve headers and compiled libs, and I've gotten all of our automated build systems to create these things automatically. I'm not going to spell out all the details here, but it basically comes down to performing your build, creating an MSBuild XML snippet to set up the precompiler and link options automatically, and then packaging all those bits (headers, libs, XML) in the correct way. When done correctly, it's just a two step process to use an existing package in a new project -- establish the Nuget reference and then add the #includes into your code. You don't even need a server -- you can source them directly from a directory of your own control.
https://learn.microsoft.com/en-us/nuget/create-packages/native-packages

How to build Qt-5 application in Windows with no dependencies

I'd like to know the definitive method of building a Qt 5 application on Windows such that no dependencies whatsoever are required to run it, in particular the C runtime. I want to be able to distribute the final .exe with no prerequisite software/DLLs required. In particular, I want to avoid requiring my users to have to install vcredist.exe for MSVC*.dll or the MinGW redistributables.
I'll happily use either of the compilation environments (MinGW or MSVC), and will rebuild Qt from source if that is a necessary step (though I'd like to know if it is indeed necessary).
You have to static build the code. Chech this link explaining step by step method to build your code statically. http://qt-project.org/wiki/How-to-build-a-static-Qt-for-Windows-MinGW#9731f56412bd237286d3271405d55fd2

Create a self-contained project with external libraries

Hey guys,
I want to create a self-contained C project to be machine-independent.
An example? I want to "make all" my project on a machine where external libraries are not installed (but included in my project) and I want all keep working :)
The library I'm talking about is the GSL, you can find it in the libgsl0-dev ubuntu package.
Now, I want to include all the header and .c files in my project, uninstall the packages and the project must build and run as before :)
Ideas?
Thanks!
Bye!
Don't forget about dependencies.
There are reasons why libraries like GSL are distributed as independant entities:
Users can upgrade the library independantly of the software that uses it saving you from having to constantly update your project when the GSL version changes.
Licensing issues.
Dependancies. If GSL has dependencies and you want to build GSL as part of your project then you will also need to include ALL the source code for ALL dependencies...and their dependencies...and their dependencies...and so on and so on. If you are going to make it a requirement that some sub-dependency need to already be installed then you may as well make it a requirement that GSL is already installed.
Other reasons I can't be bothered to think up because I have other things to do.
Just copy the library's source code somewhere into your project's hierarchy, and start either creating or modifying Makefiles (or whatever GSL uses) to get it to build.
For instance, you could have it in a directory external/libgsl, and then set up a Makefile target for your project that does the building. Then you make your project's code dependent on the library's, so that the library is always built first.
Of course, you also need to think about any license issues that might arise if/when you distribute your project.

Resources