Recent

Author Topic: SOLVED Failed to build Lazarus on Monterey x86_64: ld cannot find CoreFoundation  (Read 3190 times)

PierceNg

  • Sr. Member
  • ****
  • Posts: 394
    • SamadhiWeb
I upgraded my laptop from Catalina to Monterey. Now Lazarus doesn't build.

- FPC 3.2.2 built on Catalina from source
- Lazarus branches main and fixes_2_2

For both Lazarus branches, 'make clean bigide' fails at building lazres:
Code: Text  [Select][+][-]
  1. Assembling lazres
  2. Linking ./lazres
  3. ld: framework not found CoreFoundation

I restored copy of Lazarus 2.2 built from source on Catalina from archive. It runs, but it fails to build my app (which builds with this restored version of Lazarus when my laptop was running Catalina):

Code: Text  [Select][+][-]
  1. % lazbuild ...
  2. ld: framework not found Cocoa

Xcode IDE and command line tools appear to work, as a GUI C++ library and executables build successfully.

According to MacPorts, 'port health' for Lazarus on Monterey x86_64 is a cross.
« Last Edit: March 03, 2023, 05:04:08 pm by PierceNg »

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1067
Re: Failed to build Lazarus on Monterey x86_64: ld cannot find CoreFoundation
« Reply #1 on: February 27, 2023, 10:47:55 pm »
After upgrading your OS, you need to reinstall the developer command line tools with
Code: [Select]
sudo xcode-select --install.

PierceNg

  • Sr. Member
  • ****
  • Posts: 394
    • SamadhiWeb
Re: Failed to build Lazarus on Monterey x86_64: ld cannot find CoreFoundation
« Reply #2 on: February 28, 2023, 04:35:49 am »
After upgrading your OS, you need to reinstall the developer command line tools with
Code: [Select]
sudo xcode-select --install

Thanks. Didn't work:

Code: Text  [Select][+][-]
  1. % sudo xcode-select --install
  2. Password:
  3. xcode-select: error: command line tools are already installed, use "Software Update" to install updates

Software Update offers me upgrade to Ventura, nothing else.

Right now I can use command line developer tools to build, e.g., webview; this library wraps Cocoa WebKit on macOS. Its demos run.

Also, using FPC (built on Catalina), two of my webview Pascal FFI demos build and run, one builds and runs but doesn't function, and two others complain about not finding macOS frameworks. Every demo opens a window and runs Cocoa WebKit in it.

Curious. Looks like I gotta spend some time on this...
« Last Edit: February 28, 2023, 04:43:25 am by PierceNg »

PierceNg

  • Sr. Member
  • ****
  • Posts: 394
    • SamadhiWeb
Re: Failed to build Lazarus on Monterey x86_64: ld cannot find CoreFoundation
« Reply #3 on: February 28, 2023, 07:59:13 am »
I found these:

- https://developer.apple.com/documentation/macos-release-notes/macos-big-sur-11_0_1-release-notes
- https://lapcatsoftware.com/articles/bigsur.html

Quoting Apple,
Quote
New in macOS Big Sur 11.0.1, the system ships with a built-in dynamic linker cache of all system-provided libraries. As part of this change, copies of dynamic libraries are no longer present on the filesystem. Code that attempts to check for dynamic library presence by looking for a file at a path or enumerating a directory will fail. Instead, check for library presence by attempting to dlopen() the path, which will correctly check for the library in the cache. (62986286)

PierceNg

  • Sr. Member
  • ****
  • Posts: 394
    • SamadhiWeb
So I followed the links I found, built some tools they pointed to, and could extract the individual framework/library files from the system caches. Well, for ARM64 and x86_64h 'Haswell' architectures, but not for my laptop's own pre-Haswell x86_64 architecture.

I think it is due to Open Core Legacy Patcher (OCLP). My laptop is > 10yo and officially it can only run up to Catalina. Thanks to OCLP I could upgrade it to Monterey. But most likely OCLP's presence caused the extraction attempt to fail. It so happens I just updated the OS on this laptop 2 days ago, and at least that once the OS update wiped out OCLP. Without OCLP I reckon I should be able to do the extraction.

KIV until next OS update then... 

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2032
  • Former Delphi 1-7, 10.2 user
You are following a red herring if you think that the dynamic linker cache is the root of your issues. You most definitely do not need to extract any files from the cache to get a working installation.

I re-build the dev version of Lazarus daily in Monterey on both Intel and M1 Mac minis upgraded from previous macOS versions and have never encountered your issue.

My advice would be to erase the current Lazarus + FPC installation and start again from scratch.

Instructions for deleting a Lazarus + FPC installation can be found on the Wiki as well as Instructions for installing Lazarus + FPC.

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1067
https://stackoverflow.com/questions/70031053/golang-cant-start-debug-shows-framework-not-found-corefoundation suggests that first deleting the old CommandLineTools folder may help. You could also just rename or move it if you want to be able to restore it in case it doesn't help.

PierceNg

  • Sr. Member
  • ****
  • Posts: 394
    • SamadhiWeb
Thank you both for your inputs. I figured it out. Only the how, not the why.

I had to add "-Ff" option to FPC. Before, the command was this:

Code: Text  [Select][+][-]
  1. fpc -Fu../../src -Fl. servcli.lpr

Now it works with this:

Code: Text  [Select][+][-]
  1. fpc -Fu../../src -Fl. \
  2.   -Ff/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks \
  3.   servcli.lpr

Same for Lazarus: I set env-var OPT="-Ff<as above>" then "make ..." completed. The resulting Lazarus and lazbuild could build my LCL program after I added the same "-Ff..." to the project options, and the resulting program works.

Edit: And within Lazarus I then configured "Build Lazarus" with the same "-Ff" option. With this Lazarus rebuilt itself  successfully.
« Last Edit: March 03, 2023, 05:23:09 pm by PierceNg »

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1067
Now it works with this:

Code: Text  [Select][+][-]
  1. fpc -Fu../../src -Fl. \
  2.   -Ff/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks \
  3.   servcli.lpr
Do not use that parameter for system frameworks. The correct parameter is "-XR/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk", but that parameter should already be in your /etc/fpc.cfg. If it's not, reinstalling FPC (not Lazarus or FPC sources, that won't change anything) should add it.

 

TinyPortal © 2005-2018