Stupid Linking question

This is a discussion on Stupid Linking question within the C++ Programming forums, part of the General Programming Boards category; This should win the stupid question of the day, but here goes. I am using the Borland BCC5.5 compiler. Now ...

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    14

    Stupid Linking question

    This should win the stupid question of the day, but here goes.

    I am using the Borland BCC5.5 compiler. Now that I started working with classes, I need to link the .cpp and .h files but cant quite figure out how. Any help would be appreciated.

  2. #2
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    I have not worked with the compiler, but if it is like any other compiler, you need to include both of those files to your project and use #include statements to link the headers.

  3. #3
    Registered User
    Join Date
    Oct 2003
    Posts
    14
    I've included the #include lines. I'm not sure about the project part.

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Code:
    // Class header
    #ifndef BLAH
    #define BLAH
    
    class blah {
      ...
    };
    
    #endif
    Code:
    // Class implementation
    #include "blah.h"
    
    ...
    Code:
    // main.cpp
    #include "blah.h"
    
    int main()
    {
      blah b;
      ...
    }
    To compile and link, do this (IIRC):
    Code:
    C:\bcc32 blah.cpp main.cpp
    My best code is written with the delete key.

  5. #5
    Registered User
    Join Date
    Oct 2003
    Posts
    14
    I'll give it a try, thanks. Do I need to do anything with the header file?

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Do I need to do anything with the header file?
    No, the header file is only used so that multiple source files can see the declarations. The linking stage makes no use of it.
    My best code is written with the delete key.

  7. #7
    Registered User
    Join Date
    Oct 2003
    Posts
    14
    It looks like it compiled ok. Do I then just type in main to run the program or do I need to do something else?

  8. #8
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Do I then just type in main to run the program or do I need to do something else?
    For the life of me I can't remember what Borland saves the executable as. Check the directory and see what the .exe file is named, then just run that program.
    My best code is written with the delete key.

  9. #9
    Registered User
    Join Date
    Oct 2003
    Posts
    14
    Will do. Thanks for the help.

  10. #10
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,161
    Quote Originally Posted by Prelude
    >Do I then just type in main to run the program or do I need to do something else?
    For the life of me I can't remember what Borland saves the executable as. Check the directory and see what the .exe file is named, then just run that program.
    bcc32 pgm.cpp subs.cpp

    will create pgm.exe

    It's the name of the first source file on the line.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stupid Question Probably
    By Kyrin in forum C Programming
    Replies: 2
    Last Post: 05-07-2006, 12:51 AM
  2. Replies: 7
    Last Post: 11-03-2005, 11:17 PM
  3. Stupid Question
    By digdug4life in forum C++ Programming
    Replies: 22
    Last Post: 05-17-2005, 11:43 AM
  4. stupid, stupid question
    By xelitex in forum C++ Programming
    Replies: 5
    Last Post: 12-22-2004, 07:22 PM
  5. Stupid question: What does Debugger do?
    By napkin111 in forum C++ Programming
    Replies: 6
    Last Post: 05-02-2002, 10:00 PM

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