macOS : configure: error: C compiler cannot create executables

By | December 20, 2019

Having some issues using the GCC compiler? The problem may show up under different circumstances, such as :

– Invoking the GCC compiler trying to compile an application manually using “sudo ./configure”. In such case, an output similar as below will be shown :

checking for gcc... gcc
checking whether the C compiler works... no
configure: error: in `/path/to/some/source/folder':
configure: error: C compiler cannot create executables

– Trying to upgrade outdated packages after updating MacPorts (which invoke GCC as well) using “sudo port upgrade outdated”. In such case, an output similar as below will be shown :

[...]
Warning: All compilers are either blacklisted or unavailable; defaulting to first fallback option
Warning: All compilers are either blacklisted or unavailable; defaulting to first fallback option
Warning: No port libedit found in the index.
Warning: No port libffi found in the index.
Warning: No port xar found in the index.
Warning: No port libcxx found in the index.
Warning: No port perl5 found in the index.
Warning: No port llvm_select found in the index.
---> Computing dependencies for some-package-0.0 Error: Problem while installing some-package-0.0
Error: Follow https://guide.macports.org/#project.tickets to report a bug.

In that case, that issue happened after Xcode update (which also update the Xcode Command Line Tools that provide GCC). Each time Xcode is updated, licence agreement for GCC must be accepted before it can be used.

If the similar condition apply to your case, it is most likely the issue. You can easily find out by issuing the following command :

gcc -v

If this issue match your case, the following output will be returned :

Agreeing to the Xcode/iOS license requires admin privileges, please run “sudo xcodebuild -license” and then retry this command.

In order to read and accept the license, run the following command as suggested :

sudo xcodebuild -license

Just type “accept” whenever you are done reading the license.

Once done, you may use the “gcc -v” command again to see if the GCC compiler is now usable, if successful, a similar output as below will now be shown :

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 11.0.0 (clang-1100.0.33.16)
Target: x86_64-apple-darwin19.0.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin