Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Delphi2007 link with static C-library

421 views
Skip to first unread message

Heiko Sommerfeldt

unread,
Aug 2, 2008, 2:10:27 AM8/2/08
to
Hello,

I have a DLL exporting a handful of C functions.
I load this DLL dynamically from my Delphi application.

I can create a static library with C++ Builder 2007 or an BPL. But I found
no way to link this code into the Delphi application.
I can link every object file, but this DLL contains a very large number of
files and so there are a lot of obj files - too much.

Does "Codegear RAD studio 2007" support such feature? Can I link C code in
Delphi (Object Pascal) without telling all hundreds of obj files?

Thanks
Heiko

Peter Below (TeamB)

unread,
Aug 2, 2008, 4:30:09 AM8/2/08
to
Heiko Sommerfeldt wrote:

> Does "Codegear RAD studio 2007" support such feature? Can I link C
> code in Delphi (Object Pascal) without telling all hundreds of obj
> files?

No and no. The DLL approach is still the best in this case since it
also makes sure you have all the required C/C++ runtime functions
linked into the DLL. If you want to link individual objs you have to
find a way to provide all the missing runtime functionality to make the
link succeed.

--
Peter Below (TeamB)
Don't be a vampire (http://slash7.com/pages/vampires),
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com

Heiko Sommerfeldt

unread,
Aug 2, 2008, 8:57:43 AM8/2/08
to
Hi Peter

>> Does "Codegear RAD studio 2007" support such feature? Can I link C
>> code in Delphi (Object Pascal) without telling all hundreds of obj
>> files?
>
> No and no. The DLL approach is still the best in this case since it
> also makes sure you have all the required C/C++ runtime functions
> linked into the DLL. If you want to link individual objs you have to
> find a way to provide all the missing runtime functionality to make the
> link succeed.

Thanks for this info.
I tried the trial version of "RAD Studio 2007" and I hoped I can achieve
this. Until now I use Turbo Delphi for the GUI and Visual Studio for the low
level stuff (and existing code that is only available in C/C++).
Are there any plans that this would work sometimes? Exactly this would be
the reason to buy a new version.

I tried to build a BPL instead on the DLL - that worked so far. Then I added
a new component (derived from TComponent) in C++. But This component is not
reachable from Delphi. So I can't create a component with C++ Builder and
use it with Delphi?

Heiko

Peter Below (TeamB)

unread,
Aug 2, 2008, 9:49:35 AM8/2/08
to
Heiko Sommerfeldt wrote:

> Are there any plans that this would work sometimes?

I don't think so. If you need this level of code compatibility between
different languages you will have to move to .NET, i'm afraid. There
assemblies written in different .NET-compatible languages can be used
in projects.

> I tried to build a BPL instead on the DLL - that worked so far. Then
> I added a new component (derived from TComponent) in C++. But This
> component is not reachable from Delphi. So I can't create a component
> with C++ Builder and use it with Delphi?

Nope, only works the other way around: you can use a component build in
Delphi with C++ but not the other way around.

Maël Hörz

unread,
Aug 2, 2008, 8:19:58 PM8/2/08
to
> I can link every object file, but this DLL contains a very large number
> of files and so there are a lot of obj files - too much.
I haven't tried this but it should be possible to link all object files
from a specific directory (dir) like this:
{$L dir\*.obj}

Of course you would still have to declare every function you want to use
in Delphi as external.

Maël Hörz

unread,
Aug 2, 2008, 8:22:26 PM8/2/08
to
> Are there any plans that this would work sometimes? Exactly this would
> be the reason to buy a new version.
I would also like to have better integration between C++ Builder and
Delphi, especially so that one can use common C++ libraries with Delphi.
I really wonder why they still haven't done this.

Bill Todd [TeamB]

unread,
Aug 2, 2008, 10:31:15 PM8/2/08
to
Maël Hörz wrote:

> I really wonder why they still haven't done this.

Has anyone entered this as a feature request in QC? Did it get any
votes? I suspect that there have been very few requests for this
capability.

--
Bill Todd (TeamB)

Peter Below (TeamB)

unread,
Aug 3, 2008, 5:05:54 AM8/3/08
to
Maël Hörz wrote:

> I would also like to have better integration between C++ Builder and
> Delphi, especially so that one can use common C++ libraries with
> Delphi. I really wonder why they still haven't done this.

It would require two completely different run-time libraries to coexist
in the same executable, for instance. And two different class models as
well. I guess the part of the Delphi market that would profid from such
an ability is too small to justify the development effort required to
make this work.

Heiko Sommerfeldt

unread,
Aug 3, 2008, 6:01:08 AM8/3/08
to
Hello

OK, one question: At the moment I have a DLL exporting 10 functions. I know,
that I have to declare these 10 functions, but Do I need to declare all
other internal funktions too?
The number of object files would be some hundred. Does that work with such
huge amount of files? Is it possible to debug through such application from
the beginning (Delphi application) down to the C/C++ code?

Heiko

Roddy Pratt

unread,
Aug 4, 2008, 9:04:01 AM8/4/08
to
Peter Below (TeamB) wrote:

> Nope, only works the other way around: you can use a component build
> in Delphi with C++ but not the other way around.

Well, there's one other approach you could consider:

RadStudio 2007 allows Delphi units and forms to be added to a
C++Builder Project, so just create your project as a C++ one rather
than a Delphi one, and see how things go from there.

I use some Delphi units in my C++ projects, but typically it doesn't
need to call back into the C++ code.

- Roddy

HpW

unread,
Aug 6, 2008, 1:08:31 PM8/6/08
to

Hi Heiko,

I did successfully use a C Builder LIB & Delphi code within a C
Builder dll.

The problem with the C Builder LIB it will be call C Builder specific
utils & mem allocation who will not be known in Delphi code.

What I did, is to mangle the C Builder LIB calls (with it's
parameters) and made them public to us it in the Delphi code within my
C Builder DLL.

On the link part also some LIB's must be used to succeed...

hp

Maël Hörz

unread,
Aug 6, 2008, 2:41:01 PM8/6/08
to
> OK, one question: At the moment I have a DLL exporting 10 functions. I
> know, that I have to declare these 10 functions, but Do I need to
> declare all other internal funktions too?
You would need to export only the functions you want to access from your
Delphi code. And possibly provide implementation for the c library
functions you rely on.

> The number of object files would be some hundred. Does that work with
> such huge amount of files?

I don't know you would have to try.

> Is it possible to debug through such application from the beginning (Delphi application) down to the C/C++ code?

As far as I know you can only debug the Delphi code as there is no Debug
info for the C/C++ code. The obj-files are just seen as black-boxes for
which you define the interface (exported functions). It would work
similarly to what happens when you call Windows API functions.

Heiko Sommerfeldt

unread,
Aug 26, 2008, 6:53:24 AM8/26/08
to
Hi hp,

how you tell the linker to use the the external static lib?

Heiko


"HpW" <h...@nospam4me.nop> schrieb im Newsbeitrag
news:d6mj949ktsd8vgvem...@4ax.com...

0 new messages