[fpc-pascal] DLL and SO with Free Pascal
Hi All, excuse me if I have included the code, but I really need help. I have: 1) spa.c (coded in ANSI C) which compiled with mingw produces "spa.dll", and compiled with gcc produces a "libspa.so" under Linux. 2) myDelphi.dpr (a delphi project) uses "spa.dll" and works fine. 3) myFpc.pp (a FP project under windows) uses "spa.dll" and works fine. 4) myC.c (a C project under Linux) uses "libspa.so" and works fine. 5) myFpc.pp (a FP project under Linux -- same code as 3) uses "libspa.so" gives many troubles. This is the C header file: #ifndef __solar_position_algorithm_header #define __solar_position_algorithm_header //enumeration for function codes to select desired final outputs from SPA enum { SPA_ZA, //calculate zenith and azimuth SPA_ZA_INC, //calculate zenith, azimuth, and incidence SPA_ZA_RTS, //calculate zenith, azimuth, and sun rise/transit/set values SPA_ALL, //calculate all SPA output values }; typedef struct { //--INPUT VALUES int year;// 4-digit year,valid range: -2000 to 6000, error code: 1 int month; // 2-digit month, valid range: 1 to 12, error code: 2 int day; // 2-digit day, valid range: 1 to 31, error code: 3 int hour;// Observer local hour, valid range: 0 to 24, error code: 4 int minute; // Observer local minute, valid range: 0 to 59, error code: 5 int second; // Observer local second, valid range: 0 to 59, error code: 6 float delta_t; // Difference between earth rotation time and terrestrial time // (from observation) // valid range: -8000 to 8000 seconds, error code: 7 float timezone; // Observer time zone (negative west of Greenwich) // valid range: -12 to 12 hours, error code: 8 float longitude; // Observer longitude (negative west of Greenwich) // valid range: -180 to 180 degrees, error code: 9 float latitude; // Observer latitude (negative south of equator) // valid range: -90 to 90 degrees, error code: 10 float elevation; // Observer elevation [meters] // valid range: -650 or higher meters, error code: 11 float pressure; // Annual average local pressure [millibars] // valid range:0 to 5000 millibars, error code: 12 float temperature; // Annual average local temperature [degrees Celsius] // valid range: -273 to 6000 degrees Celsius, error code; 13 float slope; // Surface slope (measured from the horizontal plane) // valid range: -360 to 360 degrees, error code: 14 float azm_rotation; // Surface azimuth rotation (measured from south to projection of // surface normal on horizontal plane, negative west) // valid range: -360 to 360 degrees, error code: 15 float atmos_refract; // Atmospheric refraction at sunrise and sunset (0.5667 deg is typical) // valid range: -10 to 10 degrees, error code: 16 int function;// Switch to choose functions for desired output (from enumeration) //-Intermediate OUTPUT VALUES double jd; //Julian day double jc; //Julian century double jde; //Julian ephemeris day double jce; //Julian ephemeris century double jme; //Julian ephemeris millennium double l; //earth heliocentric longitude [degrees] double b; //earth heliocentric latitude [degrees] double r; //earth radius vector [Astronomical Units, AU] double theta; //geocentric longitude [degrees] double beta;//geocentric latitude [degrees] double x0; //mean elongation (moon-sun) [degrees] double x1; //mean anomaly (sun) [degrees] double x2; //mean anomaly (moon) [degrees] double x3; //argument latitude (moon) [degrees] double x4; //ascending longitude (moon) [degrees] double del_psi; //nutation longitude [degrees] double del_epsilon; //nutation obliquity [degrees] double epsilon0;//ecliptic mean obliquity [arc seconds] double epsilon; //ecliptic true obliquity [degrees] double del_tau; //aberration correction [degrees] double lamda; //apparent sun longitude [degrees] double nu0; //Greenwich mean sidereal time [degrees] double nu; //Greenwich sidereal time [degrees] double alpha; //geocentric sun right ascension [degrees] double delta; //geocentric sun declination [degrees] double h; //observer hour angle [degrees] double xi; //sun equatoria
Re: [fpc-pascal] DLL and SO with Free Pascal
const spaDLL = 'spa.dll'; I mean here: const spaDLL = 'libspa.so'; //Calculate SPA output values (in structure) based on input values passed in structure function spa_calculate(PRec: PSpaData): integer; cdecl; external spaDLL; implementation end. seen the problem exists only under Linux. jk -- Jilani KHALDI http://jkhaldi.oltrelinux.com ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] DLL and SO with Free Pascal
On Sun, 9 Apr 2006, Jilani Khaldi wrote: > Hi All, > excuse me if I have included the code, but I really need help. > I have: > 1) spa.c (coded in ANSI C) which compiled with mingw produces "spa.dll", and > compiled with gcc produces a "libspa.so" under Linux. > 2) myDelphi.dpr (a delphi project) uses "spa.dll" and works fine. > 3) myFpc.pp (a FP project under windows) uses "spa.dll" and works fine. > 4) myC.c (a C project under Linux) uses "libspa.so" and works fine. > 5) myFpc.pp (a FP project under Linux -- same code as 3) uses "libspa.so" > gives many troubles. It would be helpful if you could tell what exactly the problem is. But from first glance, you need at least to add {$mode objfpc} or {$mode delphi} so integer is 32-bit instead of 16 bit. Secondly, normally you should add a {$packrecords C} directive to ensure record alignment compatible with C. Michael. > > This is the C header file: > > # ifndef __solar_position_algorithm_header > # define __solar_position_algorithm_header > //enumeration for function codes to select desired final outputs from SPA > enum { > SPA_ZA, //calculate zenith and azimuth > SPA_ZA_INC, //calculate zenith, azimuth, and incidence > SPA_ZA_RTS, //calculate zenith, azimuth, and sun > rise/transit/set values >SPA_ALL, //calculate all SPA output values > }; > > typedef struct > { > //--INPUT VALUES > >int year;// 4-digit year,valid range: -2000 to 6000, error > code: 1 >int month; // 2-digit month, valid range: 1 to 12, error > code: 2 >int day; // 2-digit day, valid range: 1 to 31, error > code: 3 >int hour;// Observer local hour, valid range: 0 to 24, error > code: 4 >int minute; // Observer local minute, valid range: 0 to 59, error > code: 5 >int second; // Observer local second, valid range: 0 to 59, error > code: 6 > >float delta_t; // Difference between earth rotation time and > terrestrial time > // (from observation) > // valid range: -8000 to 8000 seconds, error > code: 7 > > float timezone; // Observer time zone (negative west of Greenwich) > // valid range: -12 to 12 hours, error code: 8 > > float longitude; // Observer longitude (negative west of Greenwich) > // valid range: -180 to 180 degrees, error code: 9 > > float latitude; // Observer latitude (negative south of equator) > // valid range: -90 to 90 degrees, error code: 10 > > float elevation; // Observer elevation [meters] > // valid range: -650 or higher meters,error > code: 11 > > float pressure; // Annual average local pressure [millibars] > // valid range:0 to 5000 millibars, error > code: 12 > >float temperature; // Annual average local temperature [degrees Celsius] > // valid range: -273 to 6000 degrees Celsius, error > code; 13 > >float slope; // Surface slope (measured from the horizontal plane) > // valid range: -360 to 360 degrees, error code: 14 > >float azm_rotation; // Surface azimuth rotation (measured from south to > projection of > // surface normal on horizontal plane, negative > west) > // valid range: -360 to 360 degrees, error code: 15 > >float atmos_refract; // Atmospheric refraction at sunrise and sunset > (0.5667 deg is typical) > // valid range: -10 to 10 degrees, error code: 16 > >int function;// Switch to choose functions for desired output (from > enumeration) > >//-Intermediate OUTPUT VALUES > > double jd; //Julian day > double jc; //Julian century > > double jde; //Julian ephemeris day > double jce; //Julian ephemeris century > double jme; //Julian ephemeris millennium > > double l; //earth heliocentric longitude [degrees] > double b; //earth heliocentric latitude [degrees] > double r; //earth radius vector [Astronomical Units, AU] > > double theta; //geocentric longitude [degrees] > double beta;//geocentric latitude [degrees] > > double x0; //mean elongation (moon-sun) [degrees] > double x1; //mean anomaly (sun) [degrees] > double x2; //mean anomaly (moon) [degrees] > double x3; //argument latitude (moon) [degrees] > double x4; //ascending longitude (moon) [degrees] > > double del_psi; //nutation longitude [degrees] > double del_epsilon; //nutation obliquity [degrees] > double epsilon0;//ecliptic mean obliquity [arc seconds] > double epsilon; //ecliptic true obliquity [degrees] > > double del_tau; //aberration correction [degrees] > double lamda; //apparent sun longitude [degrees] > double n
Re: [fpc-pascal] DLL and SO with Free Pascal
It would be helpful if you could tell what exactly the problem is. But from first glance, you need at least to add {$mode objfpc} or {$mode delphi} so integer is 32-bit instead of 16 bit. Secondly, normally you should add a {$packrecords C} Thank you very much Michael, you hint to add "{$packrecords C}" fixes the problem. Just curious. I tried: SpaData = packed record ... end; instead of: SpaData = record ... end; But it doesn't solve the problem. jk -- Jilani KHALDI http://jkhaldi.oltrelinux.com ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] DLL and SO with Free Pascal
On Sun, 9 Apr 2006, Jilani Khaldi wrote: > > > It would be helpful if you could tell what exactly the problem is. > > > > But from first glance, you need at least to add {$mode objfpc} or {$mode > > delphi} > > so integer is 32-bit instead of 16 bit. Secondly, normally you should > > add a {$packrecords C} > > > > > Thank you very much Michael, you hint to add "{$packrecords C}" fixes the > problem. > Just curious. I tried: > SpaData = packed record > ... > end; > > instead of: > SpaData = record > ... > end; > > But it doesn't solve the problem. No, because C doesn't use the 'packed record'. It uses a special alignment algorithm, which is imitated by $PACKRECORDS C Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] When are used units recompiled? (wiki page added)
Tom Verhoeff ha scritto: This makes it much less attractive to release units without source code. That may be understandable from an open-source perspective, but in teaching I find it useful or even necessary to provide units without source code. IN TEACHING? Btw. no sane commercial Delphi developer has ever considered using a component without source code at least since Delphi 2.0. Look at the offering of component vendors and you will see that they invariably offer source code licenses. Giovanni ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal