Solved

BCB3: "library": how to implement?

Posted on 1998-04-18
7
249 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

695 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