Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2015-06

FPC linking syntax error

11 messages · 5 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

patspiper

Hi,

Compiling the following simple program (from fpc prog manual http://www.freepascal.org/docs-html/prog/progsu46.html#x53-520001.2.46) yields a linking syntax error:

program Project1;
{$Linklib c}
Const P : PChar = 'This is fun !';
Function strlen (P: PChar): Longint; cdecl; external;
begin
   WriteLn ('Length of (',p,') : ',strlen(p))
end.
ppc386 program1.pp

Free Pascal Compiler version 3.1.1 [2015/06/06] for i386 Copyright (c) 1993-2015 by Florian Klaempfl and others Target OS: Linux for i386
Compiling program1.pp
Linking program1
/usr/bin/ld:link.res: file format not recognized; treating as linker script /usr/bin/ld:link.res:121: syntax error
program1.pp(8,1) Error: Error while linking
program1.pp(8,1) Fatal: There were 1 errors compiling module, stopping Fatal: Compilation aborted

Using 'ppc386 -s program1.pp' instead, line 121 of link.res is '-l c' in the section:
INPUT(
-l c
)

and the linker invocation line in ppas.sh is:
/usr/bin/ld -b elf32-i386 -m elf_i386
--dynamic-linker=/lib/ld-linux.so.2 -s -L. -o program1 link.res

Is this a bug?

Thanks,
Stephano

Reply by email

Marco van de Voort
to patspiper

In our previous episode, patspiper said:

Show quoted text 5 lines
Compiling the following simple program (from fpc prog manual http://www.freepascal.org/docs-html/prog/progsu46.html#x53-520001.2.46) yields a linking syntax error: Is this a bug?

Not of a general kind, since it works on most Linux distros. E.g. it works fine on my debian jessie 64-bit.

So it must be something particular to your Linux installation or distribution. So best is to tell something about that installation.

Reply by email

Stéphane Aulery
to Marco van de Voort

Hello,

Marco van de Voort wrote 12 lines
In our previous episode, patspiper said: > Compiling the following simple program (from fpc prog manual > http://www.freepascal.org/docs-html/prog/progsu46.html#x53-520001.2.46) > yields a linking syntax error: > Is this a bug? Not of a general kind, since it works on most Linux distros. E.g. it works fine on my debian jessie 64-bit. So it must be something particular to your Linux installation or distribution. So best is to tell something about that installation.

I had a similar discussion last April. See those two bug reports:

http://bugs.freepascal.org/view.php?id=27988
http://bugs.freepascal.org/view.php?id=27994

It might help you understand if the problem is the same or not.

Regards,

Stéphane Aulery

Reply by email

patspiper
to Marco van de Voort: In our previous episode, patspiper said: Not of a general kind, since it works on most…
Marco van de Voort wrote 10 lines
In our previous episode, patspiper said: > Compiling the following simple program (from fpc prog manual > http://www.freepascal.org/docs-html/prog/progsu46.html#x53-520001.2.46) > yields a linking syntax error: > Is this a bug? Not of a general kind, since it works on most Linux distros. E.g. it works fine on my debian jessie 64-bit. So it must be something particular to your Linux installation or distribution. So best is to tell something about that installation.

Ubuntu 11.04 32bit
fpc 3.0.1 and 3.1.1 (not sure which rev but max 2 weeks old) ld version: GNU ld (GNU Binutils for Ubuntu) 2.21.0.20110327

Stephano

Reply by email

Mark Morgan Lloyd
to patspiper
patspiper wrote 16 lines
On 21/06/15 14:58, Marco van de Voort wrote: > In our previous episode, patspiper said: >> Compiling the following simple program (from fpc prog manual >> http://www.freepascal.org/docs-html/prog/progsu46.html#x53-520001.2.46) >> yields a linking syntax error: >> Is this a bug? > Not of a general kind, since it works on most Linux distros. E.g. it > works > fine on my debian jessie 64-bit. > > So it must be something particular to your Linux installation or > distribution. So best is to tell something about that installation. Ubuntu 11.04 32bit fpc 3.0.1 and 3.1.1 (not sure which rev but max 2 weeks old) ld version: GNU ld (GNU Binutils for Ubuntu) 2.21.0.20110327

Can you try with a different linker version? I've previously had problems with ld 2.21 on SPARC Solaris which apparently is acknowledged as a bad build, I was able to work round them to some extent by giving fpc an option like -k-T/some_path_here/ldscripts/elf32_sparc.x

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

patspiper
to Marco van de Voort: In our previous episode, patspiper said: Not of a general kind, since it works on most…
Marco van de Voort wrote 10 lines
In our previous episode, patspiper said: > Compiling the following simple program (from fpc prog manual > http://www.freepascal.org/docs-html/prog/progsu46.html#x53-520001.2.46) > yields a linking syntax error: > Is this a bug? Not of a general kind, since it works on most Linux distros. E.g. it works fine on my debian jessie 64-bit. So it must be something particular to your Linux installation or distribution. So best is to tell something about that installation.

- I tried to link manually using the fpc produced link.res and got the same error.

- I removed the section INPUT(-l c) from link.res and linked manually (adding -lc as an option):
/usr/bin/ld -b elf32-i386 -m elf_i386
--dynamic-linker=/lib/ld-linux.so.2 -L. -lc -o program1 link.res Success!

I changed the following part in link.res:
INPUT(
-l c
)
to
INPUT(
-lc
)
and manual linking works!

So the issue is fpc producing link.res with a -l c instead of -lc. Which program specifically produces link.res?

Note: Newer ld built from source produces the same results.

Stephano

Reply by email

patspiper
to Jonas Maebe: I think that should be "-lc", not "-l c". I don't know where the extra space is coming…
Jonas Maebe wrote 8 lines
On 21/06/15 11:28, patspiper wrote: > Using 'ppc386 -s program1.pp' instead, line 121 of link.res is '-l c' in > the section: > INPUT( > -l c > ) I think that should be "-lc", not "-l c". I don't know where the extra space is coming from in your case.

Exactly!

I have just posted a message with my findings. Which program produces link.res?

Stephano

Reply by email

Marco van de Voort
to patspiper: Exactly! I have just posted a message with my findings. Which program produces link.res?…

In our previous episode, patspiper said:

Show quoted text 9 lines
>> INPUT( >> -l c >> ) > I think that should be "-lc", not "-l c". I don't know where the extra > space is coming from in your case. Exactly! I have just posted a message with my findings. Which program produces link.res?

Maybe the problem is the $linklib line in your example? Some an extra (shift-?) space that isn't stripped but output to the linklib?

Reply by email

patspiper
to Marco van de Voort
Marco van de Voort wrote 12 lines
In our previous episode, patspiper said: >>> INPUT( >>> -l c >>> ) >> I think that should be "-lc", not "-l c". I don't know where the extra >> space is coming from in your case. > Exactly! > > I have just posted a message with my findings. Which program produces > link.res? Maybe the problem is the $linklib line in your example? Some an extra (shift-?) space that isn't stripped but output to the linklib?

Exactly! I deleted the whole line, retyped it et voila!

It seems copying from LHelp carries some unwanted luggage (some odd invisible characters).

Thanks and sorry for the noise.

However I encountered this issue while trying to help Bo Berglund in his Lazarus mailing list thread. I will post a related specific question in a new fpc thread as not to mix things here.

Stephano

Reply by email