|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. Its your move---enter to win here! |
|
#1
|
|||
|
|||
|
Cross-language development
I am trying to move some of my Delphi code to C for speeding it up as time (and my boss) doesnīt allow porting the whole project.
I did something similar already years ago with Turbo Pascal and C, iirc then i linked the Pascal file against the C compilerīs .o file and i could use the functions. (It was Turbo C then, maybe this is why it did work?) Now i am using Delphi and DevCPP (gcc 2.9x). What i am trying is: Code:
Delphi:
program pTest_C_Lib;
{$APPTYPE CONSOLE}
{$LINK libtest.o}
function Test(m:Integer):Integer; stdcall; external 'libtest.o';
begin
Test(10);
Readln;
end.
And Code:
C:
#include <stdio.h>
int test(int max) {
int i;
for (i=0;i<max;i++) {
printf("Test %d",i);
}
return 0;
}
for testing. But when compiling, Delphi keeps telling me that the .o file is in the wrong format. DevCPP is setup for making a static library. (i also get the libXXXXX.a file, but i have no idea how to import this to Delphi) Am i doing something wrong or did things change so that this way is not possible anymore? Do i really have to make a .DLL of it? (i donīt want to... but if you tell me that i have to, i will )Tia, M.Hirsch
__________________
-- Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more. |
|
#2
|
||||
|
||||
|
>> I am trying to move some of my Delphi code to C for speeding it up as time (and my boss) doesnīt allow porting the whole project.
Can you just convince your boss that Delphi uses a Borland C++ compiler in the back-end. Delphi's compiler doesn't produce the fastest code ever, but it's not too bad. IIRC, Visual C++ and Intel's C++ compiler produce better optimized and faster code, but they take longer to compile as well. IIRC most C compilers generate obj files in COFF format, but Delphi uses a different format for its obj files, so you can only use borland C++ and C++ builder (this info is old, so you may be able to use other compilers now). Anyways, here's a small tutorial on how to link C object files with delphi: http://rvelthuis.bei.t-online.de/ar...icles-cobjs.htm BTW, here are some links showing the relative performances of different C++ compilers (note that gcc 2.95 is known to be slower than gcc 3.x series) : http://www.open-mag.com/754088105111.htm http://www.coyotegulch.com/reviews/...gcc_bench1.html http://www.realworldtech.com/page.c...RWT071302231228 <-- has delphi in the tests also. http://www.willus.com/ccomp_benchmark.shtml Hope this helps ![]() Last edited by Scorpions4ever : March 9th, 2003 at 03:04 PM. |
|
#3
|
|||
|
|||
|
Thank you very much.
Iīll try that tomorrow, tonight itīs already too late. Scorpions, just in case you are interested - this is still the same project i asked for algorithms and other stuff earlier... my 3D engine. I have a hard time convincing my boss to convert to C because he also knows some basic delphi and he wants to "keep control" of the project itīs not always logic that makes projects go the way they go... i fear it seldomly is...iīm up to moving all speed critical functions to C (C++) now and use the STL as you suggested. Hope my collision detection routines will perform better then. If not, i still have the option of optimizing the C code which i can profile (i didnīt find a way yet to profile Delphi code...) Next thing will be finding common data structures for C and Delphi. Iīm already looking forward to this but i have some links, so i am confident this will be done in a few hours...Iīll convert to gcc3 soon, after i found out about the differences (i have some urls about that, just didnīt find the time yet to read.) Again, thanks vm. Iīll keep you up to date about my progress... |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > Cross-language development |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|