Recent

Author Topic: ld: library not found for -lc  (Read 1301 times)

TomAylesworth

  • Newbie
  • Posts: 2
ld: library not found for -lc
« on: November 30, 2022, 03:16:14 pm »
Getting a linker error trying to compile with new installation of fpc 3.2.2. Any ideas for how to fix it?

> fpc SphericalHouses.pas
Free Pascal Compiler version 3.2.2 [2022/10/24] for aarch64
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Darwin for AArch64
Compiling SphericalHouses.pas
SphericalHouses.pas(159,26) Warning: function result variable of a managed type does not seem to be initialized
Assembling sphericalhouses
Linking SphericalHouses
ld: library not found for -lc
An error occurred while linking
Error: Error while linking
Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Error: /opt/homebrew/bin/ppca64 returned an error exitcode


zeljko

  • Hero Member
  • *****
  • Posts: 1385
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: ld: library not found for -lc
« Reply #1 on: November 30, 2022, 04:04:17 pm »
You're missing libc-devel/libc-dev (or similar name) package ?

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1029
Re: ld: library not found for -lc
« Reply #2 on: November 30, 2022, 07:15:49 pm »
You have to install the command line developer tools using xcode-select --install

See also Getting Started (Intel and ARM64).rtf in either /Users/Shared/Free Pascal Compiler/Documentation, or on the disk image with the installation package.

zeljko

  • Hero Member
  • *****
  • Posts: 1385
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: ld: library not found for -lc
« Reply #3 on: November 30, 2022, 07:25:43 pm »
Ah, I've misreaded Target OS

TomAylesworth

  • Newbie
  • Posts: 2
Re: ld: library not found for -lc
« Reply #4 on: December 01, 2022, 02:00:09 am »
You have to install the command line developer tools using xcode-select --install

See also Getting Started (Intel and ARM64).rtf in either /Users/Shared/Free Pascal Compiler/Documentation, or on the disk image with the installation package.

Thanks for the suggestion but they are definitely installed. I'm a long-time iOS and MacOS developer with multiple compilers that rely on the Xcode Command Line Tools.

Welp, after posting that ridiculous statement, I decided to give it a try. Apparently even a "long-time (and overly arrogant) Apple developer" shouldn't make assumptions. smh

Thanks so much for the suggestion. Sorry for the ridiculous reply.

Tom
« Last Edit: December 01, 2022, 02:11:31 am by TomAylesworth »

Cavender

  • New Member
  • *
  • Posts: 12
Re: ld: library not found for -lc
« Reply #5 on: December 07, 2022, 06:15:08 pm »
I have exactly (I think) the same problem.  But I did that install yesterday.

Last login: Wed Dec  7 09:45:23 on console
jamescavender@jamescadersimac ~ % xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" in System Settings to install updates
jamescavender@jamescadersimac ~ %

Cavender

  • New Member
  • *
  • Posts: 12
Re: ld: library not found for -lc
« Reply #6 on: December 07, 2022, 06:17:57 pm »
Further clarification:


I got a new Mac mini a few days ago with macOS Ventura Version 13.0.1 and downloaded  fpc-3.2.2-intelarm64-macosx

To test it I tried to compile a program that I had compiled and run on another
Mac with another version of fpc.  I managed to overcome some problems with assembling.

Cavender

  • New Member
  • *
  • Posts: 12
Re: ld: library not found for -lc
« Reply #7 on: December 08, 2022, 09:45:47 pm »
I have found more evidence that I didn't notice at first concerning my linking problem.

Here is what I see when I try to compile,

Free Pascal Compiler version 3.2.2 [2021/05/16] for aarch64
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Darwin for AArch64
Compiling marmot.pas
Assembling marmot
Linking marmot
ld: library not found for -lc
An error occurred while linking
marmot.pas(2230,27) Error: Error while linking
marmot.pas(2230,27) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Error: /usr/local/bin/ppca64 returned an error exitcode


The linker (or something) left me three files, linkfiles2063.res, link2063.res, and ppaslink.sh.

Here is linkfiles2063.res:

/usr/local/lib/fpc/3.2.2/units/aarch64-darwin/rtl/sysinit.o
marmot.o
/usr/local/lib/fpc/3.2.2/units/aarch64-darwin/rtl/system.o


link2063.res is long, so I am only showing you the first 8 lines and the last 5 lines:

-arch
arm64
-macosx_version_min
11.0.0
-L/usr/lib/
-L/usr/local/lib/fpc/3.2.2/units/aarch64-darwin/httpd22/
-L/usr/local/lib/fpc/3.2.2/units/aarch64-darwin/rtl/
-L/usr/local/lib/fpc/3.2.2/units/aarch64-darwin/opengl/

-L/usr/local/lib/fpc/3.2.2/units/aarch64-darwin/libgd/
-L/usr/local/lib/fpc/3.2.2/units/aarch64-darwin/pcap/
-L/usr/local/lib/fpc/3.2.2/units/aarch64-darwin/
-L/usr/local/bin/
-lc

And here is all of ppaslink.sh:

#!/bin/sh
DoExitAsm ()
{ echo "An error occurred while assembling $1"; exit 1; }
DoExitLink ()
{ echo "An error occurred while linking $1"; exit 1; }
OFS=$IFS
IFS="
"
/usr/bin/ld        -x   -multiply_defined suppress -L. -o marmot `cat link2063.res` -filelist linkfiles2063.res
if [ $? != 0 ]; then DoExitLink ; fi
IFS=$OFS

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1029
Re: ld: library not found for -lc
« Reply #8 on: December 08, 2022, 10:28:14 pm »
link2063.res is long, so I am only showing you the first 8 lines and the last 5 lines:

-arch
arm64
-macosx_version_min
11.0.0
-L/usr/lib/
This suggests that either /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk was not found, which is where the command line tools normally install the macOS SDK, or that you are using a custom (.)fpc.cfg that does not contain -XR/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk (the /etc/fpc.cfg created by the FPC installer contains that line).

Cavender

  • New Member
  • *
  • Posts: 12
Re: ld: library not found for -lc
« Reply #9 on: December 09, 2022, 04:41:01 pm »
Thank you.

Library/Developer contains only 3 things,

jamescavender@jamescadersimac Developer % ls -a -l -F
total 0
drwxr-xr-x   5 jamescavender  staff   160 Dec  9 07:59 ./
drwx------@ 98 jamescavender  staff  3136 Dec  9 07:51 ../
drwxr-xr-x   5 jamescavender  staff   160 Dec  9 07:51 CoreSimulator/
drwxr-xr-x   2 jamescavender  staff    64 Dec  9 07:59 XCTestDevices/
drwxr-xr-x   5 jamescavender  staff   160 Dec  9 07:51 Xcode/

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1029
Re: ld: library not found for -lc
« Reply #10 on: December 09, 2022, 09:27:27 pm »
That means the command line tools are not installed, regardless of what xcode-select is telling you. You'll have to manually download the from https://developer.apple.com/download/all/?q=command%20line%20tools%20for%20Xcode and install them that way.

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2004
  • Former Delphi 1-7, 10.2 user
Re: ld: library not found for -lc
« Reply #11 on: December 09, 2022, 10:34:24 pm »
I recently had a similar issue after upgrading Xcode on both an M1 Mac mini and an Intel Mac mini. The solution was the following:

1) open Xcode which may say it needs to install additional components, let it do so.
2) execute xcodebuild -runFirstLaunch in a Terminal
3) execute xcode-select --install
4) success

My symptoms that all was not well (a script-driven download of FPC + Lazarus development source using git was failing) were:

1) having git crash when trying to use it!
2) being told to execute xcode-select --install
3) xcode-select --install downloading and installing the CLI
4) cycling back to 1)

All very weird.
Lazarus 2.3, FPC 3.3.1 macOS 12.6.1 x86_64 Xcode 14.1
Lazarus 2.3, FPC 3.3.1 macOS 12.6.1 aarch64 Xcode 14.1

Cavender

  • New Member
  • *
  • Posts: 12
Re: ld: library not found for -lc
« Reply #12 on: December 12, 2022, 05:39:40 pm »
Thank you, Jonas Maebe.  I did try

 https://developer.apple.com/download/all/?q=command%20line%20tools%20for%20Xcode

It didn't solve the problem.

Thank you, Trev.  I tried

xcodebuild -runFirstLaunch
xcode-select --install

That also didn't solve the problem.

A friend here in Colorado suggested

sudo rm -rf /Library/Developer/CommandLineTools

to remove Command Line Tools before reinstalling them. That didn't solve the problem.

Could you guys (or anyone) comment on my following speculations?

This is an Apple bug, not an fpc bug.  (I called Apple Help and they tried to blame it on fpc.)

fpc takes my Pascal program marmot.pas and creates marmot.o, which is in assembly language.  The language has no name. 

Then xcode takes over.  The assembler is part of xcode.  It translates marmot.o into a binary executable. 

To handle things like open, close, and assign commands, the executable necessarily uses calls to xcode procedures.  Does the Linker fill in addresses of these procedures?  What does a linker do?

It will be helpful for me to understand the functions of assembler and linker before I call Apple Help again.   



Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1029
Re: ld: library not found for -lc
« Reply #13 on: December 12, 2022, 09:04:53 pm »
In the worst case, you should be able to work around it by passing -XR/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk to the compiler, but it really should not be necessary.

The issue is not the assembler or the linker. The assembler works (FPC uses clang for that), otherwise you would not get to the stage where it looks for the C library. And the linker itself (ld) also works, since it's trying to link but it cannot find the C library. The fact that it cannot find the C library means the macOS SDK is not installed in the default location by the Xcode command line tools installer (in /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk). FPC uses that one by default because in principle you can move the Xcode application around, but if it's in the default location, the above -XR parameter should also work.

Cavender

  • New Member
  • *
  • Posts: 12
Re: ld: library not found for -lc
« Reply #14 on: December 14, 2022, 05:55:37 pm »
What does it mean to pass something to the compiler?  How do you do i?

 

TinyPortal © 2005-2018