Ada 83 File in C++ als Shared Object laden



  • Die Überschrift sagt schon alles was ich machen will...

    funktioniert das??

    Ich will eine Ada-Datei (Ada 83) in der Funktionen sind die ich benötige also Shared Object kompilieren.

    Dieses Shared Objekt will ich dann in C++ einbinden und auf die Funktionen zugreifen.

    Hat jemand das schon mal gemacht?

    Shared Object laden unter Linux is klar... mir geht es nur darum... ob das überhaupt möglich ist... bzw wie der Zugriff dann auf die Funktionen in der .so file aussieht... bzw sind das dann .so files?? und kann die Datei mit dlopen geladen werden und mit dlsym ein Handle auf die Funktion gesetzt werden?

    mfg ufo



  • Dieser Thread wurde von Moderator/in HumeSikkins aus dem Forum C++ in das Forum Linux/Unix verschoben.

    Im Zweifelsfall bitte auch folgende Hinweise beachten:
    C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?

    Dieses Posting wurde automatisch erzeugt.



  • Hallo,

    ich habe das ganze mal vor Jahren mit C probiert. Hier meine Files:

    lib.h

    int c_func(int i);
    

    lib.c

    #include "lib.h"
    
    int c_func(int i) {
    
      return ++i;
    
    }
    

    lib_ada.ads

    package Lib_Ada is
    
       function C_Function(I : in Integer) return Integer;
       pragma Import(C, C_Function, "c_func");
    
    end Lib_Ada;
    

    main.adb

    with Text_Io;
    with Lib_Ada;
    
    procedure Main is
    
       package Int_Io is new Text_Io.Integer_Io(Integer);
    
       Result : Integer;
    
    begin
    
       Result := Lib_Ada.C_Function(1);
       Int_Io.Put(Result);
    
    end;
    

    README

    C_TO_ADA_INTERFACE
    
    Description:
    This is an example for an Ada program that uses a C function.
    
    Files:
    main.adb    -- Ada main/program file
    lib_ada.ads -- Ada library that imports the C function
    lib.c       -- C source file 
    
    Remarks:
    1. First complice the C source with => gcc -c lib.c
    2. Build the executable with => gnatmake main.adb -largs lib.o
    
    The C source file has to be named <file>.c not <file>.cpp, because of 
    linker problems with C++ files.
    

    Ob man die Linkerprobleme mit C++ (siehe README) lösen kann, kann ich dir leider nicht beantworten. Soweit gingen meine Tests dann nicht.

    Gruß, Chris



  • Und die andere Richtung... (wer lesen kann ist klar im Vorteil ... ;))

    main.c

    #include <stdio.h>
    
    extern int my_function (void);
    extern void my_proc (void);
    
    int main(int argc, char *argv[])
    {
      int i = 0;
    
      i = my_function ();
      printf("Value %d\n", i);
      my_proc ();
      return (0);
    }
    
    with Interfaces.C;
    
    package Lib is
    
       function My_Function return Interfaces.C.int;
       pragma Export(C, My_function, "my_function");
    
       procedure My_Procedure;
       pragma Export(C, My_Procedure, "my_proc");
    
    end Lib;
    

    lib.ads

    with Text_Io;
    
    package body Lib is
    
       -----------------
       -- My_Function --
       -----------------
    
       function My_Function return Interfaces.C.int is
       begin
          return 1;
       end My_Function;
    
       procedure My_Procedure is
       begin
         Text_Io.Put_Line("Hallo, C. Hier Ada.");
       end My_Procedure;
    
    end Lib;
    

    lib.adb

    ADA_TO_C_INTERFACE
    
    Description:
    This is an example for an C program that uses an Ada function.
    
    Files:
    main.c    -- C main/program file
    lib.ads   -- Ada library spec that exports the function
    lib.adb   -- Ada library body source file 
    
    Remarks:
    1. First compile the Ada source with => gnatmake -c lib
    2. Second compilde the C source with => gcc -c main.o
    3. Build the executable with => gcc -o main main.o lib.o
    

    Ob das ganze auch mit Shared Ada Objects geht hab ich noch nicht probiert.

    Gruß, Chris



  • danke chris, jedoch bringt er mir bei der Variante ADA in C

    folgende Fehlermeldung beim compilieren

    ada/adatoc> gcc -o main main.o lib.o
    lib.o: In function my_proc': lib.o(.text+0x20): undefined reference toada__text_io__put_line__2'
    collect2: ld returned 1 exit status
    ada/adatoc>

    hast du nen Tip?
    die Variante C to Ada funzt.. er wirft 2 raus

    thx UFO

    p.s.

    die Beschriftung der Dateien muss bei deinem zweiten Post so lauten oder?

    main.c
    lib.ads
    lib.adb
    readme

    net das ich da was falsch zugeordnet habe


Anmelden zum Antworten