Recent

Author Topic: Lazarus and C++ ?  (Read 24422 times)

chris.gordon-smith

  • New Member
  • *
  • Posts: 12
    • http://graffiti.virgin.net/c.gordon-smith/index.html
Lazarus and C++ ?
« on: January 03, 2004, 11:53:00 am »
Lazarus certainly looks like an interesting project. My problem is that I have a substantial amount of code that's written in C++Builder and Kylix C++. Borland seems to have lost interest in supporting users of these products. C++BuilderX is a mammoth package, but I can't use it to build my existing project. Its a bizarre situation, but there it is.

Lazarus looks like the solution for Delphi users. What about C+? Would it be possible for C++ code to interface to the Lazarus code so that C++ users could take advantage of the object pascal components? Given that C++ Builder does something like this, I would have thought that it may be a possibility.

Any comments welcome. I have read the FAQ entry that says there is no plan for C++ support, but I would have thought that it should be possible.

Chris Gordon-Smith
http://graffiti.virgin.net/c.gordon-smith/

Anonymous

  • Guest
Lazarus and C++ ?
« Reply #1 on: January 03, 2004, 08:21:12 pm »
Its easy for Borland to do that cause they write their own compilers. You cant mix and match MS visual c++ and Delphi so I doubt you can do the same with FPC/Gcc in the same manner.

We would need support for Corba / Orbits to do what u want but FPC does not support Corba yet (plus a rewrite of the LCL components to use Corba interfaces). If and when thats done then it would be able to support any language that uses corba including c++ and others... (in the same way com components can be used on ms platforms).

chris.gordon-smith

  • New Member
  • *
  • Posts: 12
    • http://graffiti.virgin.net/c.gordon-smith/index.html
Lazarus and C++ ?
« Reply #2 on: January 04, 2004, 02:31:46 pm »
Thanks for these comments. As you say, Borland C++ has special language features to support the integration with Delphi. The 'pascalimplementation' declaration modifier is one of these. Clearly this language feature won't exist in a non Borland C++ compiler such as gcc. However, if it were possible to understand how the interface works, then I wonder whether it might be possible to re-engineer it in a gcc / Lazarus environment using language features that do exist. For example, whatever calling interface is required by fpc can presumably in prinpiple be satisfied in a C++ environment, even if one has to resort to the use of assembler code to achieve this.

No doubt the Corba approach offers a better and more generic solution. However, in the meantime I and a lot of other Borland BCB and Kylix (C++) face  the prospect of code that has been developed over several years becoming unsupportable if Borland do drop VCL and CLX.

An integration between Lazarus and C++ would therefore be of great interest.

Chris Gordon-Smith
http://graffiti.virgin.net/c.gordon-smith/

Anonymous

  • Guest
Lazarus and C++ ?
« Reply #3 on: January 05, 2004, 03:11:55 am »
check out the fpc future plans at :

http://www.freepascal.org/future.html

It mentions the possibility of linking with c++ code in future versions. Still u should post your question to one of the FPC team (see http://www.freepascal.org/moreinfo.html).

chris.gordon-smith

  • New Member
  • *
  • Posts: 12
    • http://graffiti.virgin.net/c.gordon-smith/index.html
Lazarus and C++ ?
« Reply #4 on: January 06, 2004, 01:12:08 am »
Thanks for the links. As you say, there is a plan for linking with C++ in a future release. However, I'm not  sure whether this means calling C++ from Pascal, or calling Pascal from C++.

I suspect it may be the first, whereas what would be required to reproduce something like the way C++ Builder interfaces with Delphi would be C+ calling Pascal.

I suspect that this may not necessarily be rocket science. It seems that gcc supports the construct

'extern pascal'

which enables a C++ program to call a program using Pascal rules. This is not an area I'm familiar with, but if I can make some time I might do a little tinkering with this.

Chris Gordon-Smith
London
Homepage: http://graffiti.virgin.net/c.gordon-smith/
Email Address: Please see my Home Page

Anonymous

  • Guest
Lazarus and C++ ?
« Reply #5 on: January 07, 2004, 03:55:18 pm »
Unfortunately FPC uses the Delphi-compatible RTTI format for classes. This is a propriety format which g++ cannot use.

Whilst you can link the object code into c++, you cannot make use of the classes because g++ will not be able to understand the  RTTI. In the same wya, FPC cannot use c++ classes because it does not understand the c++ format for classes.

Remember the lcl is class based - you are not accessing a library of discrete functions so no amount of fiddling is going to make it work without a change to the g++ compiler to support RTTI.

chris.gordon-smith

  • New Member
  • *
  • Posts: 12
    • http://graffiti.virgin.net/c.gordon-smith/index.html
Lazarus and C++ ?
« Reply #6 on: January 09, 2004, 01:20:39 am »
I think that integrating Lazarus with code written for C++ Builder is essentially a matter of establishing a calling interface between these two environments. It may well be that establishing an interface that could cope with classes and the calling of methods of classes (as opposed to simply calling non object-oriented functions) could be problematic.

My answer to this would be: Use a simple 'low tech' function based interface between the two environments, but then build a wrapper layer on both sides of the interface to convert between the 'low tech' interface to the class based interface expected by the Lazarus code and the C++ Builder code.

For example, if I have a TForm object for which I want to invoke the Show method, I could write the following C++ code:-

My_Form_Ptr->Show();

In my C++ environment, I would have a definition of the TForm::Show() function that would call another function like this:-

TForm_Show(My_Form_Ptr);

Tform_Show would be a Pascal non member function . This function would then call TForm::Show within the Pascal environment.

The above requires some change to existing C++ Builder code, but I believe that these would be limited in scope, and very simple in nature. Really just a conversion from one syntax to another.

I'm not sure whether it would matter having different   declarations for the TForm class in both environments. If so, the answer would be to use different names in the two environments. Preferably by using a namespace, but if essential by renaming the class in the C++ environment to something like TForm_CPP.

Chris Gordon-Smith
London
Homepage: http://graffiti.virgin.net/c.gordon-smith/
Email Address: Please see my Home Page

 

TinyPortal © 2005-2018