[英]Where does Homebrew install C++ packages?
我想使用 C++ 的std::format
庫來格式化字符串。 請參閱下面的最小工作示例。
/* example.cpp */
#include <iostream>
#include <format>
#include <string>
int main() {
std::string s = std::format("Hello, {}!", "John");
std::cout << s << std::endl;
return 0;
}
但是,當我編譯我的代碼時,我收到以下錯誤消息:
example.cpp:2:10: fatal error: format: No such file or directory
2 | #include <format>
我使用的是最新版本的 macOS,並且我安裝了 Homebrew 作為我的 package 管理器。 我已經通過 Homebrew 安裝了clang-format
,但由於某種原因,我的編譯器找不到 header 文件。 有人可以幫我找出問題所在嗎? 我曾嘗試使用 Apple 的 GCC 和 Homebrew 提供的自定義 GCC10,但在這兩種情況下,我都會收到相同的錯誤消息。 這是 Homebrew 問題還是 C++ 問題?
按照this answer to use fmt,您可以使用brew install fmt
安裝庫,然后將代碼修改為
/* example.cpp */
#include "fmt/format.h"
#include <iostream>
#include <string>
int main() {
std::string s = fmt::format("Hello, {}!", "John");
std::cout << s << std::endl;
return 0;
}
並編譯
clang++ -std=c++11 test.cpp -lfmt
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.