Recent

Author Topic: Does lazarus can use c++ obj file?  (Read 6772 times)

halflifezy

  • Jr. Member
  • **
  • Posts: 61
Does lazarus can use c++ obj file?
« on: January 25, 2012, 07:50:01 am »
Does lazarus can use c++ obj file?
Is any tools can covert it?

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: Does lazarus can use c++ obj file?
« Reply #1 on: January 25, 2012, 10:00:41 am »
Does lazarus can use c++ obj file?
No. Everything is different: object implementation, name mangling, exception handling, run-time, etc, etc.
Is any tools can covert it?
No.
c++ libraries can be used with a c wrapper. See ftp://ftp.freepascal.org/fpc/docs-pdf/CinFreePascal.pdf for an example.

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3541
Re: Does lazarus can use c++ obj file?
« Reply #2 on: January 25, 2012, 10:14:41 am »
Well, actually you can use C++ object files, if they are compiled with GCC. You can call methods and functions. You wont be able to subclass, but with some hacking the basics could work.

@halflifezy: Please show the header to the C++ obj file. And with which compiler, assembler and linker was it built?

halflifezy

  • Jr. Member
  • **
  • Posts: 61
Re: Does lazarus can use c++ obj file?
« Reply #3 on: January 25, 2012, 11:51:16 am »
vc 2008 or c++ builder

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3541
Re: Does lazarus can use c++ obj file?
« Reply #4 on: January 25, 2012, 11:54:45 am »
Try adding this to see if it will link the object:

{$L MyObjectFile.o}

And where is the header file?

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: Does lazarus can use c++ obj file?
« Reply #5 on: January 25, 2012, 12:00:02 pm »
Well, actually you can use C++ object files, if they are compiled with GCC. You can call methods and functions. You wont be able to subclass, but with some hacking the basics could work.
Of course, with some hacking and a lot of luck. If an unhandled c++ exception bubbles up into fpc code your probably already out of luck (http://bugs.freepascal.org/view.php?id=12974). No header file will give you this information. For sure, you can also hack away that one and the issue gives some clues to it. A cpp managed data type (fe. cpp strings) in one of the functions? Again bad luck.
 
I just gave a general answer to a general question. From the question you can't tell what type of c++ object we are talking about. Is it just an .obj, a static  or a dynamic library?

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3541
Re: Does lazarus can use c++ obj file?
« Reply #6 on: January 25, 2012, 12:02:27 pm »
Yes, it is not optimal, but if someone has no other choice, and needs to use a proprietary API for a hardware or something like that it might be the only choice.

@halflifezy: What exactly are you trying to achieve? Are you sure that you can't do that without this object file?

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7495
Re: Does lazarus can use c++ obj file?
« Reply #7 on: January 25, 2012, 12:28:45 pm »
Yes, it is not optimal, but if someone has no other choice, and needs to use a proprietary API for a hardware or something like that it might be the only choice.

No, even then I think a C wrapper is the more sane route to go. Even if you want to let code in two two different C++ compilers communicate with each other you need that (*)


(*) stronger even, two sufficient different versions of the same compiler already count as different.

halflifezy

  • Jr. Member
  • **
  • Posts: 61
Re: Does lazarus can use c++ obj file?
« Reply #8 on: January 25, 2012, 02:20:01 pm »
om,i am sorry to hear it,
i only want to use the obj files,which
compile with vc 2008 or c++ builder.
maybe only a way to use it,take the codes
into a dll file.

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: Does lazarus can use c++ obj file?
« Reply #9 on: January 25, 2012, 03:32:55 pm »
Quote
maybe only a way to use it,take the codes
into a dll file.
You'll have the same problems as mentioned before.
The only advantages of a dll are that you are sure you can link with a dll while linking with VC object files isn't supported and that you don't have to figure out all the C++ libraries needed to link with FP code. The C++ build environment has done that for you.

Since you apparently have the C++ source code, creating a c wrapper is really the best solution. The link I provided earlier is a good starting point.