0

I was trying to create a console library for C++, but found out that my print function just doesn't want to compile when I put it's code in a dynamic library.

wdxp@WDXP-System:/XVIO$ clang -L. -lXVIO -std=c++17 -lstdc++ test.cc -o test
In file included from test.cc:1:
./XVIO.h:15:15: warning: inline function 'XVIO::print<const char (&)[13]>' is not defined [-Wundefined-inline]
    constexpr print(XVAny&& ... content) noexcept;
              ^
test.cc:5:8: note: used here
        XVIO::print("Hello World!");
              ^
1 warning generated.
/usr/bin/ld: /tmp/test-42ce58.o: in function `main':
test.cc:(.text+0x17): undefined reference to `void XVIO::print<char const (&) [13]>(char const (&) [13])'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

However, this error does not occur when I put the code of the print function onto a header file.

Is there any fix?

Code for the print function:

namespace XVIO {
    <typename... XVAny>
    void print(XVAny&& ... content) noexcept
    {
        ((std::cout << std::forward<XVAny>(content) << " " ), ...); std::cout << std::endl;
    }
}
WNDXP
  • 1
  • *"However, this error does not occur when I put the code of the print function onto a header file...."* See [Why can templates only be implemented in the header file?](https://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file) – Jason Sep 25 '22 at 06:43

0 Answers0