Solved

BCB3: "library": how to implement?

Posted on 1998-04-18
7
221 Views
Last Modified: 2010-04-10
Ok... So it's not that difficult, but here's my background:

1) I took C language in college 7 yrs ago. They never taught me "Libraries/Drivers".
2) I'm a pascal/Delphi fan... That's one of the reasons I chose BC++Builder 3.

I have a TCP/IP programming assignment due in a few days. In the assignment it states "A "driver" or library module should be coded that has the following ...". So, I thinking...

"oh, that just a "unit" (from delphi)".. So I go to File/New Unit.. menu and start adding my functions that I need after #pragma package(smart_init)...
Welp... Great! I think... So I go into my new form and put
#include "rup_libary.h" at the top. So far so good... Now I start adding code to a button... in that code I need to call one of my functions that exist in the "library" called rup_close();

I goto "build" the program and bamm!... I get the following error:

[C++Error] serverfrm.cpp(22): Call to undefined function 'rup_close'.

So... How do I create a "Library" that can be seen from my form code? I'd rather not create a class if possible.

Any help would be greatly appreciated!
John
0
Comment
Question by:zitt
  • 4
  • 3
7 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1161933
Its hard to understand from what you've said.  but it sounds like you defined the close function and other functions in a source code file.  (.cpp)  but when you go to use them you are including a header file (.h).  You need to declare the function in the .h file.  (But you can still define them in the .cpp file).
0
 

Author Comment

by:zitt
ID: 1161934
Okay... So, Can I #include "rup_libary.cpp"?

Is it illegal to have only a .h file with no .cpp file?

Sorry, I'm totally new to creating my own libraries in C.

John
0
 
LVL 22

Expert Comment

by:nietod
ID: 1161935
yes, you can place the function definition (that is the body of the function) in a .cpp file and include the file.  That will work, but is very unusual.  Usually you would compile the .cpp file to produce a .obj file in one project.  Then in another project you would link in the obj file (byt adding it to the project).  And you would include a .h into this project's source file.  This .h has only the function declarations, not the definitions.  That is has the function's return value, name and parameters, but no body.
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

by:zitt
ID: 1161936
The end result is these functions in my "library" will be under constant work. I'd like to be able to debug each function as I add functionality to them.

For example, under Delphi... I can make changes on the fly to a unit and the new code would be there. I'm just having a hard time understanding why does it differently.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1161937
That should be the same under BCB3.  (Its exactly the case I have.) What your would do is create a project group that has two projects.  One project is for the library (In my case a DLL library.  But it could be an OBJ library if you want)  The other project is for an EXE that uses the library.  The EXE library should be the second project in the project group (You can use the "build sooner"/"build later" commands to control the positions.  The EXE should be built last.)  You should compile using the make all projects command.  This will check for changes to the library project and recompile/relink it if needed and then  do the same for the EXE project.  The EXE project should have at least two things under it.  One is the source code (.cpp) file  The other thing is the output file of the library project.  In my case a .LIB file, in your case a .OBJ file.

Has this been of any help to you?
0
 
LVL 22

Accepted Solution

by:
nietod earned 20 total points
ID: 1161938
Was this helpful? Do you need more?
0
 

Author Comment

by:zitt
ID: 1161939
Nietod,

Thanks for all your help... I'm not sure what the hang up was... but I got the library working...

John
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question