Thread: Linking .h files to libraries

  1. #1
    Super Moderator
    Join Date
    Sep 2001

    Angry Linking .h files to libraries

    I'm getting a little frustrated with libraries. 2 things:

    - How do I link a library (*.lib type) to a header file?

    - In the header file, do I need to put function and class prototypes if I put them in the files in the library? Can I?

    Thanks if you can help.

    If you need a specific compiler, it can be either Borland Turbo C++ 3.0 for DOS, or 4.5 for Windows. I can do either one.

    Sean Mackrory.

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    I'm not sure if this is different for the Borland products but in MSVC you don't need a header file to compile a library(you don't need to prototype the functions), but you need to declare any functions in this library before they are used in a project that uses the library. So it's a good idea to create one with the library that can be used with it.

  3. #3
    You'd be better off using assembler I think to create your library, but I've done it using MSVC in an oddball manner :P. Keep in mind that any special headers that you use to create a lib in c might not work if you use your lib with another compiler.

    extern "C" datatype somefunction(parameter list)
    function body
    return datatype

    compile it to an object file. Use your compiler's library manager (TLIB) to create the library name. Use your linker to link your program source code and add your library.

    /* mylib.cpp */

    extern "C" int drawScreen(void)
    // do something here
    return 0;

    compile here to an object file. Then use TLIB c:>tlib mylib.obj

    /* myprogram.cpp */

    extern "C" int drawScreen(void); // prototype

    int main()
    return 0;

    compile to object file or if you have an option to add the library in using your IDE use that. c:>tlink myprogram.obj + mylib.lib I think I did it like that, but it's been a while and I used lib and link of VC. At any rate the method worked.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  2. Replies: 3
    Last Post: 11-07-2006, 06:41 AM
  3. Replies: 3
    Last Post: 07-06-2006, 11:17 AM
  4. Linking Files
    By MT_Pockets in forum C++ Programming
    Replies: 8
    Last Post: 02-24-2006, 08:50 PM
  5. Making .h files
    By Diamonds in forum C++ Programming
    Replies: 3
    Last Post: 11-14-2002, 02:05 PM