C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old March 9th, 2003, 03:56 AM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,969 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 39 m 55 sec
Reputation Power: 184
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.

Reply With Quote
  #2  
Old March 9th, 2003, 02:45 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,442 Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 h 55 m 33 sec
Reputation Power: 797
>> 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.

Reply With Quote
  #3  
Old March 9th, 2003, 05:03 PM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,969 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 39 m 55 sec
Reputation Power: 184
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...

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Cross-language development


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway