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.
Related
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
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
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.
I'm a bit naive when it comes to application development in C. I've been writing a lot of code for a programming language I'm working on and I want to include stuff from ICU (for internationalization and unicode support).
The problem is, I'm just not sure if there are any conventions for including a third party library. for something like readline where lots of systems are probably going to have it installed already, it's safe to just link to it (I think). But what about if I wanted to include a version of the library in my own code? Is this common or am I thinking about this all wrong?
If your code requires 3rd party libraries, you need to check for them before you build. On Linux, at least with open-source, the canonical way to do this is to use Autotools to write a configure script that looks for both the presence of libraries and how to use them. Thankfully this is pretty automated and there are tons of examples. Basically you write a configure.ac (and/or a Makefile.am) which are the source files for autoconf and automake respectively. They're transformed into configure and Makefile.in, and ./configure conditionally builds the Makefile with any configure-time options you specify.
Note that this is really only for Linux. I guess the canonical way to do it on Windows is with a project file for an IDE...
If it is a .lib and it has no runtime linked libraries it gets complied into you code. If you need to link to dynamic libraries you will have to assure they are there provide a installer or point the user to where they can obtain them.
If you are talking about shipping your software off to end users and are worried about dependencies - you have to provide them correct packages/installers that include the dependencies needed to run your software, or otherwise make sure the user can get them (subject to local laws, export laws, etc, etc, etc, but that's all about licensing).
You could build your software and statically link in ICU and whatever else you use, or you can ship your software and the ICU shared libraries.
It depends on the OS you're targeting. For Linux and Unix system, you will typically see dynamic linking, so the application will use the library that is already installed on the system. If you do this, that means it's up to the user to obtain the library if they don't already have it. Package managers in Linux will do this for you if you package your application in the distro's package format.
On Windows you typically see static linking, which means the application bundles the library and it will use that specific version. many different applications may use the same library but include their own version. So you can have many copies of the library floating around on your system.
The problem with shipping a copy of the library with your code is that you don't get the benefit of the library's maintainers' bug fixes for free. Obscure, small, and unsupported libraries are generally worth linking statically. Otherwise I'd just add the dependency and ensure that whatever packages you ship indicate it appropriately.
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.