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

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 !

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.

Related

"fatal error: bits/libc-header-start.h: No such file or directory" while compiling HTK

I'm getting the following issue when trying to run make on the HTK library:
(cd HTKLib && make HTKLib.a) \
|| case "" in *k*) fail=yes;; *) exit 1;; esac;
make[1]: Entering directory '/home/william/speech/htk/HTK-3.4.1/htk/HTKLib'
gcc -m32 -ansi -D_SVID_SOURCE -DOSS_AUDIO -D'ARCH="x86_64"' -Wall -Wno-switch -g -O2 -I. -DPHNALG -c -o HGraf.o HGraf.c
In file included from HShell.h:40:0,
from HGraf.c:54:
/usr/include/stdio.h:27:10: fatal error: bits/libc-header-start.h: No such file or directory
#include <bits/libc-header-start.h>
^~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
<builtin>: recipe for target 'HGraf.o' failed
make[1]: *** [HGraf.o] Error 1
make[1]: Leaving directory '/home/william/speech/htk/HTK-3.4.1/htk/HTKLib'
Makefile:96: recipe for target 'HTKLib/HTKLib.a' failed
make: *** [HTKLib/HTKLib.a] Error 1
I'm unsure what to do about this error. The libc-header-start.h file is present on my system:
$ find /usr -name libc-header-start.h
/usr/include/x86_64-linux-gnu/bits/libc-header-start.h
Running gcc -H -fsyntax-only /usr/include/stdio.h appropriately returns
. /usr/include/x86_64-linux-gnu/bits/libc-header-start.h
.. /usr/include/features.h
... /usr/include/x86_64-linux-gnu/sys/cdefs.h
etc.
Also, compiling and running a sanity-check C file works fine (simply executing printf("hello!"); in its main method).
Apologies if this is a well-known error - my experience with C libraries stops at compiling and installing them using make.
UPDATE
Per the accepted answer below I executed sudo apt-get install gcc-multilib to install the missing 32 bit libraries.
Afterwards I got an error with a similar cause: "/usr/bin/ld: cannot find -lX11" error when installing htk. I resolved this by executing sudo apt-get install libx11-dev:i386 libx11-dev to retrieve the missing 32 bit library.
The -m32 is telling gcc to compile for a 32-bit platform. On a 64-bit machine, gcc normally only comes with 64-bit libraries. You have two options:
Install 32-bit headers and libraries. Here's how you'd do this on Ubuntu.
Run this command:
sudo apt-get install gcc-multilib
Compile for 64-bit instead. Modify this line in the file named configure:
CFLAGS="-m32 -ansi -D_SVID_SOURCE -DOSS_AUDIO -D'ARCH=\"$host_cpu\"' $CFLAGS"
Delete -m32, giving you:
CFLAGS="-ansi -D_SVID_SOURCE -DOSS_AUDIO -D'ARCH=\"$host_cpu\"' $CFLAGS"
Run ./configure, then make clean, then make
However, I would recommend against this approach. The library authors went out of their way to make this build for 32 bits on a 64 bit system, and I can't guarantee that it will work correctly if you do this. (It does compile, though.)
Below is one way to debug and fix this issue. Since most linux installations differ in one way or another, YMMV.
Find which package installed libc-header-start.h.
$ dpkg -S libc-header-start.h
libc6-dev:amd64: /usr/include/x86_64-linux-gnu/bits/libc-header-start.h
On a working system, /usr/include/bits is a symlink to /usr/include/x86_64-linux-gnu/bits. Running dpkg search gives us:
$ dpkg -S /usr/include/bits
libc6-dev-i386: /usr/include/bits
Installing libc6-dev-i386 creates the symlink and the error is addressed.
However, subsequently I ran into a linker error with the linker not being able to find libgcc (-lgcc). Apparently Linux default linker needs libgcc in most cases. Further debugging the issue with linker verbosity enabled lead me to missing lib32gcc-10-dev package.
In short, unless a very controlled build environment is desired, just install gcc-multilib package when using -m32 (needed for gcc or clang). For C++, g++-multilib is also required.

GCC as m68k cross-compiler

I am trying to recompile binutils and GCC as a cross-compiler for m68k architecture. I am following these instructions:
http://darkdust.net/writings/megadrive/crosscompiler
However, the process keeps failing on one part or another. I have tried with binutils 2.16.1 and gcc 3.4.6, binutils 2.15 and gcc 3.4.2 and binutils 2.15 and gcc 3.4.6.
This last attempt fails when running "make" on gcc, after making and installing binutils. It gives the following error:
gcc -g -O2 -DIN_GCC -DCROSS_COMPILE -W -Wall -Wwrite-strings -Wstrict-
prototypes -Wmissing-prototypes -pedantic -Wno-long-long -DHAVE_CONFIG_H
-I. -I. -I../../gcc-3.4.2/gcc -I../../gcc-3.4.2/gcc/. -I../../gcc-
3.4.2/gcc/../include \
-DTARGET_MACHINE=\"m68k-coff\" \
-c ../../gcc-3.4.2/gcc/collect2.c -o collect2.o
In file included from /usr/include/fcntl.h:289:0,
from ../../gcc-3.4.2/gcc/system.h:214,
from ../../gcc-3.4.2/gcc/collect2.c:30:
In function ‘open’,
inlined from ‘collect_execute’ at ../../gcc-3.4.2/gcc/collect2.c:1535:20:
/usr/include/x86_64-linux-gnu/bits/fcntl2.h:50:4: error: call to
‘__open_missing_mode’ declared with attribute error: open with O_CREAT or
O_TMPFILE in second argument needs 3 arguments
__open_missing_mode ();
^
Makefile:1364: recipe for target 'collect2.o' failed
make[1]: *** [collect2.o] Error 1
make[1]: Leaving directory '/home/gabriel/src/gcc-build/gcc'
Makefile:23339: recipe for target 'all-gcc' failed
make: *** [all-gcc] Error 2
I don't expect to fix this error, but does anyone know of a combination of binutils and gcc release that work? Should I be using a certain version of gcc to recompile gcc successfuly?
Thanks for any insight you may have on this!
EDIT:
My linux has GCC 5.4.0 so I just downloaded the 5.4.0 source to try and rebuild that for m68k cross-compiling. I now get the following error when running "make" on the gcc source:
*** Configuration m68k-unkown-coff not supported
What could be the cause of this? Is it because I need an older version of GCC? (the binutils version i'm using definately supports the m68k target). The tutorial I'm using always defines "--target=m68k-coff", should that instead be "--target=m68k-unkown-coff"?
EDIT 2:
So I tried compiling for m68k-elf but now I get this error:
checking for m68k-elf-gcc... /home/gabriel/src/gcc-build/./gcc/xgcc -B/home/gabriel/src/gcc-build/./gcc/ -B/opt/m68k/m68k-elf/bin/ -B/opt/m68k/m68k-elf/lib/ -isystem /opt/m68k/m68k-elf/include -isystem /opt/m68k/m68k-elf/sys-include
checking for suffix of object files... configure: error: in `/home/gabriel/src/gcc-build/m68k-elf/libgcc':
configure: error: cannot compute suffix of object files: cannot compile
I ran download_prerequisites before building so it should not be a problem with the MPC library. Any idea how to move on? I need assembler only so I don't mind what the format of the object files is. Thanks!
I used to do pretty much what you are doing right now.
My advice is to use crosstool-ng (http://crosstool-ng.github.io), as it does pretty much everything in an automated manner.
If you are studying m68k assembly, I used to host a modified version of gcc-explorer by Matt Godbolt (https://godbolt.org/). You can find a runnable docker image here (https://hub.docker.com/r/esantoro/acso-explorer/) and some more details here (https://znpy.wordpress.com/2017/05/08/decommisioning-acso-explorer-santoro-tk/)
Hope it helps,
znpy
you can build most versions with a current Linux. To install the prerequisites have a look at https://github.com/bebbo/amiga-gcc
unpack the gcc archive, e.g. to /opt/cross/gcc-6.5.0
create a separate build folder, e.g. /opt/cross/xcc-6.5.0 - never build inside gcc's source folder!
create the prefix folder, that's where binaries are installed to, e.g. /opt/cross/gcc65
ensure that these folders exist and are writable, then
configure from within that build folder using an absolute path for configure
cd /opt/cross/xcc-6.5.0/
/opt/cross/gcc-6.5.0/configure --target=m68k-elf --program-prefix=m68k-elf- --enable-languages=c,c++ --prefix=/opt/cross/gcc65 --disable-libssp --disable-nls --disable-multilib
make all-gcc
make install-gcc
I'm also running the compiler explorer for 68k gccs at https://franke.ms/cex/

Compiling C Program to WebAssembly Program with "Error: No available targets are compatible with this triple" on Ubuntu 16.10

Following this tutorial, I tried to compile a C program to WebAssembly by using the following command.
emcc hello.c -s WASM=1 -o hello.html
But I ecounter the "No available targets are compatible with this triple." problem.
$ emcc hello.c -s WASM=1 -o hello.html
WARNING root: LLVM version appears incorrect (seeing "(https://github.com/kripken/emscripten-fastcomp-clang/", expected "3.4")
INFO root: (Emscripten: Running sanity checks)
WARNING root: Assigning a non-existent settings attribute "WASM"
WARNING root: - did you mean one of ASM_JS?
WARNING root: - perhaps a typo in emcc's -s X=Y notation?
WARNING root: - (see src/settings.js for valid values)
/home/casper/Desktop/test/emsdk/clang/fastcomp/build_incoming_64/bin/lli: error creating EE: No available targets are compatible with this triple.
FAIL: Running the generated program failed!
How to solve it?
EMCC Version
$ emcc --version
emcc (Emscripten GCC-like replacement) 1.22.1 ()
Copyright (C) 2014 the Emscripten authors (see AUTHORS.txt)
This is free and open source software under the MIT license.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Basic Information
OS : Ubuntu 16.10
emcc Location: /usr/bin/emcc
You're running emcc version 1.22.1 which dates back from 8/7/2014, before WebAssembly was started.
emsdk in the instruction you followed must have installed a very recent emscripten version (this is what sdk-incoming-64bit from these instructions does: incoming is the latest branch), but an older emscripten is found in your system.
Run:
which emcc
echo $PATH
What do they say? I suspect you have an old emscripten lying in there. You probably also want to check and/or delete your ~/.emscripten file which may also contain obsolete information.
You can alter your path, delete the older emscripten, or invoke the SDK's emscripten using its absolute path (though this may fail later if other scripts pick up older versions along the path).
Don't forget (from the tutorial's instructions) to activate the SDK you've installed:
./emsdk activate --build=Release sdk-incoming-64bit binaryen-master-64bit
And run:
source ./emsdk_env.sh
This last command needs to be run for every shell session. If you open a new shell you need to re-source then SDK.

compiling Vim 7.4 under AIX 6.1

I have a problem while compiling Vim 7.4 under AIX 6.1.
My options for the configure script are: "--prefix /opt/freeware/bin" and "--enable-pythoninterp".
There where no Errors while running the configure Script but when I try to run "make" I get the error message:
cd src && make first
cc -qlanglvl=extc89 -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_ATHENA -DFUNCPROTO=15 -g -o objects/regexp.o regexp.c "regexp_nfa.c"
line 4410.1: 1506-046 (S) Syntax error.
make: 1254-004 > The error code from the last command is
1.
Stop. make: 1254-004 The error code from the last command is 2.
Stop.
Does anyone know what to do?
I had compiled Vim 7.4 in my home directory so I know that there is a workaround but I can't find it anymore.
AIX's built in make (based on standard AT&T make) is not compatible with the Makefiles built by autoconf tools. Use GNU make (gmake) instead. You may already have it installed (check /opt/freeware/bin), install from the Linux Toolbox for AIX set (from IBM), or from one of the websites providing prebuilt GNU tools for AIX systems (perzl, bullfreeware, etc). Just provide an alias from make to gmake, or override the use of make in the Makefile itself.

-mno-cygwin : gcc building Mercurial (Windows 2000)

Because the Mercurial Installer will not work on an old Windows 2000 system, I'm trying to build it from source. Its complaining that the C Compiler doesn't recognize the option -mno-cygwin. My version of gcc is 4.6.1. and MinGw is only two months old.
Followed these steps: https://www.mercurial-scm.org/wiki/BuildingOnWindows
F:\mercurial-2.0.2>python setup.py build
running build
running build_mo
warning: hgbuildmo: could not find msgfmt executable, no translations will be built
running build_py
package init file 'mercurial\__init__.py' not found (or not a regular file)
package init file 'mercurial\__init__.py' not found (or not a regular file)
running build_ext
building 'mercurial.base85' extension
f:\mingw\bin\gcc.exe -mno-cygwin -mdll -O -Wall -If:\python27\include
-If:\python27\PC -c mercurial/base85.c -o build\temp.win32-2.7\Release\mercurial\base85.o
**cc1.exe: error: unrecognized command line option '-mno-cygwin'**
error: command 'gcc' failed with exit status 1
From a comment by a TDM-GCC MinGW distro developer:
As of the 4.6 series, GCC no longer accepts many unrecognized options
or flags. TDM-GCC has never "supported" -mno-cygwin; now, it will
complain about it. This is also true for libtool flags such as
"-no-undefined".
So you may have to use a somewhat older GCC version that will ignore the meaningless option, or fix the build scripts so they don't use that flag (which would never be necessary with the MinGW compiler anyway).
As a follow-on note, it looks like the Cygwin compiler stopped supporting -mno-cygwin starting with GCC 4: http://www.cygwin.com/ml/cygwin/2009-03/msg00802.html
So that option has been more or less useless for a couple years.
You not to forget this step before running "python setup.py build"?
If using mingw, a setup.cfg needs to be created which directs setuptools to use it:
cd mercurial
echo [build] > setup.cfg
echo compiler=mingw32 >> setup.cfg

Resources