C++ fmt library installation is not working

6,652

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 using apt.

Run the following commands to install:

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

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:

apt-cache search libfmt

If you get too many results, you can pipe the command to grep to narrow the results like this:

apt-cache search libfmt | grep dev

or something like this:

apt-cache search fmt | grep 'C+'

or you can use the -i flag with grep so that it is not case sensitive like this:

apt-cache search fmt | grep -i 'c+'
Share:
6,652

Related videos on Youtube

Lucas
Author by

Lucas

I work as a Data Engineer at BD, an open-source project dedicated to building and maintaining a public Data Lake containing high-quality data from the Brazilian government. See my link-tree for more information: https://linktr.ee/lucascr91

Updated on September 18, 2022

Comments

  • Lucas
    Lucas over 1 year

    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?

    • Itakura
      Itakura over 4 years
      Have you tried #include "format.h" or #include "fmt/format.h"?
    • Lucas
      Lucas over 4 years
      I just tried #include "format.h" and #include "fmt/format.h". It didn't work
    • mchid
      mchid over 4 years
      Is there a reason you don't want to use the libfmt-dev package from apt? You need to enable the universe repository: sudo add-apt-repository universe
    • Lucas
      Lucas over 4 years
      I don't know about that. Where can I find it?
    • mchid
      mchid over 4 years
      You can run: sudo add-apt-repository universe and then: sudo apt update and then, sudo apt install libfmt-dev
    • Lucas
      Lucas over 4 years
      Thank you! I tried these commands but get the error Unable to locate package libfmt-dev. I'm trying to solve this now but your suggestion took me out of the black hole. Only one more question: apt is the standard way to install libraries in C++?
    • mchid
      mchid over 4 years
      @Hartnäckig Yes, 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 use apt to install stuff, everything usually "just works".
    • mchid
      mchid over 4 years
      @Hartnäckig One more thing that will help, you can also install 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.
  • Michel
    Michel about 4 years
    In header only mode, I get /usr/include/fmt/format.h:4007:11: fatal error: 'format.cc' file not found. So the install is incomplete it seems.
  • mchid
    mchid about 4 years
    @Michel apt-file search format.cc returns two packages. We usually need the packages with the "dev" suffix so my guess it that this will fix the error: sudo apt install libspdlog-dev The other package is c++-annotations but it looks like that one just has an example file.
  • mchid
    mchid about 4 years
    @Michel See this comment on how to install apt-file