Prev: Dhrystone
Next: Learning Ada
From: Ada novice on 25 Jul 2010 13:40 On Jul 25, 7:06 pm, "Dmitry A. Kazakov" <mail...(a)dmitry-kazakov.de> wrote: > C files or library files? > With library files (import or object) it is simpler > > (If you have only a shared library then it would require a bit more work.) > It's a library file in IMSL named imslcmath_dll.lib To use IMSL C library there are 2 steps: 1. Specify the location of the IMSL header files. It's an "include" directory in the IMSL directory 2. Add the actual IMSL C library to the project. This IMSL C library is called imslcmath_dll.lib which is in a "lib" directory in the IMSL directory. There are other lib files, but this one is used for numerical tasks. I'm able to do the above easily with MVS2008/2010. The first step is adding the "include" directory under Project > Configuration Properties > C/C++ > General. The second step is hust Project > Add existing item. I have only limited experience with GPS but let's give it a try: First I add create a folder and put the file imsl.ads, imsl.adb and main_ada_file.adb (my testmatrix.adb). Then I create a project gpr, specifying the main file and the source directory (containing our 3 files). Then according to my step 1 from above, I add the folder "include" from IMSL as also a source directory. So now I have 2 source directories. Then for step 2, I need to add the imslcmath_dll.lib file? How do I do that in GPS? I can compile all 3 files imsl.ads, imsl.adb, main_ada_file.adb in GPS. Then how do I proceed? How do I do this in GPS: > gnatmake main_ada_file.adb --largs library_file.lib > Sorry if I'm not that good enough to understand your explanations quickly. Thanks for your kind help and patience. YC
From: Ada novice on 25 Jul 2010 13:42 On Jul 25, 7:06 pm, "Dmitry A. Kazakov" <mail...(a)dmitry-kazakov.de> wrote: > C files or library files? > With library files (import or object) it is simpler > (If you have only a shared library then it would require a bit more work.) It's a library file in IMSL named imslcmath_dll.lib To use IMSL C library there are 2 steps: 1. Specify the location of the IMSL header files. It's an "include" directory in the IMSL directory. 2. Add the actual IMSL C library to the project. This IMSL C library is called imslcmath_dll.lib which is in a "lib" directory in the IMSL directory. There are other lib files, but this one is used for numerical tasks. I'm able to do the above easily with MVS2008/2010. The first step is adding the "include" directory under Project > Configuration Properties > C/C++ > General. The second step is just Project > Add existing item. I have only limited experience with GPS but let's give it a try: First I create a folder and put the file imsl.ads, imsl.adb and main_ada_file.adb (my testmatrix.adb). Then I create a project gpr, specifying the main file and the source directory (containing our 3 files). Then according to my step 1 from above, I add the folder "include" from IMSL as also a source directory. So now I have 2 source directories. Then for step 2, I need to add the imslcmath_dll.lib file? How do I do that in GPS? I can compile all 3 files imsl.ads, imsl.adb, main_ada_file.adb in GPS. Then how do I proceed? How do I do this in GPS: > gnatmake main_ada_file.adb --largs library_file.lib Sorry if I'm not that good enough to understand your explanations quickly. Thanks for your kind help and patience. YC
From: Simon Wright on 25 Jul 2010 13:47 Simon Wright <simon(a)pushface.org> writes: > You don't need to use "-c". Try just > > gnatmake testmatrix.adb > > It'll compile testmatrix.adb and imsl.adb for you, do the bind, and try > to do the link, but you'll get a linker error because it can't find > imsl_f_eig_gen. > > Above, you wrote a C test: [...] > and when you built that you must have told GCC where to find the IMSL > library: something like the "-limsl" below. > > gcc testprogram.c -o testprogram -limsl > > You can do exactly the same with gnatmake: > > gnatmake testmatrix.adb -largs -limsl Of course, the above are all command-line-oriented and rather Unix-y at that. Sorry I don't know how to deal with .lib files and .dlls, and can't check any suggestions I might make out because I'm not running on Windows ... I suspect others will be able to help more.
From: Ada novice on 25 Jul 2010 13:58 On Jul 25, 7:47 pm, Simon Wright <si...(a)pushface.org> wrote: > Of course, the above are all command-line-oriented and rather Unix-y at > that. Sorry I don't know how to deal with .lib files and .dlls, and > can't check any suggestions I might make out because I'm not running on > Windows ... I suspect others will be able to help more. Thanks. Yes it'll be hard to do these things on the command line I suppose. I hope as you said to get some help from some Windows guys here... YC
From: Dmitry A. Kazakov on 25 Jul 2010 14:26
On Sun, 25 Jul 2010 10:40:09 -0700 (PDT), Ada novice wrote: > On Jul 25, 7:06�pm, "Dmitry A. Kazakov" <mail...(a)dmitry-kazakov.de> > wrote: >> C files or library files? > >> With library files (import or object) it is simpler >> > >> (If you have only a shared library then it would require a bit more work.) >> > > It's a library file in IMSL named imslcmath_dll.lib > > To use IMSL C library there are 2 steps: > > 1. Specify the location of the IMSL header files. It's an "include" > directory in the IMSL directory You do not need include files > 2. Add the actual IMSL C library to the project. This IMSL C library > is called imslcmath_dll.lib which is in a "lib" directory in the IMSL > directory. There are other lib files, but this one is used for > numerical tasks. > > I'm able to do the above easily with MVS2008/2010. The first step is > adding the "include" directory under Project > Configuration > Properties > C/C++ > General. The second step is hust Project > Add > existing item. > > > I have only limited experience with GPS but let's give it a try: > > First I add create a folder and put the file imsl.ads, imsl.adb and > main_ada_file.adb (my testmatrix.adb). Then I create a project gpr, > specifying the main file and the source directory (containing our 3 > files). > > Then according to my step 1 from above, I add the folder "include" > from IMSL as also a source directory. So now I have 2 source > directories. > > Then for step 2, I need to add the imslcmath_dll.lib file? How do I do > that in GPS? I can compile all 3 files imsl.ads, imsl.adb, > main_ada_file.adb in GPS. Then how do I proceed? > > How do I do this in GPS: --------------------- imsl.ads with Interfaces.C; use Interfaces.C; package IMSL is type Float_Matrix is -- Row-wise, packed/aligned array (Positive range <>, Positive range <>) of C_Float; pragma Convention (C, Float_Matrix); type F_Complex is record Re : C_Float; Im : C_Float; end record; pragma Convention (C, F_Complex); type Complex_Array is array (Positive range <>) of F_Complex; pragma Convention (C, Complex_Array); function F_Eig_Gen (Matrix : Float_Matrix) return Complex_Array; end IMSL; -------------------------- imsl.adb with Interfaces.C; use Interfaces.C; with System; use System; package body IMSL is procedure Free (Ptr : System.Address); pragma Import (C, Free, "free"); function F_Eig_Gen (Matrix : Float_Matrix) return Complex_Array is begin if Matrix'Length (1) /= Matrix'Length (2) then raise Constraint_Error; end if; declare function imsl_f_eig_gen (N : Int; A : Address; Terminator : Address := Null_Address) return Address; pragma Import (C, imsl_f_eig_gen, "imsl_f_eig_gen"); Ptr : Address := imsl_f_eig_gen ( Matrix'Length (1), Matrix ( Matrix'First (1), Matrix'First (2) )' Address ); Data : Complex_Array (1..Matrix'Length (1)); for Data'Address use Ptr; pragma Import (Ada, Data); Result : Complex_Array := Data; -- Copy, we don't own that memory begin Free (Ptr); return Result; end; end F_Eig_Gen; end IMSL; ------------------------------------ imsl.gpr project IMSL is for Source_Files use ("imsl.adb", "imsl.ads"); package Linker is for Default_Switches ("ada") use ("imslcmath_dll.lib"); end Linker; end IMSL; ----------------------------------- test.adb with Ada.Text_IO; use Ada.Text_IO; with IMSL; use IMSL; with Interfaces.C; use Interfaces.C; procedure Test is Values : Complex_Array := F_Eig_Gen ( ( ( 8.0,-1.0,-5.0), (-4.0, 4.0,-2.0), (18.0,-5.0,-7.0) ) ); begin for Index in Values'Range loop Put_Line ( '(' & C_Float'Image (Values (Index).Re) & " ," & C_Float'Image (Values (Index).Im) & ')' ); end loop; end Test; ------------------------------------ test.gpr with "imsl.gpr"; project Test is for Source_Files use ("test.adb"); for Main use ("test.adb"); package Linker renames IMSL.Linker; end Test; put "imslcmath_dll.lib into the same directory or change its path in the project files. Make sure that the DLL is in the search path when you start the program. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de |