How to install library in linux

Where do I put third-party libraries to set up a C++ Linux development environment?

I’m not new in C++ although I’m new in Linux. I’m using CMake to precompile a cross-platform game engine with some third-party components, but I have a lot of doubts about using libraries. My question is how to work with third-party libraries and where to put them. Apt installs libs in their official place (/usr/local, /usr/lib/ ..) but I develop in Windows using local libs that are in a folder in my project dir. Also, I need a good tutorial to know the rules of how libraries work. For example: when trying to compile my project, luabind is asking for liblua.s0.1, but AFAIK there is no way to generate this library with the source provided by Lua (at least doing make, make install). I know, this question is fuzzy but I haven’t enough experience to be more concise. Update: After reading some answers, a more concise question is the following. If I install all third-party libraries, how can I distribute my program? How do I manage dependencies without using a large readme?

4 Answers 4

Where to put libraries

The best solution is to use your Linux distribution’s packaging system ( apt-get , yum , or similar) to install libraries from distro-provided packages wherever possible.

If the distro’s packaged libraries aren’t of a recent enough version, or if you need some nonstandard build options, or if you need a library that your distro doesn’t provide, then you can build and install it yourself. You have two main options for where to put the library:

  • /usr/local (libraries under /usr/local/lib , headers under /usr/local/include ). This installs the libraries systemwide and is probably the simplest solution, since you should then be able to build against them without taking any extra steps. Do NOT install libraries directly under /usr , since that will interfere with your distro’s packaging system.
  • Under your project directory, as you did under Windows. This has the advantages of not requiring root access and not making systemwide changes, but you’ll have to update your project’s include paths and library paths, and you’ll have to put any shared library files someplace where the dynamic linker can find them (using LD_LIBRARY_PATH or ld.so.conf — see the link for more details).

How libraries work

See David A. Wheeler’s excellent Programming Library HOWTO. I’d recommend reading that then posting any specific questions as new topics.

Читайте также:  Run docker windows container on linux

How to distribute your program

Traditionally, Unix / Linux programs do not include copies of their dependencies. It’s instead up to the end user or developer to install those dependencies themselves. This can require a «large README,» as you said, but it has a few advantages:

  • Development libraries can be installed, managed, and updated via the distro’s package manager, instead of each source copy having its own set of libraries to track.
  • There’s only one copy of any given library on a system, so there’s only one place that needs updating if, for example, a security flaw is found. (For example, consider the chaos that resulted when zlib, a very widely used compression library, was found to have a security flaw, so every application that included an affected version needed to be updated.)
  • If your program is popular enough (and is open source or at least freely available), then package maintainers for various Linux distributions may want to package it and include it in their distro. Package maintainers really don’t like bundled libraries. See, for example, Fedora’s page on the topic.

If you’re distributing your program to end users, you may want to consider offering a package ( .dpkg or .rpm ) that they could simply download and install without having to use source. Ideally, from the end user’s perspective, the package would be added to distros’ repositories (if it’s open source or at least freely available) so that users can download it using their package managers ( apt-get or yum ). This can all get complicated, because of the large number of Linux distros out there, but a Debian/Ubuntu compatible .dpkg and a Red Hat/CentOS/Fedora-compatible .rpm should cover a good percentage of end users. Building packages isn’t too hard, and there are good howtos online.

Источник

How do I install the Linux library libc.so.6 [SOLVED]

Libc is a C library. Libc6 and glibc are the same version of libc. Libc6 is version 6 of the linux C Library and version 2 of the GNU C Library Many applications on Linux need this library.

On Red Hat based systems, this library is called glibc , while on Debian base systems it is called libc6 . In case this library is missing or not installed, then it possible you may face compilation related errors such as » library libc.so.6 not found or missing or no such file or directory «

There are 3 possible scenarios

  1. Library is not installed or missing
  2. The library path is not configured so the application is unable to locate the library file
  3. Library is installed for wrong ARCH i.e. your application may require 64-bit library but 32-bit library is installed

Scenario-1: How do I install the library libc.so.6?

Locate the package name of the library

First you need to know the package name required to install this library.

Читайте также:  Linux windows style desktop

On Red Hat based systems you can use yum or dnf command. From the below output now you know the rpm responsible for installing 32-bit and 64-bit library.

~]# yum whatprovides */libc.so.6 glibc-2.28-151.el8.x86_64 : The GNU libc libraries Repo : @System Matched from: Filename : /lib64/libc.so.6 glibc-2.28-164.el8.i686 : The GNU libc libraries Repo : baseos Matched from: Filename : /lib/libc.so.6 glibc-2.28-164.el8.x86_64 : The GNU libc libraries Repo : baseos Matched from: Filename : /lib64/libc.so.6

On Ubuntu based distributions, there are multiple command line options as shown below:

$ sudo dpkg -S libc.so.6 libc6:amd64: /lib/x86_64-linux-gnu/libc.so.6
deepak@ubuntu:~$ sudo apt-file find libc.so.6 libc6: /lib/x86_64-linux-gnu/libc.so.6 libc6-amd64-cross: /usr/x86_64-linux-gnu/lib/libc.so.6 libc6-amd64-i386-cross: /usr/i686-linux-gnu/lib64/libc.so.6 libc6-amd64-x32-cross: /usr/x86_64-linux-gnux32/lib64/libc.so.6 libc6-arm64-cross: /usr/aarch64-linux-gnu/lib/libc.so.6 libc6-armel-cross: /usr/arm-linux-gnueabi/lib/libc.so.6 . libc6-x32-amd64-cross: /usr/x86_64-linux-gnu/libx32/libc.so.6 libc6-x32-cross: /usr/x86_64-linux-gnux32/lib/libc.so.6 libc6-x32-i386-cross: /usr/i686-linux-gnu/libx32/libc.so.6 libc6.1-alpha-cross: /usr/alpha-linux-gnu/lib/libc.so.6.1 

or you can login to https://packages.ubuntu.com/ and search for your package:

How do I install the Linux library libc.so.6 [SOLVED]

Install the missing library on Red Hat Linux

Now that you know the package to be installed, go ahead and install it using package manager based on your distribution:

Installation for 64-bit

You can check the existence of the package on your system with the following command;

foc@fedora:~$ dnf list installed | grep glibc glibc.x86_64 2.34-35.fc35 @updates glibc-all-langpacks.x86_64 2.34-35.fc35 @updates glibc-common.x86_64 2.34-35.fc35 @updates glibc-devel.x86_64 2.34-35.fc35 @updates

If the package is not installed on your system, run the following commands in the terminal;

foc@fedora:~$ sudo dnf install glibc

The following command is sufficient to learn the location of the library after installation;

foc@fedora:~$ whereis libc.so.6 libc.so.6: /usr/lib64/libc.so.6

Installation for 32-bit

If your operating system is built on a 32 architecture or if the application you want to install requires 32 bit libraries, the following package should be installed;

foc@fedora:~$ sudo dnf install glibc.i686

Now let’s look at the locations of the glibc library again;

foc@fedora:~$ whereis libc.so.6 libc.so.6: /usr/lib/libc.so.6 /usr/lib64/libc.so.6

Now since we installed both 32-bit and 64-bit version of the library so it can be found under both /usr/lib and /usr/lib64 .

Install the missing library on Debian Linux

Installation for 64-bit

Package control is provided in Debian-based system with the following commands;

foc@foc:~$ dpkg -l | grep libc6 ii libc6:amd64 2.31-13+deb11u3 amd64 GNU C Library: Shared libraries ii libc6-dbg:amd64 2.31-13+deb11u3 amd64 GNU C Library: detached debugging symbols ii libc6-dev:amd64 2.31-13+deb11u3 amd64 GNU C Library: Development Libraries and Header Files 

To install the 64-bit package;

foc@foc:~$ sudo apt install libc6

After this command, if the package is not installed, the installation starts with its dependencies.

Most distributions have this already installed. After these commands, the update information of the installed package is also learned. If it is in the old version, it will be upgraded.

To find out the location of the library, run the command below;

foc@foc:~$ whereis libc.so.6 libc.so: /usr/lib/x86_64-linux-gnu/libc.so /usr/lib/x86_64-linux-gnu/libc.so.6

Installation for 32-bit

To install the 32-bit package;

foc@foc:/$ sudo apt install libc6-i386

After package installation, the lib32 directory was created under the root directory (/);

foc@foc:/$ ls -la /lib32/libc.so.6 lrwxrwxrwx 1 root root 12 Mar 18 00:37 /lib32/libc.so.6 -> libc-2.31.so

Scenario-2: Library is installed but LD_LIBRARY_PATH not configured

Many software packages look out for LD_LIBRARY_PATH environment variable to search for shared libraries. Many times you will just copy the required library path to /usr/lib or any other path but then your application will not start consuming the library just because the file is there.

Читайте также:  Jbead windows macos linux

We need to use ldconfig [options] lib_dirs which will update the ld.so cache file with shared libraries specified on the command line in lib_dirs , in trusted directories /usr/lib and /lib , and in the directories found in /etc/ld.so.conf .

Once you have copied your library file to /usr/lib then just execute

ldconfig creates the necessary links and cache to the most recent shared libraries found in the directories specified on the command line, in the file /etc/ld.so.conf , and in the trusted directories ( /lib and /usr/lib ).

Next you need to append this path to LD_LIBRARY_PATH variable:

For non-persistent changes you can use export command which will be applicable only for your terminal

# export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib:/usr/local/lib

For permanent changes you can place the above command in .bash_profile of individual user or just create a file inside /etc/profile.d/set-library-path.sh and add the above command. You can use any file name, set-library-path.sh is just an example.

Scenario-3: Proper library not installed as per your release version

It is possible that in your Linux box you are using both set of rpms i.e. 32-bit and 64-bit wherein the installed library package is 32-bit but your application package is looking for 64-bit library adn hence failing.

This I have already covered in Scenario-1 example on how to download and install packages for both 64-bit and 32-bit Linux environment.

Summary

We have explained the installation steps above. To remove packages, please pay attention to the following steps;

  • After the removal of i386 architecture packages, your applications with 32-bit library dependencies will be affected. Take this into consideration.
  • On a 64-bit architecture system, 32-bit libraries can cause confusion later, it is not recommended to install them. You should choose the 64-bit architecture compatible version of the application you want to use.
  • It is not recommended to uninstall these packages on a 64-architecture system. If you try to uninstall, you will encounter the following warning;
You are about to do something potentially harmful. To continue type in the phrase 'Yes, do as I say!' ?]

Think twice before removing it.

Didn’t find what you were looking for? Perform a quick search across GoLinuxCloud

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can either use the comments section or contact me form.

Thank You for your support!!

Источник

Оцените статью
Adblock
detector