Thread: Linker errors with simple static library

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    156

    Unhappy Linker errors with simple static library

    I built a simple static library using the Visual C++ wizard and put in a simple function. Then wrote a simple program that calls it.

    In the calling program I included the static library's .h file, set the project settings to look for and find the .lib (it finds it because the linker message is ->"Searching C:\Practice\simple\Debug\simple.lib:", but I still get the age old "Main.obj : error LNK2001: unresolved external symbol "int __cdecl test(void)" (?test@@YAHXZ)".

    What setting am I missing I know this must be very straight forward but it has me stumped.

    Thank you

  2. #2
    Registered User Esss's Avatar
    Join Date
    Aug 2001
    Posts
    133
    Is your library file a .C file? .C files are compiled with the C compiler, whereas .CPP files are compiled with the C++ compiler. If so, try changing the extension to .CPP and recompiling.

    Check to ensure the calling convention is the same (no WINAPI, PASCAL, __stdcall, etc.).
    Ess
    Like a rat in a maze who says,
    "Watch me choose my own direction"
    Are you under the illusion
    The path is winding your way?
    - Rush

  3. #3
    Unregistered
    Guest
    I assume you are using "MFC in a shared DLL" in the general setting for the project?

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    156
    I'm not using MFC at all in the static library (simple.lib) or the calling program.

    I'm a little confused when you say "shared dll" because all dlls are shared and even have a ref count to keep them in memory. And I'm attempting to build a simple static (not dynamic) library.

    But what I have found of interest is that my calling program searches my simple.lib
    "Searching C:\Practice\Simple\Debug\simple.lib: (I enabled link print progress messages in the project ).
    The error message is"
    error LNK2001: unresolved external symbol "int __cdecl test(void)" (?test@@YAHXZ)
    When I use dumpbin on simple.lib I get:
    Communal; sym= "int __cdecl Test(void)" (?Test@@YAHXZ)
    There is no name mangling and the function is availible and the lib is being found and searched. I know its some stupid little thing I'm missing. If you've got any suggestion PLEASE offer them.

    dang
    Last edited by Dang; 09-07-2001 at 07:23 PM.

  5. #5
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    Spot the difference -

    int __cdecl test(void) //from error message

    int __cdecl Test(void) //from dumpbin

  6. #6
    Registered User
    Join Date
    Sep 2001
    Posts
    156

    Linker errors with simple static library

    Do I feel like a horse's you know what. Thank you for spotting what I should have.

    Much appreciation.

    dang

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. static data structure in a library
    By melight in forum C Programming
    Replies: 6
    Last Post: 01-10-2009, 11:12 AM
  2. Problem with Free.
    By chakra in forum C Programming
    Replies: 9
    Last Post: 12-15-2008, 11:20 AM
  3. Linker errors with static abstract class...
    By Shamino in forum C++ Programming
    Replies: 19
    Last Post: 01-15-2008, 03:35 PM
  4. help, linker errors when adding library file to project
    By ngcfan525 in forum C++ Programming
    Replies: 1
    Last Post: 03-09-2003, 02:27 PM
  5. MSVis-Studio C++ libraries and linker errors
    By kellydj in forum Windows Programming
    Replies: 10
    Last Post: 03-12-2002, 02:03 PM