Thread: Header Files

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    4

    Unhappy Header Files

    Can anyone help?

    I am having problems using header files, I am experiencing the following error;

    Linker Error: Undefined symbol _opensc in module SCREENO.C
    (Using Borland 4.52)

    The header file opensc.h contains the the prototype but I still get this error.

    If I include the code from the function opensc in the header file the program compiles and works.

    If I don't use a header file/seperate module for the function opensc but include it as a seperate function in the program all works too??

    Any help highly appreciated.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > Linker Error: Undefined symbol _opensc in module SCREENO.C
    This is a linker message, not a compiler message.

    The compiler uses .h files to tell it about the outside world.

    The linker uses .lib files to tell it about the outside world.

    You need to find the library containing the symbol "_opensc", and tell the linker to use that library.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    4
    Ah, I'm wasting my time looking for problems with the header file then.

    Problem with Library/linking to the library file(s).

    I thought I had that set correctly;

    I've set the project screeno options to look for include & library files in the correct dircetories.

    I created a project, target type "Static Library (for.exe)[.lib] and added the node containing the source code for the function opensc.

    I thought that should do the trick??

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > I created a project, target type "Static Library (for.exe)[.lib]
    This is what you do when you are creating a library

    I thought you were creating a program (.exe), which just uses a library for some of the required routines.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    4
    Yes that's right.

    I have a program screeno.exe that uses a function I have created, opensc.

    I was told to create the header file with the prototype for the function and create the library files etc by creating a project - target type static library (for.exe)[.lib]

    Is this wrong?

  6. #6
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    function opensc's definition should be in a .cpp file separate from the main.cpp file. Compile them all. Include the header file in both .cpp files. If this doesn't work than post your code.

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > uses a function I have created, opensc
    I think you need two projects then

    Project 1
    This is a "target type static library (for.exe)[.lib]", and contains those functions which you want to put into the library.
    You can include whatever you want, EXCEPT for a function called main.
    A key aspect of this is one or more .h files which describe all the functions which are in the library. If you have mylib.lib as the library, the .h file might be called mylib.h


    Project 2
    This is a "target type .exe", and contains the non-library code and a main() function.
    Anything which wants to call a library function will need to #include "mylib.h".
    In your project setup, you will tell the compiler where to find mylib.h, and you'll tell the linker where to find mylib.lib.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #8
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    Nice thing about MSVC++6 and VS.NET is that you don't even have to mess with settings. It's all GUI. And the default settings don't have to be reset.

  9. #9
    Registered User
    Join Date
    Oct 2001
    Posts
    4
    "I think you need two projects then"

    Yes this is the set-up that I have, for some reason the Borland IDE will not find the library files that I am creating - even though I tell it were to find them.

    My lecturer has told me that this is a problem with Borland (V5 at college but expected V4.52 to work at home) ....very helpful.

    The work around is to add an extra node to my test project "target type .exe", the node to add is the source code used to create my library file (mylib.c).

    Thanks for all the help/suggestions.

    CSK.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. #include header files or .cpp files?
    By DoctorX in forum C++ Programming
    Replies: 3
    Last Post: 12-23-2006, 12:21 PM
  3. classes and header files
    By Drake in forum C++ Programming
    Replies: 8
    Last Post: 11-30-2006, 07:12 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM