使用brew安装fmt和gcc编译器后,为什么找不到fmt库? [英] Why is fmt library not found after installing fmt and gcc compiler with brew?

查看:375
本文介绍了使用brew安装fmt和gcc编译器后,为什么找不到fmt库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是MACOS Mojave版本10.14.3,需要使用GNU编译器而不是clang.

I am using MACOS Mojave version 10.14.3 and need to use GNU compiler and not clang.

我使用brew install gcc安装了gcc编译器. 然后我使用brew install fmt安装了fmt库.

I installed gcc compiler using brew install gcc. Then I installed fmt library using brew install fmt.

我将#include <fmt/format.h>放在C ++脚本的顶部

I put #include <fmt/format.h> at the top of my C++ script

然后我输入:

/usr/local/bin/g++-8 -O0 -g3 -Wall -c -fmessage-length=0 -std=c++17 -MMD -MP -MF"src/trail2.d" -MT"src/trail2.o" -o "src/trail2.o" "../src/trail2.cpp"

但是我收到此错误:

fatal error: fmt/format.h: No such file or directory

当我尝试使用Boost库时也会发生同样的事情.

Same happens when I try using the boost library.

当我使用clang时,发现fmt和boost没有问题.

When I use clang, fmt and boost are found without problem.

以防万一,我正在为C/C ++开发人员使用Eclipse IDE.版本:2018-12(4.10.0).

Just in case I am using Eclipse IDE for C/C++ Developers. Version: 2018-12 (4.10.0).

具体来说,如何使fmt库与在brew中安装的gcc一起使用?

To be specific, how can I get fmt library to work with the gcc I installed with brew?

我在Mac的/usr/local/Cellar中拥有的是:

What I have in my Mac at /usr/local/Cellar is:

drwxr-xr-x   3 aaa  staff    96 Feb 22 22:07 gcc
drwxr-xr-x   3 aaa  staff    96 Feb 23 01:58 fmt

我在Mac的/usr/local/Cellar中拥有的是:

What I have in my Mac at /usr/local/Cellar is:

    lrwxr-xr-x    1 aaa  admin        29 Feb 22 22:07 c++-8 -> ../Cellar/gcc/8.2.0/bin/c++-8
    lrwxr-xr-x    1 aaa  admin        29 Feb 22 22:07 cpp-8 -> ../Cellar/gcc/8.2.0/bin/cpp-8
    lrwxr-xr-x    1 aaa  admin        29 Feb 22 22:07 g++-8 -> ../Cellar/gcc/8.2.0/bin/g++-8
    lrwxr-xr-x    1 aaa  admin        29 Feb 22 22:07 gcc-8 -> ../Cellar/gcc/8.2.0/bin/gcc-8

感谢高级帮助

推荐答案

自制软件的工作方式是将所有内容放入

The way homebrew works is that it puts everything in

/usr/local/Cellar/PACKAGE-NAME/PACKAGE-VERSION

,然后为/usr/local/bin中的二进制文件创建到这些东西的链接,例如

and then it creates links to those things for binaries in /usr/local/bin, e.g.

/usr/local/bin/grep -> /usr/local/Cellar/grep/4.17/bin/grep

,因此您只需要将/usr/local/bin放入PATH中,所有自制软件程序都可以按名称运行,例如在上面的示例中为grep.

so that you just need to put /usr/local/bin in your PATH and all homebrew programs will be runnable by name, e.g. grep in the above example.

它执行相同的编译操作,将实际的标头和库放入:

It does the same thing for compiling, it puts the actual headers and libraries in:

/usr/local/Cellar/PACKAGE-NAME/PACKAGE-VERSION/include
/usr/local/Cellar/PACKAGE-NAME/PACKAGE-VERSION/lib

,还创建指向其中的链接

and also creates links to those in

/usr/local/include
/usr/local/lib

因此,您的gcc命令将是:

g++-8 -I /usr/local/include -L /usr/local/lib -lfmt <PROGRAM.CPP> -o <PROGRAM>


您可以查看哪些文件属于您的fmt软件包以及它们的位置:


You can see what files belong to your fmt package and where they are with:

brew ls fmt --verbose


如果您安装pkg-config,请使用:


If you install pkg-config, using:

brew install pkg-config

它将使用文件fmt.pc,并且如果您键入以下内容,则可以告诉您正确的编译开关:

it will use the file fmt.pc and can tell you the correct switches for compiling if you type:

pkg-config --libs --cflags fmt

示例输出

-I/usr/local/Cellar/fmt/5.3.0/include -L/usr/local/Cellar/fmt/5.3.0/lib -lfmt

这意味着您可以将gcc命令简化为:

That means you can simplify your gcc command to:

g++-8 $(pkg-config --libs --cflags fmt) <PROGRAM.CPP> -o <PROGRAM>

这篇关于使用brew安装fmt和gcc编译器后,为什么找不到fmt库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆