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?
#include "format.h"
or#include "fmt/format.h"
?#include "format.h"
and#include "fmt/format.h"
. It didn't worklibfmt-dev
package fromapt
? You need to enable the universe repository:sudo add-apt-repository universe
apt
is the standard way of installing pretty much everything on Ubuntu. I'm running 18.04. If it cannot find the package, try running all three commands again. When you useapt
to install stuff, everything usually "just works".apt-file
to help you find files that you need.sudo apt install apt-file
and then update it:sudo apt-file update
and then to search for the file:apt-file search /usr/include/fmt/format.h
This should show you what package contains the file.