Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MacOS "configure: error: cannot run C compiled programs"

I am pretty new to the MacOS environment and I previously had some issue compiling C scripts. I had the following issue:

fatal error: stdio.h: No such file or directory
 #include <stdio.h>
                   ^
compilation terminated.

I tried to re-install xcode-select --install but keep telling me

xcode-select: error: command line tools are already installed, use "Software Update" to install updates

I updated everything and nothing. Apparently it is because I don't have the /usr/includes file. I found a way to compile my software by using

/Library/Developer/CommandLineTools/usr/bin/g++ XXXX.cpp

However, now I am trying to ./compile and make another software but I don't know how to use this gcc interpreter by default. When I try to ./configure I got this error

configure: error: cannot run C compiled programs. If you meant to cross compile, use '--host'. See 'config.log' for more details

So when I do look into config.log :

configure:3224: checking for gcc
configure:3240: found /usr/local/bin/gcc
configure:3251: result: gcc
configure:3282: checking for C compiler version
configure:3291: gcc --version >&5
gcc (GCC) 4.9.2 20141029 (prerelease)
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

configure:3302: $? = 0
configure:3291: gcc -v >&5
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-apple-darwin14.0.0/4.9.2/lto-wrapper
Target: x86_64-apple-darwin14.0.0
Configured with: ../gcc-4.9-20141029/configure --enable-languages=c++,fortran
Thread model: posix
gcc version 4.9.2 20141029 (prerelease) (GCC) 
configure:3302: $? = 0
configure:3291: gcc -V >&5
gcc: error: unrecognized command line option '-V'
gcc: fatal error: no input files
compilation terminated.
configure:3302: $? = 1
configure:3291: gcc -qversion >&5
gcc: error: unrecognized command line option '-qversion'
gcc: fatal error: no input files
compilation terminated.
configure:3302: $? = 1
configure:3322: checking whether the C compiler works
configure:3344: gcc    conftest.c  >&5
configure:3348: $? = 0
configure:3396: result: yes
configure:3399: checking for C compiler default output file name
configure:3401: result: a.out
configure:3407: checking for suffix of executables
configure:3414: gcc -o conftest    conftest.c  >&5
configure:3418: $? = 0
configure:3440: result: 
configure:3462: checking whether we are cross compiling
configure:3470: gcc -o conftest    conftest.c  >&5
conftest.c:15:19: fatal error: stdio.h: No such file or directory
 #include <stdio.h>
                   ^
compilation terminated.
configure:3474: $? = 1
configure:3481: ./conftest
./configure: line 3483: ./conftest: No such file or directory
configure:3485: $? = 127
configure:3492: error: in `/Users/XXXX/phyml':
configure:3494: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details

Do you have any ideas of how I can fix it ?

Thanks a lot !

like image 522
Eddie Avatar asked Oct 29 '18 04:10

Eddie


1 Answers

It's really easy to miss the answer from melpomene in the small comments to this question so let me post this here for everyone to see. This error usually means you're missing compiler tools (headers actually) that have been removed from Xcode.

You can find them in /Library/Developer/CommandLineTools/Packages/ since their name might be different depending on your version of macOS in the future.

Assuming you're running macOS Mojave (10.14), you need to run:

open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

And an macOS-style package installer will start, asking you for your adminstrator password. This is an official Apple package and although it might be weird to install something out of a random directory, you can trust it. You don't have to take my word for it though. Apple buried this change in the Xcode 10 release notes and you can find their explanation here: https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes#3035623

I'll reproduce this here in case this link ever goes away or gets changed:

The Command Line Tools package installs the macOS system headers inside the macOS SDK. Software that compiles with the installed tools will search for headers within the macOS SDK provided by either Xcode at:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk

or the Command Line Tools at:

/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk

depending on which is selected using xcode-select.

The command line tools will search the SDK for system headers by default. However, some software may fail to build correctly against the SDK and require macOS headers to be installed in the base system under /usr/include. If you are the maintainer of such software, we encourage you to update your project to work with the SDK or file a bug report for issues that are preventing you from doing so. As a workaround, an extra package is provided which will install the headers to the base system. In a future release, this package will no longer be provided. You can find this package at:

/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg 
> To make sure that you're using the intended version of the command line tools, run xcode-select -s or xcode select -s /Library/Developer/CommandLineTools after installing.

like image 143
Olivier Lacan Avatar answered Nov 05 '22 09:11

Olivier Lacan