I went to do a little code maintenance on a couple utils I'd written in FreePascal, and they wouldn't build. For a couple years, FPC just didn't work on 64-bit Mac OS, but they finally fixed that. Current fpc 3.2.0 is in MacPorts, I'm not sure what the state of Lazarus is, I quit using it. But the core Pascal is fine for many tasks, and I may do some things in CP/M Pascal when I get my SpecNext (longest wait ever until fall/whenever).
Anyway, the error I got was ld: library not found for -lc
and nobody on the Internet has ever posted with that error, that I can find.
And eventually I tracked it down to the SDK not being linked at all. So here's an updated fpc.cfg
which goes in your $PPC_CONFIG_PATH, note the DARWIN section. Also that's x86_64 only, I need to add an ARM64 branch at some point.
#IFDEF DEBUG
#WRITE DEBUG
-gl
-Crtoi
#ELSE
# Strip debuginfo
-O2
-Xs
#ENDIF
#IFDEF DARWIN
#WRITE DARWIN
# use pipes instead of temporary files for assembling
-ap
#DEFINE CPUX86_64
-Px86_64
-FD/Library/Developer/CommandLineTools/usr/bin
-XR/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
#ENDIF
#IFDEF OBJFPC
#WRITE OBJFPC
-Mobjfpc
#ELSE
#WRITE FPC
-Mfpc
#ENDIF
# use ansistrings
-Sh
# stop after warnings
-Sew
# don't show Hint: (5023) Unit "X" not used in Y
-vm5023
# don't show Hint: (5024) Parameter "name" not used
-vm5024
#-Fl/usr/X11/lib
#-Fl/usr/local/lib
-Fu/opt/local/libexec/fpc/lib/fpc/$fpcversion/units/$fpctarget
-Fu/opt/local/libexec/fpc/lib/fpc/$fpcversion/units/$fpctarget/*
And a quick hello world/Unicode tester:
{ hello.pas
Copyright ©2017 by Mark Damon Hughes. Do what thou wilt.
}
program hello;
uses crt, sysutils;
var
name: utf8string;
c: widechar;
i: integer;
begin
write('What is your name? ');
readln(name);
writeln('Hello, ', name, ' from code page ', stringCodePage(name), '!');
for i := 1 to length(name) do begin
c := name[i];
writeln(i, ': ', c, '(', ord(c), ')');
end;
readkey();
end.
fpc -dDEBUG hello.pas
produces a couple dozen warnings like: ld: warning: object file (/opt/local/libexec/fpc/lib/fpc/3.2.0/units/x86_64-darwin/rtl/baseunix.o) was built for newer macOS version (11.0) than being linked (10.8) and I'd love it if someone could tell me how to get FPC to tell ld to make that STFU.
But it works:
% ./hello
What is your name? Mark
Hello, Mark from code page 65001!
1: M(77)
2: a(97)
3: r(114)
4: k(107)
5: �(239)
6: �(163)
7: �(191)