https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109380

            Bug ID: 109380
           Summary: inline member function symbol not exported with
                    explicit template instantiation declaration on MinGW
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vittorio.romeo at outlook dot com
  Target Milestone: ---

Created attachment 54801
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54801&action=edit
Full example (lib.h, lib.cpp, main.cpp, build.sh)

Given the following code:

    // ----------------------------
    // lib.h
    template <typename>
    struct S
    {
        void f();
        void g() { }
    };

    template <typename T> void S<T>::f() { }
    extern template struct __declspec(dllexport) S<int>;

    // ----------------------------
    // lib.cpp
    #include "lib.h"
    template struct S<int>;

    // ----------------------------
    // main.cpp
    #include "lib.h"
    int main() { S<int>{}.g(); }


When building with:

    g++ -c -o main.o main.cpp && \
    g++ -c -o lib.o lib.cpp && \
    g++ -shared -o lib.dll lib.o -Wl,--out-implib,liblib.dll.a && \
    g++ -o main.exe main.o -L. -llib


This linker error is erroneously produced:

   
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
main.o:main.cpp:(.text+0x15): undefined reference to `S<int>::g()'
    collect2.exe: error: ld returned 1 exit status


This is likely the same as bug #89088:

     https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89088


And probably related to this Clang PR and review:

     https://reviews.llvm.org/D61118


I bumped into this issue today, using GCC version 12.2.0, on MinGW/MSYS2. 
The last bug report is UNCONFIRMED since 2019.

Reply via email to