?
Solved

BCB3: "library": how to implement?

Posted on 1998-04-18
7
Medium Priority
?
258 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
Technology Partners: 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 60 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses
Course of the Month9 days, 16 hours left to enroll

762 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