Einen in C geschriebenen Code in FPC ein zu binden ist erfolgreich abgehackt, nun versuche ich mich in der anderen Richtung und kamme aktuell nicht weiter.
Bassierend auf diesem Thread: viewtopic.php?t=9198 muss es ja prinzipiell gehen.
Also habe ich mir erst mal eine Unit gebastelt, welche der Zukünftige C-Code einbinden / ausführen soll:
Code: Alles auswählen
Unit ufpc_to_c;
Interface
uses ctypes;
Function fpc_add(a: cuint16; b: cuint16): cuint16; cdecl; public name{$IFDEF CPU64} 'fpc_add'{$ELSE} '_fpc_add'{$ENDIF};
Implementation
Function fpc_add(a: cuint16; b: cuint16): cuint16; cdecl;
Begin
result := a + b;
End;
End.
Damit ich das ganze testen kann brauche ich noch die angehängte main.c und eine passende .h Datei:
Code: Alles auswählen
// -------------------------------------------------- ufpc_to_c.h
#ifndef __UFPC_TO_C_H
#define __UFPC_TO_C_H
#include <stdint.h>
uint16_t fpc_add(uint16_t a, uint16_t b);
#endif
// -------------------------------------------------- main.c
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "ufpc_to_c.h"
int main(void)
{
printf("Demo Application to include FPC-source into a C project\n");
uint16_t a = 20;
uint16_t b = 22;
uint16_t c;
c = fpc_add(a,b);
printf("The one and only answer is %d\n", c);
printf("finished, going down now.\n");
return 0;
}
1. erzeugen der main.o mittels
2. zusammenfügen der beiden .o Dateien zu einem executablegcc -c main.c
Aber anstatt mir das .exe file zu erzeugen bekomme folgende Fehlermeldung:gcc -o test.exe main.o ufpc_to_c,o
Das internet sagt dazu folgendes:$ gcc -o test.exe main.o ufpc_to_c.o
/usr/lib/gcc/x86_64-pc-cygwin/10/../../../../x86_64-pc-cygwin/bin/ld: error: 0-bit reloc in dll
collect2: error: ld returned 1 exit status
=> irgendwas mache ich noch falsch, aber was und wie repariere ich es ?The error message is produced when the linker is attempting to
translate the relocations in the input files into the PE required
format and it encounters a relocation type that it does not
recognise. In this case it would appear that the linker is
encountering a null reloc. (ie one that has already been processed).