Thread: Problem in exporting static function in win32 dll

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    10

    Problem in exporting static function in win32 dll

    Hi All,

    I have a function in my C file. This is a static function. I want to export this function in the windows DLL. for exporting this function i have it in .h file as

    static int SPLIBRSYNC_API SayHello(int i);

    If i compile my code without the .def file. it compiles successfully. No as i have to export this function. i put the entry of this function in the .def file as

    LIBRARY MyDll

    EXPORTS
    SayHello @1

    Now after adding the .def file, when i compile the project, i get the linker errors as

    SPLibrSync.def : error LNK2001: unresolved external symbol SayHello
    Debug/SPLibrSync.lib : fatal error LNK1120: 1 unresolved externals
    LINK : fatal error LNK1141: failure during build of exports file

    if i remove the static keyword from the .h and .c file. The project compiles successfully. So what might be the problem with static keyword for exporting.

    Please help

    Thanks

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    the problem is that the static function is only visible inside the current c/cpp file
    So it obviously cannot be visible outside the dll
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    10
    Hi Vart,

    Thanks for the prompt reply,

    So what should i do to export the static function. Can i export it?

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    No you can't. Remove static
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    static means internal linkage, i.e. the function is not supposed to be visible outside its compilation unit. Trying to export it is a direct contradiction.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  2. [GLUT] Pointers to class methods
    By cboard_member in forum C++ Programming
    Replies: 13
    Last Post: 02-16-2006, 04:03 PM
  3. static char in function problem
    By cpeschke in forum C Programming
    Replies: 3
    Last Post: 02-15-2005, 07:44 PM
  4. Replies: 5
    Last Post: 02-08-2003, 07:42 PM
  5. Exporting Object Hierarchies from a DLL
    By andy668 in forum C++ Programming
    Replies: 0
    Last Post: 10-20-2001, 01:26 PM