Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. exporting global operator+ function from DLL

exporting global operator+ function from DLL

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++jsonquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jim Crafton
    wrote on last edited by
    #1

    if I want to export a global operator+ overload, like String operator+( const String& lhs, const int& rhs ); If I define this in a header, like

    __declspec( dllexport ) String operator+( const String& lhs, const int& rhs );

    and then implement this in a .cpp like

    __declspec( dllexport ) String operator+( const String& lhs, const int& rhs )
    {
    return ....//rest of code omitted
    }

    it compiles and builds the DLL fine. When I link to the dll from an exe, however, I get linker errors claiming "String operator+(..." isn't defined. What am I doing wrong? Is it not possible to have the implementation in a .cpp file? Thanks ! ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF!

    K B 2 Replies Last reply
    0
    • J Jim Crafton

      if I want to export a global operator+ overload, like String operator+( const String& lhs, const int& rhs ); If I define this in a header, like

      __declspec( dllexport ) String operator+( const String& lhs, const int& rhs );

      and then implement this in a .cpp like

      __declspec( dllexport ) String operator+( const String& lhs, const int& rhs )
      {
      return ....//rest of code omitted
      }

      it compiles and builds the DLL fine. When I link to the dll from an exe, however, I get linker errors claiming "String operator+(..." isn't defined. What am I doing wrong? Is it not possible to have the implementation in a .cpp file? Thanks ! ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF!

      K Offline
      K Offline
      KaRl
      wrote on last edited by
      #2

      May that be a problem of linker decoration, calling convention mismatch? Could using extern "C" solve your problem? :~


      Fold With Us! Sie wollen mein Herz am rechten Fleck, doch Seh' ich dann nach unten weg Da schlägt es links

      J 1 Reply Last reply
      0
      • K KaRl

        May that be a problem of linker decoration, calling convention mismatch? Could using extern "C" solve your problem? :~


        Fold With Us! Sie wollen mein Herz am rechten Fleck, doch Seh' ich dann nach unten weg Da schlägt es links

        J Offline
        J Offline
        Jim Crafton
        wrote on last edited by
        #3

        Well I did try the "extern" keyword and that didn't make any difference. I'm really at a loss, and I guess I'll just have to try and put the impl in the header, which I really didn't want to have to do. ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF!

        1 Reply Last reply
        0
        • J Jim Crafton

          if I want to export a global operator+ overload, like String operator+( const String& lhs, const int& rhs ); If I define this in a header, like

          __declspec( dllexport ) String operator+( const String& lhs, const int& rhs );

          and then implement this in a .cpp like

          __declspec( dllexport ) String operator+( const String& lhs, const int& rhs )
          {
          return ....//rest of code omitted
          }

          it compiles and builds the DLL fine. When I link to the dll from an exe, however, I get linker errors claiming "String operator+(..." isn't defined. What am I doing wrong? Is it not possible to have the implementation in a .cpp file? Thanks ! ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF!

          B Offline
          B Offline
          Bo Hunter
          wrote on last edited by
          #4

          Is the __declspec( dllexport ) hard coded in the header? If so you might try forward declaring the prototype with dllimport and try that. Thank You Bo Hunter

          J 1 Reply Last reply
          0
          • B Bo Hunter

            Is the __declspec( dllexport ) hard coded in the header? If so you might try forward declaring the prototype with dllimport and try that. Thank You Bo Hunter

            J Offline
            J Offline
            Jim Crafton
            wrote on last edited by
            #5

            nope, I am using the traditional DLL_API kind of macro to shift it to import or export as the case may be. ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF!

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups