How to install C++ modules

Asked

Viewed 85 times

0

I would like to know how to install new modules in C++. For example, I recently discovered that there is a module that has an application of the method format of strings very similar to the method of the same name in python (here the link for the module). It turns out that I have not been successful in importing this module. Below is a replicable example of my error:

#include <iostream> //Já tem
#include <string> // Já tem
#include <fmt/format.h> // Preciso instalar. Como??

using namespace std;

int main(){
   string firstname = "Carlos";
   string secondname = "Drummond";
   string thirdname = "de Andrade";

   cout<<fmt::format("{} {} {} foi um grande poeta nascido em Itabira ", firstname, secondname, thirdname)<< endl;
   return 0;
}

I searched a little and saw that for these external modules to work I need to have on my computer a folder with extension files lib and h. It seems that these files are in the module repository on Github, so I downloaded all the files from the repository and tried to run the program, but I was unsuccessful. So I have two doubts:

  1. I need to specify the path for the module to be activated? If so, how do I do this?
  2. There is a less "manual" way of doing this (in other words, there is something similar to the pip install python?
  • Ever tried to do an env on linux, and see if sudo apt?

  • env you say is a virtual environment'? In relation to sudo apt you are asking if there is a way to install with this command? Well, I searched and did not find a sudo apt for this package. But this is usually how it is done? As if I were installing any program on my PC?

1 answer

0

Most packages and libraries do not need to be downloaded and installed manually on Ubuntu. You can install libfmt-dev using the official "Universe" repository, using apt.

Run the following commands to install:

sudo add-apt-repository universe
sudo apt update
sudo apt install libfmt-dev

Most "build" packages in Ubuntu repositories have the suffix "dev" at the end. 9 out of 10 times, when you need to install some prerequisite or dependency to create things using g++ or C++, these will be the necessary "lib" packages.

To search for available packages, you can use the command apt-cache search as in this example:

apt-cache search libfmt

If you get many results, you can filter the search using the command grep:

apt-cache search libfmt | grep dev

or:

apt-cache search fmt | grep 'C+'

or you can use the flag -i with grep so that it does not distinguish between upper and lower case so:

apt-cache search fmt | grep -i 'c+'

IMPORTANT: This answer is a free translation of a solution obtained by the author of the question in Ask.ubuntu. The original version can be seen in that link. I chose to post the translation to provide a material in Portuguese so that someone without the the English language may have access to the material if there is a problem similar. If this procedure violates the rules and conventions of the site in any way, please inform me that I delete the question.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.