Solved

BCB3: "library": how to implement?

Posted on 1998-04-18
7
201 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now