Using the fmt library is problematic
-
Hello!
First steps in C++ (with Qt Creator as IDE) are disappointing.
The book states that if "format" is absent (Apple clang version 15.0.0), it can be replaced by the "fmt" library available at this address:
https://github.com/fmtlib/fmtUnfortunately, none of the tests are conclusive regarding the integration of this component into the structure of the project file.
With this simple code...#include <iostream> #include "fmt-master/include/fmt/format.h" using namespace std; using namespace fmt; int main() { string theCar{"My car"}; int price{10000}; cout << format("{} costs {} USD\n", theCar, price); return 0; }
...I get these error messages:
*By not providing "Findfmt.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "fmt", but CMake did not find one. Could not find a package configuration file provided by "fmt" with any of the following names: fmtConfig.cmake fmt-config.cmake Add the installation prefix of "fmt" to CMAKE_PREFIX_PATH or set "fmt_DIR" to a directory containing one of the above files. If "fmt" provides a separate development package or SDK, be sure it has been installed.
Included header format.h is not used directly (fix available)*
Can anyone explain to me how to use "fmt"?
Sorry for not understanding...
Thanks for your help.CMakeLists.txt is set as follows:
cmake_minimum_required(VERSION 3.14) project(fmt_B LANGUAGES CXX) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core) add_executable(fmt_B main.cpp fmt.cc format.cc os.cc ) find_package(fmt REQUIRED) target_link_libraries(fmt_B/fmt-master/include/fmt Qt${QT_VERSION_MAJOR}::Core) include(GNUInstallDirs) install(TARGETS fmt_B LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )
-
Hi,
Are you following these instructions ?
-
The fmt library also has a header-only mode. It is enabled by providing a define
FMT_HEADER_ONLY
. In this case you don't need to link to the fmt library anymore. The only requirement is then to have the path to the headers in your search path. (BTW, if everything is set up correctly, you most likely have to just write#include "fmt/format.h"
. The path up to this point should be set up differently.)