<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-text-flowed" style="font-family: -moz-fixed;
      font-size: 14px;" lang="x-unicode">Using clang on Windows
      targeting mingw(-64)/gcc since it does not appear possible to
      export individual member functions of a class, as well as export
      the RTTI of the class, without exporting the entire class, I have
      changed my example in my post "Linker error and obfuscated name"
      to export the entire class itself. But I am still seeing a linker
      error, Here is the changed code and command lines:
      <br>
      <br>
      // ex_decl.hpp
      <br>
      <br>
      #ifndef EX_DECL_HPP
      <br>
      #define EX_DECL_HPP
      <br>
      #if defined(BLD_EX_EXAMPLE)
      <br>
          #define EX_DECL __attribute__((__dllexport__))
      <br>
      #else
      <br>
          #define EX_DECL __attribute__((__dllimport__))
      <br>
      #endif
      <br>
      #endif // EX_DECL_HPP
      <br>
      <br>
      // ex_exception.hpp
      <br>
      <br>
      #ifndef EX_EXCEPTION_HPP
      <br>
      #define EX_EXCEPTION_HPP
      <br>
      #include <exception>
      <br>
      #include "ex_decl.hpp"
      <br>
      class EX_DECL ex_exception :
      <br>
          public virtual std::exception
      <br>
      {
      <br>
      private:
      <br>
          char m_buffer[128];
      <br>
      protected:
      <br>
          unsigned int append(unsigned int l, const char * a);
      <br>
          ex_exception() ;
      <br>
      public:
      <br>
          typedef enum {
      <br>
            no_exception,
      <br>
            other_exception
      <br>
          } ex_exception_code;
      <br>
          ex_exception_code code;
      <br>
          ex_exception(ex_exception_code c,const char * e1 = 0,const
      char * e2 = 0) ;
      <br>
          ex_exception(ex_exception const &) ;
      <br>
          virtual ~ex_exception() throw() ;
      <br>
          virtual const char * what() const throw() ;
      <br>
      };
      <br>
      #endif // EX_EXCEPTION_HPP
      <br>
      <br>
      // ex_exception.cpp
      <br>
      <br>
      #include <exception>
      <br>
      #include <cstring>
      <br>
      #define BLD_EX_EXAMPLE
      <br>
      #include "ex_exception.hpp"
      <br>
      unsigned int ex_exception::append(unsigned int l, const char * a){
      <br>
          while(l < (sizeof(m_buffer) - 1)){
      <br>
              char c = *a++;
      <br>
              if('\0' == c)
      <br>
                  break;
      <br>
              m_buffer[l++] = c;
      <br>
          }
      <br>
          m_buffer[l] = '\0';
      <br>
          return l;
      <br>
      }
      <br>
      ex_exception::ex_exception(ex_exception_code c,const char *
      e1,const char * e2) : code(c)
      <br>
      {
      <br>
        unsigned int length = 0;
      <br>
          switch(code){
      <br>
          case no_exception:
      <br>
              length = append(length, "uninitialized exception");
      <br>
              break;
      <br>
          case other_exception:
      <br>
              length = append(length, "unknown derived exception");
      <br>
              break;
      <br>
          default:
      <br>
              length = append(length, "programming error");
      <br>
              break;
      <br>
          }
      <br>
      }
      <br>
      ex_exception::ex_exception(ex_exception const & oth) :
      std::exception(oth),code(oth.code)
      <br>
      {
      <br>
          std::memcpy(m_buffer,oth.m_buffer,sizeof m_buffer);
      <br>
      }
      <br>
      ex_exception::~ex_exception() throw() {}
      <br>
      const char * ex_exception::what() const throw() { return m_buffer;
      }
      <br>
      ex_exception::ex_exception() : code(no_exception) {}
      <br>
      <br>
      // Compile ex_exception.cpp
      <br>
      <br>
      clang++.exe -c -x c++ -D__MINGW_FORCE_SYS_INTRINS
      -Wno-unused-local-typedef -Wno-dll-attribute-on-redeclaration -O0
      -g -fno-inline -Wall -g -march=i686 -m32 -o "ex_exception.obj"
      "ex_exception.cpp"
      <br>
      <br>
      // ex_xml_exception.hpp
      <br>
      <br>
      #ifndef EX_XML_EXCEPTION_HPP
      <br>
      #define EX_XML_EXCEPTION_HPP
      <br>
      #include <exception>
      <br>
      #include "ex_decl.hpp"
      <br>
      #include "ex_exception.hpp"
      <br>
      class EX_DECL ex_xml_exception :
      <br>
          public virtual ex_exception
      <br>
      {
      <br>
      public:
      <br>
          typedef enum {
      <br>
              xml_archive_parsing_error,
      <br>
              xml_archive_tag_mismatch,
      <br>
              xml_archive_tag_name_error
      <br>
          } ex_exception_code;
      <br>
          ex_xml_exception(ex_exception_code c,const char * e1 = 0,const
      char * e2 = 0);
      <br>
          ex_xml_exception(ex_xml_exception const &) ;
      <br>
          virtual ~ex_xml_exception() throw() ;
      <br>
      };
      <br>
      #endif // EX_XML_EXCEPTION_HPP
      <br>
      <br>
      // ex_xml_exception.cpp
      <br>
      <br>
      #include <exception>
      <br>
      #define BLD_EX_EXAMPLE
      <br>
      #include "ex_xml_exception.hpp"
      <br>
      ex_xml_exception::ex_xml_exception(ex_exception_code c,const char
      * e1,const char * e2) :
      <br>
              ex_exception(other_exception, e1, e2)
      <br>
          {
      <br>
              switch(c){
      <br>
              case xml_archive_parsing_error:
      <br>
                  ex_exception::append(0, "unrecognized XML syntax");
      <br>
                  break;
      <br>
              case xml_archive_tag_mismatch:
      <br>
                  ex_exception::append(0, "XML start/end tag mismatch");
      <br>
                  if(0 != e1){
      <br>
                      ex_exception::append(0, " - ");
      <br>
                      ex_exception::append(0, e1);
      <br>
                  }
      <br>
                  break;
      <br>
              case xml_archive_tag_name_error:
      <br>
                  ex_exception::append(0, "Invalid XML tag name");
      <br>
                  break;
      <br>
              default:
      <br>
                  ex_exception::append(0, "programming error");
      <br>
                  break;
      <br>
              }
      <br>
          }
      <br>
      ex_xml_exception::ex_xml_exception(ex_xml_exception const &
      oth) : std::exception(oth),ex_exception(oth){}
      <br>
      ex_xml_exception::~ex_xml_exception() throw() {}
      <br>
      <br>
      // Compile ex_xml_exception.cpp
      <br>
      <br>
      clang++.exe -c -x c++ -D__MINGW_FORCE_SYS_INTRINS
      -Wno-unused-local-typedef -Wno-dll-attribute-on-redeclaration -O0
      -g -fno-inline -Wall -g -march=i686 -m32 -o "ex_xml_exception.obj"
      "ex_xml_exception.cpp"
      <br>
      <br>
      // Link exmp-clang37-d-1_59.dll
      <br>
      <br>
      clang++.exe -o "exmp-clang37-d-1_59.dll" -Wl,-soname
      -Wl,exmp-clang37-d-1_59.dll -shared -Wl,--start-group
      "ex_exception.obj" "ex_xml_exception.obj"  -Wl,-Bstatic 
      -Wl,-Bdynamic  -Wl,--end-group -g -march=i686 -m32
      <br>
      <br>
      // throw_exception_ex.cpp
      <br>
      <br>
      #include "ex_xml_exception.hpp"
      <br>
      template<class E> void throw_exception(E const & e) {
      throw e; }
      <br>
      int main(int argc,char * argv[])
      <br>
      {
      <br>
          if (argc > 1)
      <br>
                {
      <br>
      <br>
throw_exception(ex_xml_exception(ex_xml_exception::xml_archive_parsing_error));
      <br>
                }
      <br>
          return 0;
      <br>
      }
      <br>
      <br>
      // Compile throw_exception_ex.cpp
      <br>
      <br>
      clang++.exe -c -x c++ -D__MINGW_FORCE_SYS_INTRINS
      -Wno-unused-local-typedef -Wno-dll-attribute-on-redeclaration -O0
      -g -fno-inline -Wall -g -march=i686 -m32 -o
      "throw_exception_ex.obj" "throw_exception_ex.cpp"
      <br>
      <br>
      // Link thr_exmp.exe
      <br>
      <br>
      clang++.exe -Wl,-R -Wl,"." -Wl,-rpath-link -Wl,"." -o
      "thr_exmp.exe" -Wl,--start-group "throw_exception_ex.obj"
      "exmp-clang37-d-1_59.dll" -Wl,-Bstatic -Wl,-Bdynamic
      -Wl,--end-group -g -march=i686 -m32
      <br>
      <br>
      // Error message from this link
      <br>
      <br>
      throw_exception_ex.obj: In function
      `Z15throw_exceptionI16ex_xml_exceptionEvRKT_':
      <br>
      throw_exception_ex.cpp:2: undefined reference to
      `_imp___ZTI16ex_xml_exception'
      <br>
      clang++.exe: error: linker command failed with exit code 1 (use -v
      to see invocation)
      <br>
      <br>
      So even when I export/import the entire class rather than
      individual member functions, I can not link my final module
      successfully as it is still looking for something in the shared
      library that it says is not there.
      <br>
      <br>
      This same code succeeds without problem with mingw(-64)/gcc on
      Windows.
      <br>
    </div>
  </body>
</html>