gfortran not working on osx yosemite - fortran

I recently installed fortran on my Macbook Pro mid 2011 that is running OS X Yosemite. When I try to compile code, I get this:
gfortran: warning: couldn’t understand kern.osversion ‘14.0.0 ld: library not found for -lcrt1.o collect2: error: ld returned 1 exit status

This is due to the fact that Mac OS X's headers are not C99/C++98 compatible.
See bug 61407 at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61407. That bug report provides a patch.

Try installing Xcode command line tools as described at http://hpc.sourceforge.net
I also installed full gcc binary for Yosemite from http://hpc.sourceforge.net
Seemed to solve this problem.
JTN

Install the 5.0 version of gcc and/or gfortran from http://hpc.sourceforge.net
Works perfectly for OS X Yosemite

Related

ld warning in mac terminal using skm and c++ compiler

I’ve been getting this warning when using the Mac terminal and skm library to compile a simple hello world program in C++. I’m new to this so not really sure what to do.
ld: warning: dylib (/Users/chriscommon/.splashkit/lib/macos/libSplashKit.dylib) was built for newer macOS version (10.15.4) than being linked (10.15)
ld: warning: object file (/Users/chriscommon/.splashkit/clang++/lib/macos/libSplashKitCpp.a(splashkit.cpp.o)) was built for newer macOS version (10.15.4) than being linked (10.15)
ld: warning: object file (/Users/chriscommon/.splashkit/clang++/lib/macos/libSplashKitCpp.a(adapter_type_mapper.cpp.o)) was built for newer macOS version (10.15.4) than being linked (10.15)
Does anyone know if there is some way I can resolve this so it links to the correct version? I’m running macOS10.15.7 and have tried to update skm, reinstall Xcode command line tools etc and the program works ultimately but the warnings appear each time I compile.
Try to add this flag to Xcode when you build your program:
-mmacosx-version-min=11.0

Compiling for macOS arm64 arch

I am using macOS 10.15.7 to build a simple hello world C++ program for macOS arm64 architecture (not iOS). I have Xcode 12 installed. I tried the following:
xcodebuild -project TestApp.xcodeproj clean build ARCHS=arm64 EXCLUDED_ARCHS=""
But received the following error:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include/sys/cdefs.h:807:2: error: Unsupported architecture
#error Unsupported architecture
and similar other errors.
I supposed I can cross-build for upcoming ARM-based macs from my x86_64 mac, but it doesn't seem to work.
The SDK for macOS Big Sur wasn't released as part of the public Xcode 12.0 release, it only contains the SDK for Catalina (macOS 10.15).
To target macOS Big Sur (and macOS on Apple Silicon), you need the beta SDK (Xcode 12.2 beta).
It works fine when I removed the 'EXCLUDED_ARCHS' part.

OpenMP on Mac not working anymore

I had OpenMP compiling and executing in C/C++ on my Mac but then I formatted and reinstalled a fresh copy of OS X. I believe the only difference in the setup was that I had Xcode 5 before the format, and now I have Xcode 6.
Now I get fatal error: 'omp.h' file not found
I read this has something to do with clang and gcc, but, my confusion lies with why did it work before and now its not working?
After some research I seem to have found an answer.
GCC included in the latest version of Xcode (Xcode 6) is only a symbolic link to clang. Since clang does not support OpenMP at this time, you need to install a different version of GCC. The easiest way to do this would be to use Homebrew or MacPorts.
Keep in mind that even when you do this you will probably need to alter your $PATH to have /usr/local come before /usr/bin. This is because Homebrew will have placed your newly installed GCC in /usr/local. Also, some implementations may name the command gcc-49 instead of plain gcc.
Mac OSX uses clang.The gcc compiler in OS X does not support OpenMP. To use this feature a new gcc compiler needs to be installed.
Go to Terminal, if you have not installed Hombrew, install it:
/usr/bin/ruby -e "$(curl -fsSL https://`enter code here`raw.githubusercontent.com/Homebrew/install/master/install)"
then install new version of gcc
brew reinstall gcc --without-multilib
This will not make changes to the existing gcc compiler installed by Xcode as we are reinstalling it.
After running the command given below compile the files using the new version of gcc using the syntax : gcc-version -fopenmp filename.c
To find the version type gcc and then press tab. This will list out all the possible variants of gcc. The version number can be found out from this. For example : gcc-6, gcc-4.9,etc

Can I use gcc 4.7 (and C++11) on Mountain Lion without installing XCode?

I've been using command line tools and a text editor to compile class projects, which has worked great. Unfortunately, they've become sticklers about us using 4.7. Xcode (and thus OSX) only has llvm-gcc 4.2, so I was looking to upgrade.
I've got macports installed and have found instructions for installing gcc 4.7, but it says that I need xcode installed. I was hoping to be able to just use command line tools and not have xcode (I don't need any of the iOS or graphics stuff, I just want gcc.
Anyway, if it's not possible, it's no big deal, but I'd be appreciative if anyone could point me in the right direction. Thanks!
To clarify, I have command line tools, but not the version of gcc I'd like. Running macports results in this:
$ sudo port install gcc47
Error:
Error: No Xcode installation was found.
Error: Please install Xcode and/or run xcode-select to specify its location.
Error:
Error: The installed version of Xcode (2.0orlower) is too old to use on the installed OS version.
Version 4.1 or later is recommended on Mac OS X 10.8.

Compile for OS X 10.6?

Normally for my OS X builds I have been compiling my applications on an old Mac Book Pro that runs 10.6. This assures that I support this version of OS X.
However for various reasons, the MBP is no longer a long term option so I have been compiling on a more recent device which runs 10.8. However when I do this, my application does not work on 10.6 even with the -mmacosx-version-min=10.6 flag set. The error that happens when I set the flag is "Symbol not found: _wcsdup" in libSystem.B.dynlib
I looked up this error and the only recommendations I can find is to directly link against the 10.6 SDK. However when I tried copying the 10.6 SDK from my MPB to the new machine (because 10.6 SDK is not installed on 10.8), it fails to compile with errors like "error: bits/c++config.h: No such file or directory" I assume this is because of the way I "installed" the SDK, although others have had success with this.
Does anyone have a solution?
Run 10.6 in a VM, like VMWare or VirtualBox.
I am able to reinstall older SDKs and compilers with this procedure: How can we restore ppc/ppc64 as well as full 10.4/10.5 SDK support to Xcode 4?
You need to change the path of xcode installs in the script.
Also you probably won't be able to use -std=c++11 when targeting 10.6 since you will mostly also need -stdlib=libc++ which is only available when targeting 10.7 or above.
Apple only distributes libc++ binaries since 10.7. You could build your own libc++ and deploy it with your app to 10.6 machines. But Apple hard coded the compiler to disallow -stdlib=libc++ when targeting anything lower than 10.7.