×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

What is needed to get my own Package Library working?

What is needed to get my own Package Library working?

What is needed to get my own Package Library working?

(OP)
I cannot find how to access a home made Package Library from an application. I use Codegear C++ builder 2007.
First I coded the Package and it produced a .bpl file. I copied it to a directory that can be found.
Then I made the application that needs the package. Nothing I tried caused the application to compile. The error messages I get say that there is an "...Error: Unresolved external 'A::getValue() const' referenced from D:\RAD PROJECTEN\BPL-TEST\TEST01APPLCATIE\DEBUG_BUILD\UNIT1.OBJ".

I now have the code as follows:
mylib.cpp:

CODE

#pragma hdrstop

#include "mylib.h"

//---------------------------------------------------------------------------

#pragma package(smart_init)
//----------------------------------------------
#include "mylib.h"

class A;

A::A(int newa) : a(newa)
{
}

int A::getValue() const
{
  return a;
}

void A::setValue(int newa)
{
  a = newa;
}
mylib.h:

CODE

#ifndef mylibH
#define mylibH
//---------------------------------------------------------------------------

class A;

class A
{
   public:
      A();
      ~A() {};
      A(int newa);
      int getValue() const;
      void setValue(int newa);
   private:
      int a;
};
//----------------------------------------------

#endif
Unit1.cpp:

CODE

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"

#include "mylib.h"

TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
  : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  // Creates an object, A (from the library)
  A test(50);
  Form1->Caption = test.getValue();
}
Unit1.h:

CODE

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:    // IDE-managed Components
  TButton *Button1;
  void __fastcall Button1Click(TObject *Sender);
private:    // User declarations
public:        // User declarations
  __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

What is missing?

Regards,  Alex

RE: What is needed to get my own Package Library working?

I'm not very familiar with packages so when I'm telling you is from my interpretation of C++Builder Developer's Journal's six part article named, Packages in C++Builder. These started in July of 2008 but you have to be a subscriber to read them. The cost is well worth it in my humble opinion.

When I've seen this error, it usually relates to exporting functions or namespaces. In packages, like DLLs, you have to export your functions and classes. Unlike DLLs, you don't have to create a custom "define". You use the keyword PACKAGE.

Quote (Packages in C++Builder, Part I):

If you've ever created a DLL project then you'll know you need to use the __declspec( dllimport ) and __declspec( dllexport ) declarations, and the following examples will look familiar.

#ifdef _BUILDDLL_ // DLL project define
#define APITYPE __declspec( dllexport )
#else
#define APITYPE __declspec( dllimport )
#endif
APITYPE int func();
class APITYPE TMyClass
{
int i;
virtual int func( void );
};

The declaration difference between a DLL project and a Package project is that you don't need to create a custom "define" for the latter type. Instead, you use the PACKAGE keyword, like so:

PACKAGE int func();
class PACKAGE TMyClass
{
int i;
virtual int func( void );
};

This simple keyword simplifies project development a little—and every bit helps.

When creating namespaces in packages, there are some rules to follow.

Quote (Packages in C++Builder, Part II):

The name given to the namespace has a very specific naming convention. It must bare the same name as the unit that contains it, but the first character must be a capital letter and all others lowercase.

This advice is from skimming over those six articles and I don't know if they will help or not but these were the first things that came to my mind.
 

James P. Cottingham
I'm number 1,229!
I'm number 1,229!

RE: What is needed to get my own Package Library working?

(OP)
James,
Thanks for your reply. I'll study it, though I don't know if it is enough to get me going. Maybe I am on the wrong track wanting to use a Library Package and perhaps I should go back to a DLL. I don't think I want to spend $49 for a journal that most probably is over my head!
I will look into DLL's and see where it gets me.
Regards,  Alex

RE: What is needed to get my own Package Library working?

Also, try looking at the #pragma link directive.  This directs the linker to link in the library.

RE: What is needed to get my own Package Library working?

(OP)
Thanks Prattaratt, I will come to that I expect. I have begun to study the examples given in a book by Hollingworth et al and working with CPPB 5. It will increase my understanding of the subject (I hope!)
Regards,  Alex

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close