fltk complains about gcc on windows - c

I've been trying for almost a to build fltk on windows in so many different ways but I always end up with:
configure: error: C compiler cannot create executable
(msys fltk/configure)
or
Check for working C compiler: C:/MinGW/bin/gcc.exe -- broken
(CMake-gui)
I've tried it with fltk 1.3.0 and 1.3.3 and I've even used three different MinGW distros, GCC version: 5.1.0; 4.9.2 and 3.4.5. Yet it just won't compile. Here is some of the error log generated by the ./configure file:
$ ./configure --prefix=C:/libs/fltk-1.3.3
-----------
Core tests.
-----------
configure:1336: checking build system type configure:1354: result:
i686-pc-mingw32 configure:1362: checking host system type
configure:1376: result: i686-pc-mingw32 configure:1439: checking for
gcc configure:1455: found /c/mingw32/bin/gcc configure:1465: result:
gcc configure:1709: checking for C compiler version configure:1712:
gcc --version &5 gcc.exe (i686-win32-dwarf-rev2, Built by
MinGW-W64 project) 4.9.2 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:1715: $? = 0 configure:1717: gcc -v &5 Using
built-in specs. COLLECT_GCC=c:\mingw32\bin\gcc.exe
COLLECT_LTO_WRAPPER=c:/mingw32/bin/../libexec/gcc/i686-w64-mingw32/4.9.2/lto-wrapper.exe
Target: i686-w64-mingw32 Configured with:
../../../src/gcc-4.9.2/configure --host=i686-w64-mingw32
--build=i686-w64-mingw32 --target=i686-w64-mingw32 --prefix=/mingw32 --with-sysroot=/c/mingw492/i686-492-win32-dwarf-rt_v4-rev2/mingw32 --with-gxx-include-dir=/mingw32/i686-w64-mingw32/include/c++ --enable-shared --enable-static --disable-multilib --enable-languages=ada,c,c++,fortran,objc,obj-c++,lto --enable-libstdcxx-time=yes --enable-threads=win32 --enable-libgomp --enable-libatomic --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --disable-sjlj-exceptions --with-dwarf2 --disable-isl-version-check --disable-cloog-version-check --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=i686 --with-tune=generic --with-libiconv --with-system-zlib --with-gmp=/c/mingw492/prerequisites/i686-w64-mingw32-static --with-mpfr=/c/mingw492/prerequisites/i686-w64-mingw32-static --with-mpc=/c/mingw492/prerequisites/i686-w64-mingw32-static --with-isl=/c/mingw492/prerequisites/i686-w64-mingw32-static --with-cloog=/c/mingw492/prerequisites/i686-w64-mingw32-static --enable-cloog-backend=isl --with-pkgversion='i686-win32-dwarf-rev2, Built by MinGW-W64 project'
--with-bugurl=http://sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe -I/c/mingw492/i686-492-win32-dwarf-rt_v4-rev2/mingw32/opt/include -I/c/mingw492/prerequisites/i686-zlib-static/include -I/c/mingw492/prerequisites/i686-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe
-I/c/mingw492/i686-492-win32-dwarf-rt_v4-rev2/mingw32/opt/include -I/c/mingw492/prerequisites/i686-zlib-static/include -I/c/mingw492/prerequisites/i686-w64-mingw32-static/include' CPPFLAGS= LDFLAGS='-pipe
-L/c/mingw492/i686-492-win32-dwarf-rt_v4-rev2/mingw32/opt/lib -L/c/mingw492/prerequisites/i686-zlib-static/lib -L/c/mingw492/prerequisites/i686-w64-mingw32-static/lib -Wl,--large-address-aware' Thread model: win32 gcc version 4.9.2 (i686-win32-dwarf-rev2, Built by MinGW-W64 project) configure:1720:
$? = 0 configure:1722: gcc -V &5 gcc.exe: error:
unrecognized command line option '-V' gcc.exe: fatal error: no input
files compilation terminated. configure:1725: $? = 1 configure:1748:
checking for C compiler default output configure:1751: gcc
conftest.c >&5
c:/mingw32/bin/../lib/gcc/i686-w64-mingw32/4.9.2/../../../../i686-w64-mingw32/lib/../lib/libmingw32.a(lib32_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x39):
undefined reference to `WinMain#16' collect2.exe: error: ld returned 1
exit status configure:1754: $? = 1 configure: failed program was: |
line 1728 "configure" | /* confdefs.h. */ | | #define PACKAGE_NAME "" | #define PACKAGE_TARNAME "" | #define PACKAGE_VERSION "" | #define
PACKAGE_STRING "" | #define PACKAGE_BUGREPORT "" | /* end confdefs.h.
*/ | | int main () | { | | ; | return 0; | } configure:1793: error: C compiler cannot create executables See `config.log' for more
details.
configure: exit 77
I previously compiled 2 other gui libraries with these same tools (nana and SFML), so there can't be anything wrong with the gcc compilers.
EDIT
Something (most probably cygwin) keeps breaking my mingw gcc program and every time its "broken" I get black vcc1.exe windows. Then I must replace the mingw folder to get it working again, this happens mostly when I open netbeans. I just don't know how to fix this, so I've just been avoiding cygwin and netbeans.

I was finally able to build it yesterday with this version of TDM-GCC (as per the gui installer):
MinGW-w64/TDM64 (32-bit and 64-bit) ==> TDM-GCC
I used he cmake gui instead of the .configure 1. open cmake gui. 2. input the source code folder (root of fltk folder, ie: "C:/libs/fltk-1.3.3"). 3. input the build folder, ie: "C:/libs/fltk-1.3.3/build/". 4. click configure 5. ** optionally you can change some options but i didn't 6. click Genertae 7. in cmd (I used git bash though): cd to the build directory and run make or mingw32-make
I completely uninstalled cygwin because of its interference with the tool chain builds, i.e mingw and tdm-gcc (Still not sure why this happens).

An easier way to setup a development environment is to use MSYS2.
Download and install
Run MSYS2 Shell
Install some dev tools anf FLTK: pacman -S make automake autoconf libtool mingw-w64-i686-gcc mingw-w64-i686-fltk
Run Mingw64 Shell and you'll be able to easily compile your source: g++ -o myproject myproject.cpp -lfltk

Related

configure: error: C compiler cannot create executables - Mac Sierra

I know these have been posted before, but I'm stuck and can't seem to get anywhere, even by reading copious responses to similar issues to mine.
I get the dreaded "C compiler cannot..." from the title of this post.
I'm on macOS Sierra (long story as to why I'm behind), and have XCode CLT 9.2 installed. I ditched the full XCode app and just went down to the CLT - installed from the Dev area.
Otherwise, I have the latest Homebrew, GCC, Dialog, Libtool, and Automake/Autoconf - some were pre-reqs for the LIRC system I'm trying to get compiled and installed (IR subsystem).
brew config shows that it properly sees the correct XCode CLT, so my guess is that that part is ok.
I get errors once I run the ./configure for this system I'm trying to get up and running...here's the output:
Configuration: .setup.config, executable shell script: configure.sh
Starting the generated shell script which will call configure with the right
parameters...
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... ./install-sh -c -d
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for gcc... gcc
checking whether the C compiler works... no
configure: error: in `/Volumes/Macintosh HD Giant/Users/Nidocamen/Downloads/LIRC-port-for-Mac-OS-X-master':
configure: error: C compiler cannot create executables
See `config.log' for more details
Thought it could be a permissions issue on the LIRC folder, but it's accessible.
I put in a symlink to ensure that gcc is running gcc-9 in /usr/local/bin and ensured that that path is before /usr/bin (brew doctor isn't complaining about that anymore).
Anyways, I'm otherwise really not sure what's causing this to fail. I've been a developer before, but more on the web app side of things and not at this level.
If anyone has some suggestions, I'd love to hear them...thanks! :)
UPDATE - here's some output from the log that would appear to narrow this down. While the people who created this install claims it works well on recent macOS version, it seems like some of the code used is really outdated and that could be why it's not compiling.
Configured with: ../configure --build=x86_64-apple-darwin16 --prefix=/usr/local/Cellar/gcc/9.2.0 --libdir=/usr/local/Cellar/gcc/9.2.0/lib/gcc/9 --disable-nls --enable-checking=release --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-9 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-system-zlib --with-pkgversion='Homebrew GCC 9.2.0' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues
Thread model: posix
gcc version 9.2.0 (Homebrew GCC 9.2.0)
configure:3322: $? = 0
configure:3311: gcc -V >&5
gcc: error: unrecognized command line option '-V'
gcc: fatal error: no input files
compilation terminated.
configure:3322: $? = 1
configure:3311: gcc -qversion >&5
gcc: error: unrecognized command line option '-qversion'; did you mean '--version'?
gcc: fatal error: no input files
compilation terminated.
configure:3322: $? = 1
configure:3342: checking whether the C compiler works
configure:3364: gcc -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -mmacosx-version-min=10.9 conftest.c >&5
ld: library not found for -lSystem
collect2: error: ld returned 1 exit status
configure:3368: $? = 1
configure:3406: result: no
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME ""
| #define PACKAGE_TARNAME ""
| #define PACKAGE_VERSION ""
| #define PACKAGE_STRING ""
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL ""
| #define PACKAGE "lirc"
| #define VERSION "0.9.1-git"
| /* end confdefs.h. */
I had a similar issue, and in my case the "library not found for -lSystem" was caused by a line in my .bash_profile
alias openclc=/System/Library/Frameworks/OpenCL.framework/Libraries/openclc
No idea why I had put that in there, but unalias-ing it fixed my issues...

MINGW + SQLITE3 - DLL / Linker Issues

Trying to call SQLITE3 functions in MINGW C - program does not behave as expected. I suspect the issue is around the .a file but cannot see where or why there is no output.
Installed latest MinGW Distro from nuwen.net on Windows 10 in c:\mingw.
C:\c>gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/x86_64-w64-mingw32/8.1.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../src/configure --enable-languages=c,c++ --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --disable-multilib --prefix=/c/temp/gcc/dest --with-sysroot=/c/temp/gcc/dest --disable-libstdcxx-pch --disable-libstdcxx-verbose --disable-nls --disable-shared --disable-win32-registry --with-tune=haswell --enable-threads=posix --enable-libgomp
Thread model: posix
gcc version 8.1.0 (GCC)
Downloaded sqlite-amalgamation-3260000.zip, sqlite-dll-win64-x64-3260000.zip and sqlite-tools-win32-x86-3260000.zip from sqlite.org.
The headers sqlite3.h and sqlite3ext.h were copied from sqlite-amalgamation-3260000.zip to the include\sqlite3 directory.
The files sqlite3.def and sqlite3.dll were extracted from sqlite-dll-win64-x64-3260000.zip to a temporary directory.
In the temporary directory, I ran dlltool -U -d sqlite3.def -l libsqlite3.a (as described in http://www.mingw.org/wiki/createimportlibraries).
(note I tried with and without -U and -k flags)
No messages were output and the libsqlite3.a file is approx 200K (although I note .DLL is 10x size). I copied the resultant libsqlite3.a to the lib directory.
I write a quick test3.c program just to check I can call an sqlite function correctly:
#include <stdio.h>
#include "sqlite3\sqlite3.h"
sqlite3* db;
int main() {
printf("Start\n");
sqlite3_open("test.db", &db);
if(db == 0) {
printf("Could not open database.\n");
}
else {
printf("Database Open \n");
}
}
I compile with no errors using: gcc test3.c -lsqlite3
I run a.exe and see absolutely nothing - not even the "Start" string printed
I comment out just the "sqlite3_open" line and recompile with same command then run again and I see
C:\c>a
Start
Could not open database.
As behaviour is unexpected when calling an sqlite3 function, and as the .a file is a tenth of the size of the .DLL, I suspect the problem is there - but still cannot see why the "Start" is not output.

Compiling c program with MinGW causes cc1.exe fatal error

I installed MinGW-w64 using win-builds.
It all went ok but then when I compile a file using
gcc -Wall -o prog.exe main.c
I get this error
cc1.exe: fatal error: Files/win-builds-1.5.0/include: No such file or directory
compilation terminated.
I have updated gcc path. I get the same error when I try to build on eclipse.
The location where win-builds put all the files is C:\Program Files\win-builds-1.5.0\ and the folder \include\ exists.
My guess is that cc1.exe is trying to access C:\Program Files\win-builds-1.5.0\include but, for some reason it is separating C:\Program of Files\win-builds-1.5.0\include.
How can I get the compiler to work?
EDIT:
Here is the code to be compiled
/*
* main.c
*
* Created on: 13/06/2018
* Author: haslima
*/
#include <stdio.h>
int main()
{
printf("Hello World");
return 1;
}
EDIT:
when I run gcc -v -c -o prog.exe main.c I get this output:
Reading specs from c:/program files/win-builds-1.5.0/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/specs
COLLECT_GCC=gcc
Target: x86_64-w64-mingw32
Configured with: ../gcc-4.8.3/configure --prefix=/opt/windows_64 --with-sysroot=/opt/windows_64 --libdir=/opt/windows_64/lib64 --mandir=/opt/windows_64/man --infodir=/opt/windows_64/info --enable-shared --disable-bootstrap --disable-multilib --enable-threads=posix --enable-languages=c,c++ --enable-checking=release --enable-libgomp --with-system-zlib --with-python-dir=/lib64/python2.7/site-packages --disable-libunwind-exceptions --enable-__cxa_atexit --enable-libssp --with-gnu-ld --verbose --enable-java-home --with-java-home=/opt/windows_64/lib64/jvm/jre --with-jvm-root-dir=/opt/windows_64/lib64/jvm --with-jvm-jar-dir=/opt/windows_64/lib64/jvm/jvm-exports --with-arch-directory=amd64 --with-antlr-jar='/home/adrien/projects/win-builds-1.5/slackware64-current/d/gcc/antlr-*.jar' --disable-java-awt --disable-gtktest --build=x86_64-slackware-linux --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32
Thread model: posix
gcc version 4.8.3 (GCC)
COLLECT_GCC_OPTIONS='-v' '-c' '-o' 'prog.exe' '-mtune=generic' '-march=x86-64'
c:/program files/win-builds-1.5.0/bin/../libexec/gcc/x86_64-w64-mingw32/4.8.3/cc1.exe -quiet -v -iprefix c:\program files\win-builds-1.5.0\bin\../lib64/gcc/x86_64-w64-mingw32/4.8.3/ -D_REENTRANT -IC:/Program Files/win-builds-1.5.0/include main.c -quiet -dumpbase main.c -mtune=generic -march=x86-64 -auxbase-strip prog.exe -version -o C:\Users\hasli\AppData\Local\Temp\ccnpAzB7.s
GNU C (GCC) version 4.8.3 (x86_64-w64-mingw32)
compiled by GNU C version 4.8.3, GMP version 5.1.3, MPFR version 3.1.2, MPC version 0.8.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring duplicate directory "c:/program files/win-builds-1.5.0/lib64/gcc/../../lib64/gcc/x86_64-w64-mingw32/4.8.3/include"
ignoring nonexistent directory "/opt/windows_64/opt/windows_64/lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../include"
ignoring duplicate directory "c:/program files/win-builds-1.5.0/lib64/gcc/../../lib64/gcc/x86_64-w64-mingw32/4.8.3/include-fixed"
ignoring duplicate directory "c:/program files/win-builds-1.5.0/lib64/gcc/../../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/include"
ignoring nonexistent directory "/opt/windows_64/mingw/include"
ignoring nonexistent directory "C:/Program"
#include "..." search starts here:
#include <...> search starts here:
c:\program files\win-builds-1.5.0\bin\../lib64/gcc/x86_64-w64-mingw32/4.8.3/include
c:\program files\win-builds-1.5.0\bin\../lib64/gcc/x86_64-w64-mingw32/4.8.3/include-fixed
c:\program files\win-builds-1.5.0\bin\../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/include
End of search list.
cc1.exe: fatal error: Files/win-builds-1.5.0/include: No such file or directory
compilation terminated.
From [MinGW]: Getting Started (including bolds):
MinGW may have problems with paths containing spaces, and if not, usually other programs used with MinGW will experience problems with such paths. Thus, we strongly recommend that you do not install MinGW in any location with spaces in the path name reference. You should avoid installing into any directory or subdirectory having names like "Program Files" or "My Documents", etc.
So, the solution is pretty straightforward:
Uninstall your current version (might not be necessary, but there's no point keeping something broken)
Make sure to read all installation requirements / notes
Install it in a SPACE free dir
I should have thought of this sooner, as I don't install stuff in default dirs (e.g. I have MinGW installed in "f:\Install\pc064\MinGW\MinGW-W64\x86_64-8.1.0-posix-seh-rt_v6-rev0").

gcc creates a different folder base on its version

When I try to rpmbuild something I got this error message
checking for x86_64-redhat-linux-gcc... no
checking for gcc... no
checking for x86_64-redhat-linux-cc... no
checking for cc... no
checking for x86_64-redhat-linux-cl.exe... no
checking for cl.exe... no
And I found out that, the tool are in /usr/bin/gcc48 what I did is link the gcc48 to gcc folder: Which I got the idea from this link https://stackoverflow.com/a/13327320/612920
ln /usr/bin/gcc48 /usr/bin/gcc
And when I tried to run rpmbuild again I got this error message:
checking for x86_64-redhat-linux-gcc... no
checking for gcc... gcc
checking whether the C compiler works... no
configure: error: in `/usr/src/rpm/BUILD/courier-unicode-1.1':
configure: error: C compiler cannot create executables
See `config.log' for more details
error: Bad exit status from /var/tmp/rpm-tmp.jrbnrw (%prep)
What is wrong? I had already installed all development tools and its on its latest versions. Can Somebody help me?
And by the way I am using Amazons Redhat (gcc version 4.8.2 20131212 (Red Hat 4.8.2-7) (GCC))
UPDATED:
config.log
configure:3499: $? = 0
configure:3488: gcc -v >&5
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-amazon-linux/4.8.2/lto-wrapper
Target: x86_64-amazon-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugu$
Thread model: posix
gcc version 4.8.2 20131212 (Red Hat 4.8.2-7) (GCC)
configure:3499: $? = 0
configure:3488: gcc -V >&5
gcc: error: unrecognized command line option '-V'
gcc: fatal error: no input files
compilation terminated.
configure:3499: $? = 4
configure:3488: gcc -qversion >&5
gcc: error: unrecognized command line option '-qversion'
gcc: fatal error: no input files
compilation terminated.
configure:3499: $? = 4
configure:3519: checking whether the C compiler works
configure:3541: gcc -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp$
collect2: fatal error: cannot find 'ld'
compilation terminated.
configure:3545: $? = 1
configure:3583: result: no
configure: failed program was:
| /* end confdefs.h. */
|
| int
| main ()
| {
|
| ;
| return 0;
| }
configure:3588: error: in `/home/falko/rpm/BUILD/courier-unicode-1.1':
configure:3590: error: C compiler cannot create executables
gcc is one of a number of tools required to build a software package, and as you can see from the error in your config.log, some more are missing from your system:
collect2: fatal error: cannot find 'ld'
It is complaining that it cannot find the system linker (ld).
Before addressing this, I recommend you set the gcc version to be used correctly. Unfortunately the advice you followed from https://stackoverflow.com/a/13327320/612920 is somewhat incomplete.
Redhat based systems provide a mechanism for being able to switch between different implementations of a piece of software at will (for example, different versions). This tool is called alternatives. You should use that to set the GCC version that will be used when you run 'gcc' at the command line. It will update a whole set of symlinks, not just the one you manually set.
sudo alternatives --config gcc
After doing this set the linker to be used:
sudo alternatives --config ld
Note that when I've tried out an AMI linux image, I found that by installing gcc like this:
sudo yum install gcc48
it automatically set the correct 'alternatives' for the newly installed compiler and corresponding linker. I'm not sure how your system got into the state that it is currently in, but if you still have problems after the above procedure, I recommend uninstalling and re-installing gcc and binutils.
After a couple of research I had found out that I am just lacking of ld(GNU linker) tool from RedHat's developer tool set and I also found out that there is an alternative tool just in case ld(GNU linker) is not available, ld.bfd(alternative to the GNU linker) which is in my case it is available. What I did, I make a link from ld.bfd to ld:
ln /usr/bin/ld.bfd /usr/bin/ld
I don't know if it is the proper solution but it works for me.
Reference: Red_Hat_Developer_Toolset

stdlib.h: no such file or directory

I am using various stdlib functions like srand(), etc. I have the line
#include <stdlib.h>
at the top of my code.
I entered this on the command line:
# find / -name stdlib.h
find: `/home/dmurvihill/.gvfs: permission denied
/usr/include/stdlib.h
/usr/include/bits/stdlib.h
So, stdlib.h is clearly in /usr/include.
My preprocessor:
# gcc -print-prog-name=cc1
/usr/libexec/gcc/x86_64-redhat-linux/4.5.1/cc1
My preprocessor's default search path:
# /usr/libexec/gcc/x86_64-redhat-linux/4.5.1/cc1 -v
ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.5.1/include-fixed"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../x86_64-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/lib/gcc/x86_64-redhat-linux/4.5.1/include
/usr/include
End of search list.
So, stdlib.h is clearly in /usr/include, which is most definitely supposed to be searched by my preprocessor, but I still get this error!
/path/to/cpa_sample_code_main.c:15:20: fatal error: stdlib.h: No such file or directory
compilation terminated
Update
A program I wrote to test this code:
#include <stdio.h>
#include <stdlib.h>
#include <linux/time.h>
int main()
{
printf("Hello, World!\n");
printf("Getting time...\n");
time_t seconds;
time(&seconds);
printf("Seeding generator...\n");
srand((unsigned int)seconds);
printf("Getting random number...\n");
int value = rand();
printf("It is %d!",value);
printf("Goodbye, cruel world!");
return 0;
}
The command
gcc -H -v -fsyntax-only stdlib_test.c
output
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.5.1/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,lto --enable-plugin --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.5.1 20100924 (Red Hat 4.5.1-4) (GCC)
COLLECT_GCC_OPTIONS='-H' '-v' '-fsyntax-only' '-mtune=generic' '-march=x86-64'
/usr/libexec/gcc/x86_64-redhat-linux/4.5.1/cc1 -quiet -v -H /CRF_Verify/stdlib_test.c -quiet -dumpbase stdlib_test.c -mtune=generic -march=x86-64 -auxbase stdlib_test -version -fsyntax-only -o /dev/null
GNU C (GCC) version 4.5.1 20100924 (Red Hat 4.5.1-4) (x86_64-redhat-linux)
compiled by GNU C version 4.5.1 20100924 (Red Hat 4.5.1-4), GMP version 4.3.1, MPFR version 2.4.2, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.5.1/include-fixed"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../x86_64-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/lib/gcc/x86_64-redhat-linux/4.5.1/include
/usr/include
End of search list.
GNU C (GCC) version 4.5.1 20100924 (Red Hat 4.5.1-4) (x86_64-redhat-linux)
compiled by GNU C version 4.5.1 20100924 (Red Hat 4.5.1-4), GMP version 4.3.1, MPFR version 2.4.2, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: ea394b69293dd698607206e8e43d607e
. /usr/include/stdio.h
.. /usr/include/features.h
... /usr/include/sys/cdefs.h
.... /usr/include/bits/wordsize.h
... /usr/include/gnu/stubs.h
.... /usr/include/bits/wordsize.h
.... /usr/include/gnu/stubs-64.h
.. /usr/lib/gcc/x86_64-redhat-linux/4.5.1/include/stddef.h
.. /usr/include/bits/types.h
... /usr/include/bits/wordsize.h
... /usr/include/bits/typesizes.h
.. /usr/include/libio.h
... /usr/include/_G_config.h
.... /usr/lib/gcc/x86_64-redhat-linux/4.5.1/include/stddef.h
.... /usr/include/wchar.h
... /usr/lib/gcc/x86_64-redhat-linux/4.5.1/include/stdarg.h
.. /usr/include/bits/stdio_lim.h
.. /usr/include/bits/sys_errlist.h
. /usr/include/stdlib.h
.. /usr/lib/gcc/x86_64-redhat-linux/4.5.1/include/stddef.h
.. /usr/include/bits/waitflags.h
.. /usr/include/bits/waitstatus.h
... /usr/include/endian.h
.... /usr/include/bits/endian.h
.... /usr/include/bits/byteswap.h
..... /usr/include/bits/wordsize.h
.. /usr/include/sys/types.h
... /usr/include/time.h
... /usr/lib/gcc/x86_64-redhat-linux/4.5.1/include/stddef.h
... /usr/include/sys/select.h
.... /usr/include/bits/select.h
..... /usr/include/bits/wordsize.h
.... /usr/include/bits/sigset.h
.... /usr/include/time.h
.... /usr/include/bits/time.h
... /usr/include/sys/sysmacros.h
... /usr/include/bits/pthreadtypes.h
.... /usr/include/bits/wordsize.h
.. /usr/include/alloca.h
... /usr/lib/gcc/x86_64-redhat-linux/4.5.1/include/stddef.h
. /usr/include/linux/time.h
.. /usr/include/linux/types.h
... /usr/include/asm/types.h
.... /usr/include/asm-generic/types.h
..... /usr/include/asm-generic/int-ll64.h
...... /usr/include/asm/bitsperlong.h
....... /usr/include/asm-generic/bitsperlong.h
... /usr/include/linux/posix_types.h
.... /usr/include/linux/stddef.h
.... /usr/include/asm/posix_types.h
..... /usr/include/asm/posix_types_64.h
In file included from /CRF_Verify/stdlib_test.c:3:0:
/usr/include/linux/time.h:9:8: error: redefinition of ‘struct timespec’
/usr/include/time.h:120:8: note: originally defined here
/usr/include/linux/time.h:15:8: error: redefinition of ‘struct timeval’
/usr/include/bits/time.h:75:8: note: originally defined here
Multiple include guards may be useful for:
/usr/include/asm/posix_types.h
/usr/include/bits/byteswap.h
/usr/include/bits/endian.h
/usr/include/bits/select.h
/usr/include/bits/sigset.h
/usr/include/bits/stdio_lim.h
/usr/include/bits/sys_errlist.h
/usr/include/bits/time.h
/usr/include/bits/typesizes.h
/usr/include/bits/waitflags.h
/usr/include/bits/waitstatus.h
/usr/include/gnu/stubs-64.h
/usr/include/gnu/stubs.h
/usr/include/wchar.h
Your error appears to stem from including linux/time.h when also trying to include stdlib.h. linux/time.h is a kernel header and should only be used in kernel code. stdlib.h is a user-land function and should only be used in user programs. If you notice the error you get:
/usr/include/linux/time.h:12: error: redefinition of 'struct timespec'
/usr/include/linux/time.h:18: error: redefinition of 'struct timeval'
you can see that you are getting an error related to this. As seen in your long trace, this is because stdlib.h is including time.h (the one in /usr/include, not /usr/include/linux). I imagine that this is the real cause of the error you see about not finding stdlib.h (although I cannot imagine the details of how the errors are occurring the way they are).
For anyone who landed here trying to compile a C++ program with Cygwin on Windows, my problem was that I had both MingW and Cygwin. MingW was installed as part of the Cygwin setup. I used the setup.exe (let's call it package installer) from Cygwin and removed all instances of MingW. After that, my test application compiled properly.
Note: This solution is what worked for me. There are gazillion other reasons why you have the same error.
I've found another cause when using g++ v6.x, bug 70129. I triggered it when specifying -isystem (via CMake's SYSTEM keyword) for a Boost include directory - which ultimately included cstdlib.

Resources