Hi guys I'm a C++ beginner and I just found that the fmt lib is really interesting. But I ran into a problem when trying to use it. I used homebrew to install fmt lib brew install fmt
.I check the fmt installation using apt-file search /usr/include/fmt/format.
and it then returned libfmt-dev: /usr/include/fmt/format.h
.I tried to build a sample project to test it as follows:
#include <fmt/format.h>
int main() {
fmt::print("The answer is {}.\n", 42);
}
After I tried to complie it with gcc11 it returned
/home/linuxbrew/.linuxbrew/bin/ld: /tmp/ccmrL6RH.o: in function `void fmt::v8::print<int>(fmt::v8::basic_format_string<char, fmt::v8::type_identity<int>::type>, int&&)':
/home/linuxbrew/.linuxbrew/include/fmt/core.h:3209: undefined reference to `fmt::v8::vprint(fmt::v8::basic_string_view<char>, fmt::v8::basic_format_args<fmt::v8::basic_format_context<fmt::v8::appender, char> >)'
collect2: error: ld returned 1 exit status
Honestly I don't understand what this problem is... The syntax looks good and there is nothing wrong with the compiler and IDE. Could you help me out? Thanks in advance.
Update:
@steeldriver told me that it was because the fmt lib was not linked. So I added some commands in the tasks.json
file:
...
"tasks": [
...
"args": [
...
"-lfmt", "-L~/usr/include/fmt"
]
]
...
/usr/include/fmt
is the path to fmt lib. @steeldriver recommended this reference https://stackoverflow.com/questions/49486880/how-to-link-fftw3-libraries-for-c-in-vs-code-in-ubuntu.