I'm a new C++ user and I have been facing some problems to install external libraries in my programs. Currently, I'm trying to install the fmt library. I downloaded the repository content and unpack it. Then I add de sub-directory fmt
to usr/include/fmt
, which doesn't work. I also tried add fmt
to usr/local/include
, also without success. Here is a sample code and the respective error that returns:
#include <iostream>
#include <string>
#include <format.h> // I also tried include <fmt/format.h>
using namespace std;
int main(){
string s = fmt::format("{0}{1}{0}", "abra", "cad");
cout<< s<<endl;
return 0;
}
error:
stack.cpp:3:10: fatal error: format.h: No such file or directory
#include <format.h>
^~~~~~~~~~
compilation terminated
I note that the fmt
folder is "closed" (marked with a "X") after the command I use to transfer it to usr/~
using:
cp fmt-master/include/fmt usr/local/include/fmt
I tried to change the folder permissions using:
sudo chmod -rwx usr/local/include/fmt
But EVEN this didn't work. The command runs without output and fmt
folder continues with X mark.
I would like to know 1) Save the library folder in /usr/include
is the standard procedure to install external libraries in C++? (It looks too manual to me) 2) What am I doing wrong here?
Best Answer
Most packages and libs don't need to be manually downloaded and installed on Ubuntu. You can install
libfmt-dev
using the somewhat official "universe" repository usingapt
.Run the following commands to install:
Most of the "build" type packages in the Ubuntu repositories have the "dev" suffix at the end. 9 times out of 10, when you need to install some prerequisite or dependency to build stuff using g++ or C++, these will be the "lib" packages that you need.
To search for available packages, you can use the
apt-cache search
command like in this example:If you get too many results, you can pipe the command to
grep
to narrow the results like this:or something like this:
or you can use the
-i
flag withgrep
so that it is not case sensitive like this: