Compiling c program with MinGW causes cc1.exe fatal error - c

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").

Related

Mingw64 / Msys2 - gcc unable to find headers in its own include dir

I recently installed MSYS2 following Steely Wing's answer on this thread: How to install MinGW-w64 and MSYS2?
The final goal is to compile a project on Windows in order to create an executable that I can use with an installer.
But here comes the problem: when I use make, gcc does not find err.h:
src/debug/error_handler.c:2:10: fatal error: err.h: No such file or directory
2 | #include <err.h>
| ^~~~~~~
compilation terminated.
make: *** [Makefile:26: imagin] Interrupt
After some searching I found out that it could come from the MinGW's default Include path. Thus following this: http://mingw.org/wiki/IncludePathHOWTO, I created an empty foo.c and executed gcc -v foo.c:
Configured with: ../gcc-9.2.0/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/mingw64/x86_64-w64-mingw32/include --libexecdir=/mingw64/lib --enable-bootstrap --with-arch=x86-64 --with-tune=generic --enable-languages=c,lto,c++,fortran,ada,objc,obj-c++ --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-filesystem-ts=yes --enable-libstdcxx-time=yes --disable-libstdcxx-pch --disable-libstdcxx-debug --disable-isl-version-check --enable-lto --enable-libgomp --disable-multilib --enable-checking=release --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --enable-plugin --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion='Rev2, Built by MSYS2 project' --with-bugurl=https://sourceforge.net/projects/msys2 --with-gnu-as --with-gnu-ld
Thread model: posix
gcc version 9.2.0 (Rev2, Built by MSYS2 project)
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/cc1.exe -quiet -v -iprefix C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/ -D_REENTRANT foo.c -quiet -dumpbase foo.c -mtune=generic -march=x86-64 -auxbase foo -version -o C:\msys64\tmp\ccXlDSUc.s
GNU C17 (Rev2, Built by MSYS2 project) version 9.2.0 (x86_64-w64-mingw32)
compiled by GNU C version 9.2.0, GMP version 6.1.2, MPFR version 4.0.2, MPC version 1.1.0, isl version isl-0.21-GMP
warning: GMP header version 6.1.2 differs from library version 6.2.0.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring duplicate directory "C:/msys64/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/9.2.0/include"
ignoring nonexistent directory "C:/building/msys64/mingw64/include"
ignoring nonexistent directory "/mingw64/include"
ignoring duplicate directory "C:/msys64/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/9.2.0/include-fixed"
ignoring duplicate directory "C:/msys64/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/include"
ignoring nonexistent directory "C:/building/msys64/mingw64/x86_64-w64-mingw32/include"
#include "..." search starts here:
#include <...> search starts here:
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/include
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../include
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/include-fixed
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/include
End of search list.
GNU C17 (Rev2, Built by MSYS2 project) version 9.2.0 (x86_64-w64-mingw32)
compiled by GNU C version 9.2.0, GMP version 6.1.2, MPFR version 4.0.2, MPC version 1.1.0, isl version isl-0.21-GMP
warning: GMP header version 6.1.2 differs from library version 6.2.0.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 3bcdf03344e3ad7cb057c2ec82f696e6
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/as.exe -v -o C:\msys64\tmp\cckgYpTe.o C:\msys64\tmp\ccXlDSUc.s
GNU assembler version 2.33.1 (x86_64-w64-mingw32) using BFD version (GNU Binutils) 2.33.1
COMPILER_PATH=C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/;C:/msys64/mingw64/bin/../lib/gcc/;C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/
LIBRARY_PATH=C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/;C:/msys64/mingw64/bin/../lib/gcc/;C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/lib/../lib/;C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../lib/;C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/lib/;C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/collect2.exe -plugin C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/liblto_plugin-0.dll -plugin-opt=C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/lto-wrapper.exe -plugin-opt=-fresolution=C:\msys64\tmp\cch1aQIi.res -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_eh -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -plugin-opt=-pass-through=-lpthread -plugin-opt=-pass-through=-ladvapi32 -plugin-opt=-pass-through=-lshell32 -plugin-opt=-pass-through=-luser32 -plugin-opt=-pass-through=-lkernel32 -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_eh -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -m i386pep -Bdynamic C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/crtbegin.o -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0 -LC:/msys64/mingw64/bin/../lib/gcc -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/lib/../lib -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../lib -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/lib -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../.. C:\msys64\tmp\cckgYpTe.o -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt -lpthread -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/lib/../lib/default-manifest.o C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/crtend.o
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o): in function `main':
D:/mingwbuild/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crt0_c.c:18: undefined reference to `WinMain'
collect2.exe: error: ld returned 1 exit status
This is a bit messy but I think the interesting part is there:
#include "..." search starts here:
#include <...> search starts here:
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/include
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../include
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/include-fixed
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/include
Considering the fact that err.h comes from openssl that I installed using https://packages.msys2.org/package/mingw-w64-x86_64-openssl, openssl folder is included in /mingw64/include. But gcc does not find it.
I tried to use -I/mingw64/include in my CFLAGS, but it did not work. I tried with -I/mingw64/include/openssl and it worked, but now gcc considers errx function as unititialized, as if, before, gcc never went in the openssl folder. I tried to add -L/mingw64/lib but it did not work.
Any help is appreciated, thank's by advance. DO NOT hesitate to ask for any precision I could have miss here.
After hours of searching I found out that there was no err.h on MSYS2, see https://github.com/cliffordwolf/icestorm/issues/85 and resolved my case by replacing all my errx() function calls following these method https://github.com/cliffordwolf/icestorm/pull/88/commits/9acaac752ac53b51b9b33290394b7811048221fa.

installed gcc include path doesn't seem correct and library and header mismatch reported

This is a long but simple basic question. So anyone familiar could answer to my questions.
I have a simple program below on my CentOS 6.4 system. (have it unnder ~/test)
I wanted to test insmod and rmmod.
#include <linux/module.h>
static int __init hello_world( void )
{
printk( "hello world!\n" );
return 0;
}
static void __exit goodbye_world( void )
{
printk( "goodbye world!\n" );
}
module_init( hello_world );
module_exit( goodbye_world );
When I did
gcc -o hello_world hello_world.c
I got
hello_world.c:1:26: error: linux/module.h: No such file or directory
hello_world.c:3: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'hello_world'
hello_world.c:9: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'goodbye_world'
hello_world.c:14: warning: data definition has no type or storage class
hello_world.c:14: warning: parameter names (without types) in function declaration
hello_world.c:15: warning: data definition has no type or storage class
hello_world.c:15: warning: parameter names (without types) in function declaration
So I figured the include path is not setup correctly. I searched where this linux/module.h is located and found linux/module.h is under /usr/src/kernels/2.6.32-358.2.1.el6.x86_64/include/linux/module.h.
(When I give 'uname -a', I get
Linux stph45.etri.re.kr 2.6.32-358.2.1.el6.x86_64 #1 SMP Wed Mar 13 00:26:49 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
So this /usr/src/kernels/2.6.32-358.2.1.el6.x86_64/include is the right kernel header directory.)
Then I tried again like this
gcc -I/usr/src/kernels/2.6.32-358.2.1.el6.x86_64/include/ -o hello_world hello_world.c
and got
In file included from /usr/src/kernels/2.6.32-358.2.1.el6.x86_64/include/linux/list.h:7,
from /usr/src/kernels/2.6.32-358.2.1.el6.x86_64/include/linux/module.h:9,
from hello_world.c:1:
/usr/src/kernels/2.6.32-358.2.1.el6.x86_64/include/linux/prefetch.h:14:27: error: asm/processor.h: No such file or directory
/usr/src/kernels/2.6.32-358.2.1.el6.x86_64/include/linux/prefetch.h:15:23: error: asm/cache.h: No such file or directory
... more lines ...
I found this architecture dependent header file in /usr/src/kernels/2.6.32-358.2.1.el6.x86_64/arch/x86/include/asm/processor.h. So this time I did
gcc -I/usr/src/kernels/2.6.32-358.2.1.el6.x86_64/arch/x86/include -I/usr/src/kernels/2.6.32-358.2.1.el6.x86_64/include -o hello_world hello_world.c
providing the separate header path for the arch dependent files. Now I have these errors..
In file included from /usr/src/kernels/2.6.32-358.2.1.el6.x86_64/arch/x86/include/asm/percpu.h:45,
from /usr/src/kernels/2.6.32-358.2.1.el6.x86_64/arch/x86/include/asm/current.h:5,
from /usr/src/kernels/2.6.32-358.2.1.el6.x86_64/arch/x86/include/asm/processor.h:15,
from /usr/src/kernels/2.6.32-358.2.1.el6.x86_64/include/linux/prefetch.h:14,
from /usr/src/kernels/2.6.32-358.2.1.el6.x86_64/include/linux/list.h:7,
from /usr/src/kernels/2.6.32-358.2.1.el6.x86_64/include/linux/module.h:9,
from hello_world.c:1:
/usr/src/kernels/2.6.32-358.2.1.el6.x86_64/include/linux/kernel.h:949:2: warning: #warning Attempt to use kernel headers from user space, see http:
In file included from /usr/src/kernels/2.6.32-358.2.1.el6.x86_64/arch/x86/include/asm/processor.h:15,
from /usr/src/kernels/2.6.32-358.2.1.el6.x86_64/include/linux/prefetch.h:14,
from /usr/src/kernels/2.6.32-358.2.1.el6.x86_64/include/linux/list.h:7,
from /usr/src/kernels/2.6.32-358.2.1.el6.x86_64/include/linux/module.h:9,
from hello_world.c:1:
/usr/src/kernels/2.6.32-358.2.1.el6.x86_64/arch/x86/include/asm/current.h:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'struct'
.... more lines ....
I think this 'Attempt to user kernel headers' is ok in this case. and I have to find the cause of "error: expected '=', ',', ';', 'asm' or 'attribute' before 'struct'" error.
I think my gcc (I guess it came with the CentOS.) seems to have some problem. Can anybody tell me what's wrong with my gcc installation? Seeing below message, there are some mismatches and I don't know the procedures for the cures. (afraid to ruin the whole development tool chain which is dependent on gcc)
ckim#stph45:~/testprog] echo "" | gcc -o /tmp/tmp.o -v -x c -
Using built-in specs.
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-languages=c,c++,objc,obj-c++,java,fortran,ada --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.4.7 20120313 (Red Hat 4.4.7-4) (GCC)
COLLECT_GCC_OPTIONS='-o' '/tmp/tmp.o' '-v' '-mtune=generic'
/usr/libexec/gcc/x86_64-redhat-linux/4.4.7/cc1 -quiet -v - -quiet -dumpbase - -mtune=generic -auxbase - -version -o /tmp/ccWAQshz.s
ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.4.7/include-fixed"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../x86_64-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/include
/usr/include
End of search list.
GNU C (GCC) version 4.4.7 20120313 (Red Hat 4.4.7-4) (x86_64-redhat-linux)
compiled by GNU C version 4.4.7 20120313 (Red Hat 4.4.7-4), GMP version 4.3.1, MPFR version 2.4.1.
warning: GMP header version 4.3.1 differs from library version 4.3.2.
warning: MPFR header version 2.4.1 differs from library version 2.4.2.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 11481e4aa93ef024f1be70ed47ae45e3
COLLECT_GCC_OPTIONS='-o' '/tmp/tmp.o' '-v' '-mtune=generic'
as -V -Qy -o /tmp/ccTYQoBw.o /tmp/ccWAQshz.s
GNU assembler version 2.20.51.0.2 (x86_64-redhat-linux) using BFD version version 2.20.51.0.2-5.36.el6 20100205
COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/4.4.7/:/usr/libexec/gcc/x86_64-redhat-linux/4.4.7/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/4.4.7/:/usr/lib/gcc/x86_64-redhat-linux/:/usr/libexec/gcc/x86_64-redhat-linux/4.4.7/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/4.4.7/:/usr/lib/gcc/x86_64-redhat-linux/
LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/4.4.7/:/usr/lib/gcc/x86_64-redhat-linux/4.4.7/:/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-o' '/tmp/tmp.o' '-v' '-mtune=generic'
/usr/libexec/gcc/x86_64-redhat-linux/4.4.7/collect2 --eh-frame-hdr --build-id -m elf_x86_64 --hash-style=gnu -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o /tmp/tmp.o /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crt1.o /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/4.4.7/crtbegin.o -L/usr/lib/gcc/x86_64-redhat-linux/4.4.7 -L/usr/lib/gcc/x86_64-redhat-linux/4.4.7 -L/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../.. /tmp/ccTYQoBw.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-redhat-linux/4.4.7/crtend.o /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crtn.o
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
To compile a kernel module, you are supposed to write a Makefile to setup the kernel path and other environment variable.
You can use the below Makefile to build you kernel module
obj-m := hello_world.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
Copy the above contents to file name Makefile in the same directory as that of the source.
Just enter $ make command to build the module. The output would be hello_world.ko in the same directory.
Concerning the header/library mismatch
warning: GMP header version 4.3.1 differs from library version 4.3.2.
warning: MPFR header version 2.4.1 differs from library version 2.4.2.
it may not be a problem here. I suppose that GCC was compiled with GMP 4.3.1 and MPFR 2.4.1, but after that, the GMP and MPFR shared libraries were upgraded to ABI-compatible versions 4.3.2 and 2.4.2 respectively. If this is the case, this is allowed.

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.

Manually compile using gcc -v

Is it possible to compile a simple Hello World program that only uses provided gcc/glibc files rather than using the default ones provided by the OS ? (Therefore, when executed, the program will only use the provided files rather than the ones the OS provides.) I've looked everywhere on the net but cannot get any to work:
I tried to manually do what this does gcc -v simple.c but I cannot reproduce it myself.
This is what I tried: (all provided files are on the Desktop)
/home/myuser/Desktop/cc1 -quiet -v simple.c -quiet -dumpbase simple.c -mtune=generic -auxbase simple -version -o /tmp/temp1.s
How can the below paths be changed to custom ones rather than default ones ?
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include search starts here:
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/4.4.5/include
/usr/lib/gcc/x86_64-linux-gnu/4.4.5/include-fixed
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
GNU C (Debian 4.4.5-8) version 4.4.5 (x86_64-linux-gnu)
compiled by GNU C version 4.4.5, GMP version 4.3.2, MPFR version 3.0.0-p3.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: dac4d891d068d1bed01868869b00bd17
as -V -Qy -o /tmp/temp2.o /tmp/temp1.s
GNU assembler version 2.20.1 (x86_64-linux-gnu) using BFD version (GNU Binutils for Debian) 2.20.1-system.20100303
/home/myuser/Desktop/collect2 --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=both -dynamic-linker ld-2.11.2.so crt1.o crti.o crtbegin.o /tmp/temp2.o libgcc.a --as-needed libgcc_s.so.1 --no-as-needed libc.a libgcc_s.so.1 --as-needed libgcc.a --no-as-needed crtend.o crtn.o
Why is the below /usr/bin/ld used instead of the provided ld-2.11.2.so ?
/usr/bin/ld: dynamic STT_GNU_IFUNC symbol `strcmp' with pointer equality in `libc.a(strcmp.o)' can not be used when making an executable; recompile with -fPIE and relink with -pie
collect2: ld returned 1 exit status
Can anybody modify it to work ?
-v shows you the actions performed by the compiler driver. It does not affect what standard libraries you get.
To run with all custom libraries, use -nostdlib.
How can the below paths be changed to
custom ones rather than default ones ?
Simply add -I path to the compiler call. This path will be added before the internal paths.
Why is the below /usr/bin/ld used
instead of the provided ld-2.11.2.so ?
The first one is an executable binary, the second one is a shared object. You can't use a shared object in a place of a binary.

How do I properly reference the GNU readline library to scan terminal input?

I am attempting to compile C code that utilizes the following within GNU readline.
#include <readline/readline.h>;
#include <readline/history.h>;
I've tried changing the <> to "" and compiling both with and without the -lreadline options. Nothing seems to work. When compiling without -lreadline under gcc results in the following being generated while compiling (verbose):
Reading specs from /software/gcc-3.4.6-0/pkg/lib/gcc/i386-unknown-freebsd6.1/3.4.6/specs
Configured with: ../gcc-3.4.6/configure --prefix=/software/gcc-3.4.6-0/pkg --disable-dependency-tracking --localstatedir=/var --disable-nls --program-suffix=34 --enable-shared --enable-version-specific-runtime-libs
Thread model: posix
gcc version 3.4.6
/software/gcc-3.4.6-0/pkg/libexec/gcc/i386-unknown-freebsd6.1/3.4.6/cc1 -quiet -v myshell.c -quiet -dumpbase myshell.c -auxbase myshell -version -o /var/tmp//ccVSq3jQ.s
ignoring nonexistent directory "/software/gcc-3.4.6-0/pkg/lib/gcc/i386-unknown-freebsd6.1/3.4.6/../../../../i386-unknown-freebsd6.1/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/software/gcc-3.4.6-0/pkg/include
/software/gcc-3.4.6-0/pkg/lib/gcc/i386-unknown-freebsd6.1/3.4.6/include
/usr/include
End of search list.
GNU C version 3.4.6 (i386-unknown-freebsd6.1)
compiled by GNU C version 3.4.6.
GGC heuristics: --param ggc-min-expand=99 --param ggc-min-heapsize=129976
as -o /var/tmp//ccl1Jaqk.o /var/tmp//ccVSq3jQ.s
/software/gcc-3.4.6-0/pkg/libexec/gcc/i386-unknown-freebsd6.1/3.4.6/collect2 -V -dynamic-linker /libexec/ld-elf.so.1 -L/software/gcc-3.4.6-0/pkg/lib/gcc/i386-unknown-freebsd6.1 -o a /usr/lib/crt1.o /usr/lib/crti.o /software/gcc-3.4.6-0/pkg/lib/gcc/i386-unknown-freebsd6.1/3.4.6/crtbegin.o -L/software/gcc-3.4.6-0/pkg/lib/gcc/i386-unknown-freebsd6.1/3.4.6 -L/software/gcc-3.4.6-0/pkg/lib/gcc/i386-unknown-freebsd6.1/3.4.6/../../.. /var/tmp//ccl1Jaqk.o -lreadline -lgcc -lgcc_eh -lc -lgcc -lgcc_eh /software/gcc-3.4.6-0/pkg/lib/gcc/i386-unknown-freebsd6.1/3.4.6/crtend.o /usr/lib/crtn.o
/usr/bin/ld: cannot find -lreadline
GNU ld version 2.15 [FreeBSD] 2004-05-23
Supported emulations:
elf_i386_fbsd
collect2: ld returned 1 exit status
This is the output when compiling without the -lreadline option.
/var/tmp//ccNnucSC.o(.text+0x4f): In function `main':
: undefined reference to `readline'
collect2: ld returned 1 exit status
I have been unable to resolve this error up to this point. What am I missing in either my code or while invoking gcc?
While compiling under UNIX I found the following is necessary to properly reference the GNU readline library:
gcc code.c -L/usr/local/lib -I/usr/local/include -lreadline
This ensures that the compiler finds the readline directories and files during compilation and linking.
It sounds like you don't have the libreadline development libraries installed. On Debian (including the FreeBSD port) the library is located in /lib and the development libraries (that you would link to) are in /usr/lib.
Additionally you have semi-colons after your includes, which you shouldn't have.

Resources