Problem in exporting static function in win32 dll

This is a discussion on Problem in exporting static function in win32 dll within the Windows Programming forums, part of the Platform Specific Boards category; Hi All, I have a function in my C file. This is a static function. I want to export this ...

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,450
    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
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,450
    No you can't. Remove static
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    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, 04:42 PM
  2. [GLUT] Pointers to class methods
    By cboard_member in forum C++ Programming
    Replies: 13
    Last Post: 02-16-2006, 03:03 PM
  3. static char in function problem
    By cpeschke in forum C Programming
    Replies: 3
    Last Post: 02-15-2005, 06:44 PM
  4. Replies: 5
    Last Post: 02-08-2003, 06: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21