PR# 19873 Build failure while linking C library

Problem Report Summary
Submitter: daniel.nachun
Category: EiffelStudio
Priority: Low
Date: 2022/09/20
Class: Bug
Severity: Serious
Number: 19873
Release: 22.05
Confidential: No
Status: Closed
Responsible:
Environment: Linux
Synopsis: Build failure while linking C library

Description
We have encountered a build failure while building EiffelStudio in Ubuntu 22.04 in Homebrew: https://github.com/Homebrew/homebrew-core/pull/111070#discussion_r973814067.

The failure is:
ld -m elf_x86_64 -shared -o libmtfinalized.so ../idrs/MTidrs.o MTscoop.o MTscoop_gc.o MTscoop_helpers.o MTprocessor_registry.o MTprivate_queue.o MTprocessor.o MTqueue_cache.o MTmessage_channel.o MTrequest_group.o MTidentifier_set.o MTmalloc.o MTgarcol.o MTlocal.o MTstack.o MTstore.o MTretrieve.o MThash.o MTtraverse.o MThashin.o MTtools.o MTinternal.o MTplug.o MTcopy.o MTequal.o MTlmalloc.o MTout.o MTtimer.o MTurgent.o MTsig.o MThector.o MTcecil.o MTfile.o MTdir.o MTmisc.o MTstring.o MTerror.o MTumain.o MTmemory.o MTmemory_analyzer.o MTargv.o MTboolstr.o MTsearch.o MTrun_idr.o MTpath_name.o MTobject_id.o MTeif_threads.o MTeif_project.o MTposix_threads.o MTgen_conf.o MTeif_type_id.o MTrout_obj.o MToption.o MTcompress.o MTconsole.o MToffset.o MTmain.o MTexcept.o  -lm -lpthread
  ld: cannot find -lm: No such file or directory
  ld: cannot find -lpthread: No such file or directory

We were able to fix this issue by making two changes to CONFIGS/linux-x86-64 in c.tar.bz2:
1) Change the value of sharedlink from "ld" to our C compiler "gcc"
2) Change the value of ldflags from "-m elf_x86_64" to "" because this flag is unsupported by GCC

It seems like it may be be more portable to let the compiler call the linker instead of invoking it directly as the compiler will be able to figure out the right way to link to glibc, which can vary based on different Linux systems.
To Reproduce
On a system where Docker is available, after https://github.com/Homebrew/homebrew-core/pull/111070 has been merged:
docker run -it homebrew/ubuntu22.04:master
brew edit eiffelstudio

Delete or comment out these lines, then save the modified formula:
     if OS.linux?
       system "tar", "xf", "c.tar.bz2"
       inreplace "C/CONFIGS/linux-x86-64", "sharedlink='ld'", "sharedlink='#{ENV.cc}'"
       inreplace "C/CONFIGS/linux-x86-64", "ldflags=\"-m elf_x86_64\"", "ldflags=''"
       system "tar", "cjf", "c.tar.bz2", "C"
     end

brew install -v -s --keep-tmp eiffelstudio

Go the temp folder where the failed output is saved, and check compile.log
Problem Report Interactions
From:jfiat_es    Date:2023/11/09    Status: Closed    Download   
Suggestion to use C compiler instead of the specific "ld" applied for Linux, Macosx, ...

From:jfiat_es    Date:2022/09/23    Status: Analyzed    Download   
I did check further, and I see that your report is about the usage of "brew" on Linux (especially Ubuntu 22.04).
I am not familiar with "brew" , especially on linux.
Is there anything specific to brew on Linux?
I am asking as we have no issue compiling EiffelStudio on Ubuntu 22.04 directly.

From:jfiat_es    Date:2022/09/23    Status: Analyzed    Download   
Dear Daniel,

Thanks for the report and suggestion.
We also note about the github link.

Correct me if I am wrong, but the script is to build the macosx version of EiffelStudio, and not the "linux-x86-64" .
So the correct value for ISE_PLATFORM should be "macosx-x86-64" 

I haven't checked carefully the full diff associated with the github link. 
Without deeper investigation, I would say  if you build EiffelStudio for macosx, then you should use "macosx-x86-64", and not "linux-..."