Re: [fpc-pascal] How to use external linker on windows i386

2024-06-06 Thread Ondrej Pokorny via fpc-pascal

On 06.06.2024 11:16, Sven Barth via fpc-pascal wrote:
Ondrej Pokorny via fpc-pascal  
schrieb am Do., 6. Juni 2024, 09:30:


Hello,

I am on Windows 64bit, but using the i386 compiler.

I have to link a 3rd party OBJ file with {$L 'xyz.obj'}.

With the internal linker I get these errors:
Error: COMDAT selection mode 0 not supported (section: "0")
Error: Failed reading coff file, invalid section index while
reading xyz.obj
Error: Associative COMDAT section for section ".rdata" not found


Can you provide a small example as a bug report that shows this 
behavior (preferably also with source for the object file) so that we 
can improve the internal linker?



So I tried to use the external linker with -Xe and I get these errors:
Linking myProgram.exe
ld: warning: directory not found for option '-L/usr/lib'
ld: warning: directory not found for option
'-F/System/Library/Frameworks/'
ld: warning: option -b is obsolete and being ignored
ld: file not found: pei-i386
Error: Error while linking


That reads like the compiler is picking up the wrong linker (a WSL one 
perhaps?). The ld.exe (probably with platform prefix) should already 
be located in the compiler's binary directory and PATH needs to point 
to that first.


Thank you Sven for the help!

I changed the PATH so that the FPC bin directory is the first entry and 
the output indeed changed: I get only "Error: Error while linking" 
output without additional information that I got before.


Furthermore, I see from the docs that the -XR isn't supported on Windows 
(https://www.freepascal.org/docs-html/user/userap1.html)
-XR Prepend  to all linker search paths (BeOS, Darwin, 
FreeBSD, Linux, Mac OS, Solaris)


Maybe it would be good to support it on Windows as well to be able to 
explicitly tell which linker to use.


Ondrej
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Ordinal casting to enums

2024-06-06 Thread Hairy Pixels via fpc-pascal
oh, it's writeln which is doing the runtime check, thanks. Doing math on enums 
is probably not a smart idea though. I wonder why a subscript like [] was never 
added to enums. It would be nice to do:

f := Fruit[banana.index + 1];

instead of dealing with raw values. A runtime check for creating enums was 
ordinals would be smart also, like:

f := Fruit.Create(10);

instead of blindly cast ordinals to enums which may be invalid.

> On Jun 6, 2024, at 2:33 PM, Ondrej Pokorny  wrote:
> 
> To find out, compile FPC with debug info and step into the writeln() call 
> with F7 (multiple times until you get into fpc_shortstr_enum_intern()):
> 
> #0 FPC_SHORTSTR_ENUM_INTERN(4284424, 4284488, POINTER(nil), 
> POINTER($00326000), , 12) at sstrings.inc:575
> #1 fpc_write_text_enum(POINTER($00416008), POINTER($00416048), 0, TEXT (), 
> 12) at text.inc:1272
> #2 main at project1.lpr:16

Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] How to use external linker on windows i386

2024-06-06 Thread Sven Barth via fpc-pascal
Ondrej Pokorny via fpc-pascal  schrieb am
Do., 6. Juni 2024, 09:30:

> Hello,
>
> I am on Windows 64bit, but using the i386 compiler.
>
> I have to link a 3rd party OBJ file with {$L 'xyz.obj'}.
>
> With the internal linker I get these errors:
> Error: COMDAT selection mode 0 not supported (section: "0")
> Error: Failed reading coff file, invalid section index while
> reading xyz.obj
> Error: Associative COMDAT section for section ".rdata" not found
>

Can you provide a small example as a bug report that shows this behavior
(preferably also with source for the object file) so that we can improve
the internal linker?


> So I tried to use the external linker with -Xe and I get these errors:
> Linking myProgram.exe
> ld: warning: directory not found for option '-L/usr/lib'
> ld: warning: directory not found for option '-F/System/Library/Frameworks/'
> ld: warning: option -b is obsolete and being ignored
> ld: file not found: pei-i386
> Error: Error while linking
>

That reads like the compiler is picking up the wrong linker (a WSL one
perhaps?). The ld.exe (probably with platform prefix) should already be
located in the compiler's binary directory and PATH needs to point to that
first.

Regards,
Sven
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Ordinal casting to enums

2024-06-06 Thread Ondrej Pokorny via fpc-pascal

On 06.06.2024 09:19, Ondrej Pokorny via fpc-pascal wrote:
writeln() converts the ordinal value to the value name and if the 
entry is not found, the 107 error is raised.


Ondrej

On 06.06.2024 06:22, Hairy Pixels via fpc-pascal wrote:

[ ... ]
how this works at runtime is another question.


To find out, compile FPC with debug info and step into the writeln() 
call with F7 (multiple times until you get into fpc_shortstr_enum_intern()):


#0 FPC_SHORTSTR_ENUM_INTERN(4284424, 4284488, POINTER(nil), 
POINTER($00326000), , 12) at sstrings.inc:575
#1 fpc_write_text_enum(POINTER($00416008), POINTER($00416048), 0, TEXT 
(), 12) at text.inc:1272

#2 main at project1.lpr:16

Ondrej

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Ordinal casting to enums

2024-06-06 Thread Ondrej Pokorny via fpc-pascal
writeln() converts the ordinal value to the value name and if the entry 
is not found, the 107 error is raised.


Ondrej

On 06.06.2024 06:22, Hairy Pixels via fpc-pascal wrote:

This program below crashes because the value 12 is not in the enum. I was curious though, 
how does it know this? Does it have to do a linear search through the enum to find the 
value? I know "succ" fails at compile time because the enum has assignments but 
how this works at runtime is another question.

type
   Fruit = (apple = 10,
banana,
pear = 20,
citrus);
var
   f: Fruit;
   i: Integer;
begin
   i := 12;
   f := Fruit(i);
   writeln(f);
end;

Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] How to use external linker on windows i386

2024-06-06 Thread Ondrej Pokorny via fpc-pascal

Hello,

I am on Windows 64bit, but using the i386 compiler.

I have to link a 3rd party OBJ file with {$L 'xyz.obj'}.

With the internal linker I get these errors:
Error: COMDAT selection mode 0 not supported (section: "0")
Error: Failed reading coff file, invalid section index while reading xyz.obj
Error: Associative COMDAT section for section ".rdata" not found

So I tried to use the external linker with -Xe and I get these errors:
Linking myProgram.exe
ld: warning: directory not found for option '-L/usr/lib'
ld: warning: directory not found for option '-F/System/Library/Frameworks/'
ld: warning: option -b is obsolete and being ignored
ld: file not found: pei-i386
Error: Error while linking

I searched for any information but couldn't find any help or tutorial 
how to setup the external linker.


I tried:
I downloaded the current mingw32 binaries and registered the search path 
with:

-Xe -XRp:\software\MinGW\mingw32\bin
But it didn't not help - still the same error.

Can anybody help please?
Delphi can link the OBJ file without problems.

Thanks
Ondrej

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal