Issue with linker for Mac OS - gcc

I have recently started using ada for a lab in my systems programming class and I can say it is really interesting.
I tried most of it at the computers labs for testing and I decided to install the compiler and its linking tools in a MacBook.
Altough the installation is done and there seems to be no problem, when I tried to print the classic hello world program I am getting this message:
gprbuild greet.adb
using project file /Users/xyderos/opt/GNAT/2020/share/gpr/_default.gpr
Bind
[gprbind] greet.bexch
[Ada] greet.ali
Link
[link] greet.adb
ld: library not found for -lSystem
collect2: error: ld returned 1 exit status
gprbuild: link of greet.adb failed
gprbuild: failed command was: /users/name/opt/gnat/2020/bin/gcc greet.o b__greet.o - L/Users/name/ada/ -L/Users/name/ada// -L/users/name/opt/gnat/2020/lib/gcc/x86_64-apple-darwin17.7.0/8.4.1/adalib/ /users/name/opt/gnat/2020/lib/gcc/x86_64-apple-darwin17.7.0/8.4.1/adalib/libgnat.a -Wl,-rpath,#executable_path/ -Wl,-rpath,#executable_path/..//opt/gnat/2020/lib/gcc/x86_64-apple-darwin17.7.0/8.4.1/adalib -o greet
I am getting really confused about the lSystem library.
It seems that the library doesn't exist on Mac(maybe I need to install Xcode?).
Does anyone have a clue about that issue or is there a probably better way to install it via brew?
Thanks a lot in advance!

On my MacOS 10.14, the following worked for me, without having to download the massive blob that is Xcode, which I had neither the bandwidth nor the diskspace for. I don't know if this still works on MacOS 10.15 (not planning to upgrade).
Most of this info was from a blog post by Simon Wright: https://forward-in-code.blogspot.com/2019/06/macos-software-development-kit-changes.html
You only need the Xcode command line tools only (not Xcode): xcode-select --install
Now unpack the included headers: sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
And tell GNAT where to find them: mv ce2109-specs /usr/local/opt/GNAT/2019/lib/gcc/x86_64-apple-darwin17.7.0/8.3.1/specs
The ce2109-specs file is from the blog post above. This did the job for me and GNAT can now link working binaries on MacOS 10.14.
If you're on 10.15 and it doesn't work (because there's no more Xcode command line tools or they're missing the headers package), you will unfortunately have to install Xcode as per the GNAT Readme.

Related

GCC won't compile anything on macOS

Recently (since Catalina was released and xcode updated, but I am still running Mojave) I have found the gcc, installed via macports, has broken. I get errors saying that the system includes cannot be found:
ld: library not found for -lSystem
I have tried the solution here: Can't compile C program on a Mac after upgrade to Mojave - but when I install macOS_SDK_headers_for_macOS_10.14.pkg it doesn't actually create anything in /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs ; all I see in there is the 10.15 (Catalina) sdk!
If I instead just sym link MacOSX10.14.sdk to MacOSX10.15.sdk (possibly not a great idea), I get a different set of errors:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/wchar.h:90,
from /opt/local/include/gcc8/c++/cwchar:44,
from /opt/local/include/gcc8/c++/bits/postypes.h:40,
from /opt/local/include/gcc8/c++/iosfwd:40,
from /opt/local/include/gcc8/c++/ios:38,
from /opt/local/include/gcc8/c++/ostream:38,
from /opt/local/include/gcc8/c++/iostream:39,
from /Users/pae9/soft/src/cmake/LIGO_support/restrictHealMap.cpp:4:
/opt/local/lib/gcc8/gcc/x86_64-apple-darwin18/8.3.0/include-fixed/stdio.h:222:7: error: conflicting declaration of 'char* ctermid(char*)' with 'C' linkage
char *ctermid(char *);
In other words, now it appears that the macports headers are conflicting with the xcode ones.
I never had a problem before; I think this issue dates to the last xcode update (currently on Version 11.2 (11B52))
Any thoughts or suggestions very welcome - I'd really like to be able to go back to compiling code using gcc!
FYI I'm using gcc7 (from macports), for consistency with the linux servers which are my actual live systems, but I have tried gcc 8 and 9 and get the same results.
cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
sudo ln -s MacOSX10.15.sdk MacOSX10.14.sdk
OK, it seems that if I do the ln -s as above, and also move #include to be the first include in all my files, the problem goes away.
This looks to me like a serious problem in the Apple SDK headers, because surely conflicting definitions like this shouldn't occur...?

Are the Metal command line tools available without Xcode?

I have installed the Xcode Command Line Tools with xcode-select --install and they have been working fine for me. I am now trying to use Metal, and get this error:
xcrun: error: unable to find utility "metal", not a developer tool or in PATH
The macOS SDK appears to be present at /Library/Developer/CommandLineTools/SDKs/MacOSX10.13.sdk but I can't find a metal utility either there on anyway else in the tools' directory.
An issue was filed with gfx-rs and put down to environment misconfiguration. It doesn't really look like this was the case, since the resolution was to point away from the Command Line Tools at the full application. An more knowledgeable issue was filed with Unreal Engine which implies that this is not possible with a CLI-only install.
Is it possible to use Metal without a full Xcode install?
I don't think so. The Metal command-line tools are located at
$XCODE_PATH/Contents/Developer/Platforms/$PLATFORM_NAME.platform/usr/bin
but are not in the standalone Command Line Tools download, probably because they're regarded as SDK content.
You could file an enhancement request Radar asking for the Metal tools to be distributed in this way; it's worth a shot.
Yes, gfx-rs uses the xcrun command to compile Metal source, as you can see in build.rs. These commands are documented by Apple.
To compile a Metal source file into an intermediate representation (.air) using the macosx SDK:
$ xcrun -sdk macosx metal -c MyLibrary.metal -o MyLibrary.air
To link 1 or more compiled Metal IR files into a single library:
$ xcrun -sdk macosx metallib MyLibrary.air -o MyLibrary.metallib
I've downloaded Xcode. Then I moved all special tools to CommandLineTools.
After that I threw Xcode into trash. For now everything seems to work fine.

Fortran codes won't compile on Mac with gfortran

I recently moved from the SGI, Sun workstation environment to a Mac. SGI and Sun came with Fortran compilers so I have maybe 100 small f77 codes I wrote over the years for post-processing and analysis of simulated data. I was hoping to get these codes running on my iMac with gfortran. Most of these are very simple codes but I can't get them to compile and execute. I tried starting with the basics and wrote the Hello World code from a gfortran help page. My code, fortran.f is:
program helloworld
print *, "hello world"
end program helloworld
When I tried compiling this according to the example I typed:
gfortran fortran.f
But I keep getting the error message:
FATAL:/opt/local/bin/../libexec/as/x86_64/as: I don't understand 'm' flag!
This is the same error message I get on my other codes. Can someone tell me what I'm doing wrong? I can't think of a simpler example but I can't seem to get it to work.
When it comes to macOS, I think that building form sources is the best approach you can have. You can achieve that quite easily by downloading and compiling GFortran as part of GCC directly from: https://gcc.gnu.org/wiki/GFortran
However, there are few things you have to take care of:
make sure you have XCode installed, you can get it here
XCode
XCode is free of charge
Make sure you have command line tools
You can get them either from developer.apple.com
Command Line Tools
or directly from XCode. It might be that XCode will tell you to install Command Line Tools upon first execution
In the past, running command like "svn", when Command Line Tools were not installed, also triggered the installation.
Compile GCC
> ./configure --prefix=$HOME/opt/usr/local
> make all
> make install
Alternatively, you can install using macOS package from GFortran
gfortran-6.3-Sierra.dmg
Fully working sample with Fortran based MPI code:
http://www.owsiak.org/running-open-mpi-on-macos/
If your gfortran was installed a long time ago and you have updated macOS since installing, it may need re-installing to get correctly aligned and linked with the latest macOS tools and libraries.
My advice would be to:
uninstall gfortran,
check that Xcode and its command line tools are up-to-date,
re-install gfortran.
Hints for each of those steps follow:
Note that gfortran is a part of GCC - the "GNU Compiler Collection".
If you installed gfortran via homebrew, you can remove it with:
brew rm gcc
You can update Xcode by by going to AppStore and clicking Updates at top-right.
The Xcode Command Line tools include make and git and command-line versions of the compilers. You can install/update the Xcode command line tools with:
xcode-select --install
You can install gfortran with homebrew using:
brew install gcc
When you are finished, you should make sure that your PATH includes /usr/local/bin near the start and that there are no errors when you run:
brew doctor
which is a brilliant utility that checks your homebrew configuration is correct.
All I had to do was change the path.
Initially, my PATH was something like
/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin
Because of this reason, the default assembler (as) was not called which is in the /usr/bin directory.
To enable the call to the right assembler (as), I had to add /usr/bin to the PATH in front of (before) /opt/local/bin, i.e. on a Mac this can be added by editing ~/.bash_profile such that one's $PATH looks like
/usr/bin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin
Once edited, execute at your command prompt:
source /etc/bash_profile
This worked for me.

Xcode install on OSX 10.9 - clang: error: no input files

I'm in the process of installing XCode Command Line Tools onto OSX 10.9 Mavericks
I did a successful install XCode:
$ xcode-select -p
/Library/Developer/CommandLineTools
However when I type in either $ clang or $ gcc it returns:
clang: error: no input files
If you just type the command without any input files, then as commented, the compiler reports an accurate error message.
But if you have an existing project, then you can see that same "clang: error: no input files" message when:
you move your folder/files after making the project
one of your files isn't recognized by the XCode project
your project pre-compile header settings is wrong (wrong prefix):
In Xcode "Build settings" reviews the value for "Prefix header".
It seems to me that you have it set to "MySecondTabbApp/MySecondTabbApp-Prefix.pch" and it should be just "MySecondTabbApp-Prefix.pch"
The OP user2925321 comments:
The error was that I was running through steps to configure ruby and was directed to instructions on another page that just stated to check for $ gcc instead of $ gcc --version.
Obviously new to coding, trying to learn more.
Try gcc -v.
I am on a Mac (Mavericks) and that worked for me. It will tell you which version you are using (and you will know it is installed).
I faced the same issue. Type in xcode-select --install. It will work.
Another possibility: double check how the file in question is added to the xcode project. In my case, the file was set to "relative to group" instead of "relative to this project" and it was causing this error.
just type gcc -v which will spit an output specifying the prefix flag with which gcc was installed and the LLVM version as well. Specifying gcc on the command line without an option will report the issue you say it is reporting because its not able to find a file to compile using gcc.
I was seeing this error while setting up a React Native project. Here is what worked for me.
sudo xcode-select --switch /Applications/Xcode.app

How to build OpenCASCADE on MAC (Mountain Lion)

I am trying to build OpenCASCADE on Mac, but I am not having any luck.
I downloaded it from Github in tar.gz, but I am really new to Mac and I am stuck.
Can anybody explain what should be my next step?
(I found some terminal commands what I should use, but I am not familiar with them. So if it is the right way to build OpenCASCADE on Mac please write down the terminal commands with details. Thank you!)
EDIT:
I understood the command line commands now from the link below. I understood it before too, but I was mistaken, because my main problem was, that I didn't had gcc installed (XCode does not installs gcc automatically...). So anyways, now finally I can run the cmake command. It starts but it ends with this:
CMake Error at /Applications/CMake
2.8-9.app/Contents/share/cmake-2.8/Modules/FindX11.cmake:420 (MESSAGE): Could not find X11 Call Stack (most recent call first):
CMakeLists.txt:313 (FIND_PACKAGE)
Anybody have any idea what to do? I tryed to search this too here, and google...and I found some "solutions" but those didn't work for me.
EDIT EDIT:
The solution for the last edit is that Mountain Lion doesn't install X11. So open up an app that uses X11 or Xquartz and it will install automatically.
Unfortunetly it still doesn't work. My next error message is the following after the make command in terminal:
In file included from
/Users/davidbirkas/Documents/tpaviot-oce-6c9a06a/src/AlienImage/AlienImage_X11XWDAlienData.cxx:14:
/Users/davidbirkas/Documents/tpaviot-oce-6c9a06a/inc/Aspect_XWD.hxx:5:12:
fatal error:
'X11/XWDFile.h' file not found
# include
^ 1 error generated. make[2]: * [adm/cmake/TKService/CMakeFiles/TKService.dir/_/_/__/src/AlienImage/AlienImage_X11XWDAlienData.cxx.o]
Error 1 make1:
[adm/cmake/TKService/CMakeFiles/TKService.dir/all] Error 2 make: **
[all] Error 2
Any ideas how to fix this?
Ensure that, together with XCode, you also install the X11 support from Apple's Devtools. Your error message is indicating that it is missing.
FWIW, I have written a blog post about OCC and PythonOCC on Mac some time ago. Maybe you'll find some detailed info there.
http://cad-3d.blogspot.com/2011/10/pythonocc-open-source-interactive-cad.html
In this post, I still talk about using the binary installer, but recent updates to the OCE edition compile usually without problems out-of-the-box, also on OSX (that is NOT the case with the official OpenCASCADE release).
I spent a little time on this and I think I have it. Here is what I did step by step:
Preparation phase:
Installing Xcode (with command line tools) = Apple developer site
// If Xcode doesn't install gcc, than you can still download it from the developer site as Command Line Tools for Xcode.
Installing Cmake (with command line tools) = Google
// You can download it from the official site with a .dmg/.pkg file extension. Easy install.
X11 under Mountain Lion "changed" to Xquartz. Probably it is not installed by default, but it is easy to check it. Just go to the folder "Application" and start the X11 app. If X11/Xquartz is not installed than it will install automatically!
Installing FTGL = MacPorts = Google
// Download MacPorts from their official site, install it with the installer, than write this to the terminal:
sudo port install ftgl
Download OCE and extract it (.OCE-0.9.0.tar.gz file) = https://github.com/tpaviot/oce/wiki/Download
Installing phase:
I. Open Terminal.
II. Run this command
// This will set the proper PATH.
ln -s /opt/X11/include/X11 /usr/local/include/X11
III. Than from the Terminal go to the directory where you extracted the OCE file (the original extracted file name should be: tpaviot-oce-6c9a06a).
IV. Than write these commands:
// You make a build directory to the extracted OCE folder.
mkdir build
cd build
V. After this you give out the cmake command:
cmake -DOCE_INSTALL_PREFIX:PATH=$HOME/OCE \
-DOCE_WITH_FREEIMAGE:BOOL=ON \
-DOCE_WITH_GL2PS:BOOL=ON \
-DOCE_DRAW:BOOL=ON \
..
VI. And at the end the make commands:
make
make install/strip
If you did everything exactly like this, than it should work!
Give OCE a try. Compiling for osx is a walk in the park

Resources