warning LNK4049: locally defined symbol Func() imported

This is a discussion on warning LNK4049: locally defined symbol Func() imported within the C++ Programming forums, part of the General Programming Boards category; I'm getting this warning when compiling a project in VC++ 6.0: Code: warning LNK4049: locally defined symbol Func() imported The ...

  1. #1
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545

    warning LNK4049: locally defined symbol Func() imported

    I'm getting this warning when compiling a project in VC++ 6.0:
    Code:
    warning LNK4049: locally defined symbol Func() imported
    The MSDN description of the warning says:
    Quote Originally Posted by MSDN
    The symbol was both exported from and imported to the program.
    So I'm wondering what kind of danger it's warning me about, and how to I get rid of the warning?

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,669
    Are you using "__declspec( dllimport )" on Func()?

    gg

  3. #3
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    No, none that I could find.
    I searched all project files for the function and all I found were normal function definitions and declarations using extern.

  4. #4
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    No wait, I found some function declarations that use a macro infront of them. When I searched for the macro name it's #defined all over the place and sometimes it's defined as:
    __declspec(dllexport)
    and sometimes as:
    __declspec(dllimport)

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,669
    You typically see something like this in a DLL header...
    Code:
    #if defined(BUILDING_MY_DLL)
    #   pragma message ("Compiling MyApi.DLL")
    #   define MY_API __declspec(dllexport)
    #else
    #   pragma message ("Linking to MyApi.DLL")
    #   define MY_API __declspec(dllimport)
    #endif
    So when you're actually compiling the DLL, you have "BUILDING_MY_DLL" defined. That way, anything decorated with "MY_API" will be exported from the DLL.

    When you're compiling something that uses the DLL, you should not have "BUILDING_MY_DLL" defined. So when you include the DLL header, anything decorated with "MY_API" will be imported from the DLL. Then you just have to link with the import library to resolve all those imported symbols.

    I only remember getting that linker warning when I wasn't doing the above correctly

    gg

  6. #6
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Some of the header files I saw did that, but others (like stdafx.h) always export.

    Is this warning indicating that there is some kind of problem (i.e. could this break anything), or is it just a reminder that something useless is being done in the code?

  7. #7
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,669
    Can't say if anything will "break" - maybe not since it's just a warning. Ideally, you'd fix the warning

    gg

  8. #8
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    It will break when you distribute an updated DLL and wonder why the changes aren't picked up. Now that's fun: you distribute a bugfix, but it doesn't fix the bug.
    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

  9. #9
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by CornedBee View Post
    It will break when you distribute an updated DLL and wonder why the changes aren't picked up. Now that's fun: you distribute a bugfix, but it doesn't fix the bug.
    After I replaced the DLL with the new one I built, I'm getting trace errors about not being able to load the DLL... So I'm guessing you're right.

    What exactly would cause the changes to not be picked up?

    When I look at the old & new DLL with Depends, they have the same functions, except the new one is missing 4 functions that the old one has.

  10. #10
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,669
    >> What exactly would cause the changes to not be picked up?
    Sounds like those functions don't have "__declspec(dllexport)" when building the DLL.

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GradeInfo
    By kirksson in forum C Programming
    Replies: 23
    Last Post: 07-16-2008, 03:27 PM
  2. Trouble with multiple symbols
    By Kotatsu in forum C++ Programming
    Replies: 3
    Last Post: 04-08-2003, 09:03 PM
  3. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  4. Header files
    By borland_man in forum C++ Programming
    Replies: 14
    Last Post: 02-22-2002, 03:30 AM
  5. Function basics
    By sjleonard in forum C++ Programming
    Replies: 15
    Last Post: 11-21-2001, 11:02 AM

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