Can't include standard C++ Library files using GCC-G++ - c++

I am having a problem including standard C++ library files when compiling with G++
Here is the code i have tried to compile:
#include <iostream>
int main()
{
return 0;
}
When compiling this i get an error:
test.cpp:1:20: fatal error: iostream: No such file or directory
#include <iostream>
And I can not figure out why...
Any hints would be appreciated, thanks.
Edit: This is the command i am using to compile
g++ -pedantic -Wall -Wextra -std=c++11 test.cpp -o test
Edit: This is the log whilst compiling with -v Any suggestions would be great... :)
C:\Users\Someone\Desktop>g++ test.cpp -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.8.1/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.8.1/configure --prefix=/mingw --host=mingw32 --build=m
ingw32 --without-pic --enable-shared --enable-static --with-gnu-ld --enable-lto
--enable-libssp --disable-multilib --enable-languages=c,c++,fortran,objc,obj-c++
,ada --disable-sjlj-exceptions --with-dwarf2 --disable-win32-registry --enable-l
ibstdcxx-debug --enable-version-specific-runtime-libs --with-gmp=/usr/src/pkg/gm
p-5.1.2-1-mingw32-src/bld --with-mpc=/usr/src/pkg/mpc-1.0.1-1-mingw32-src/bld --
with-mpfr= --with-system-zlib --with-gnu-as --enable-decimal-float=yes --enable-
libgomp --enable-threads --with-libiconv-prefix=/mingw32 --with-libintl-prefix=/
mingw
Thread model: win32
gcc version 4.8.1 (GCC)
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=generic' '-march=pentiumpro'
c:/mingw/bin/../libexec/gcc/mingw32/4.8.1/cc1plus.exe -quiet -v -iprefix c:\min
gw\bin\../lib/gcc/mingw32/4.8.1/ Test.cpp -quiet -dumpbase Test.cpp -mtune=gener
ic -march=pentiumpro -auxbase Test -version -o C:\Users\Gabriel\AppData\Local\Te
mp\ccJCPwY4.s
GNU C++ (GCC) version 4.8.1 (mingw32)
compiled by GNU C version 4.8.1, GMP version 5.1.2, MPFR version 3.1.2,
MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include/c+
+"
ignoring nonexistent directory "c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include/c+
+/mingw32"
ignoring nonexistent directory "c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include/c+
+/backward"
ignoring nonexistent directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/inc
lude/c++"
ignoring nonexistent directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/inc
lude/c++/mingw32"
ignoring nonexistent directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/inc
lude/c++/backward"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/inclu
de"
ignoring nonexistent directory "i:/p/giaw/mingw/include"
ignoring duplicate directory "/mingw/include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/inclu
de-fixed"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/../..
/../../mingw32/include"
ignoring duplicate directory "/mingw/include"
#include "..." search starts here:
#include <...> search starts here:
c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include
c:\mingw\bin\../lib/gcc/mingw32/4.8.1/../../../../include
c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include-fixed
c:\mingw\bin\../lib/gcc/mingw32/4.8.1/../../../../mingw32/include
End of search list.
GNU C++ (GCC) version 4.8.1 (mingw32)
compiled by GNU C version 4.8.1, GMP version 5.1.2, MPFR version 3.1.2,
MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: e3b01b00b6cf2cc1dc95350e55dafc7d
Test.cpp:1:20: fatal error: iostream: No such file or directory
#include <iostream>
^
compilation terminated.

I was able to resolve this issue by re installing MinGW

Related

g++ will not compile. fatal error: Files: No such file or directory windows

I am sure there is an answer out there for this but I cannot track it down.
code is simply
#include <iostream>
int main(){
std::cout << "hello world";
return 0;
}
Visual Studio runs the programs fine however when trying to compile from cmd
Directory of C:\Users\ebump\OneDrive\Documents\test
05/20/2022 12:53 AM <DIR> .
05/20/2022 12:53 AM <DIR> ..
05/08/2021 06:42 PM 9,891 asuka.jpg
05/19/2022 08:18 PM 37,583,331 asuka2.jpg
05/20/2022 01:10 AM 82 steg.cpp
02/01/2021 05:32 PM 38,903,396 wet_circuits.wav
05/19/2022 08:15 PM 37,573,440 wet_circuits.zip
5 File(s) 114,070,140 bytes
2 Dir(s) 440,502,870,016 bytes free
C:\Users\ebump\OneDrive\Documents\test>g++ steg.cpp
steg.cpp:6:1: fatal error: Files: No such file or directory
what exactly is going on?
tried to update using Msys2
below is the output of g++ -v stegg.cpp
Reading specs from c:/program files (x86)/codeblocks/bin/../lib/gcc/i686-w64-mingw32/4.8.3/specs
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=c:/program\ files\ (x86)/codeblocks/bin/../libexec/gcc/i686-w64-mingw32/4.8.3/lto-wrapper.exe
Target: i686-w64-mingw32
Configured with: ../gcc-4.8.3/configure --prefix=/opt/windows_32 --with-sysroot=/opt/windows_32 --libdir=/opt/windows_32/lib --mandir=/opt/windows_32/man --infodir=/opt/windows_32/info --enable-shared --disable-bootstrap --disable-multilib --with-arch=pentium3 --enable-threads=posix --enable-languages=c,c++ --enable-checking=release --enable-libgomp --with-system-zlib --with-python-dir=/lib/python2.7/site-packages --disable-libunwind-exceptions --enable-__cxa_atexit --enable-libssp --with-gnu-ld --verbose --enable-java-home --with-java-home=/opt/windows_32/lib/jvm/jre --with-jvm-root-dir=/opt/windows_32/lib/jvm --with-jvm-jar-dir=/opt/windows_32/lib/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=i686-w64-mingw32 --target=i686-w64-mingw32
Thread model: posix
gcc version 4.8.3 (GCC)
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=generic' '-march=pentium3'
c:/program files (x86)/codeblocks/bin/../libexec/gcc/i686-w64-mingw32/4.8.3/cc1plus.exe -quiet -v -iprefix c:\program files (x86)\codeblocks\bin\../lib/gcc/i686-w64-mingw32/4.8.3/ -D_REENTRANT steg.cpp -quiet -dumpbase steg.cpp -mtune=generic -march=pentium3 -auxbase steg -version -IC:/Program Files (x86)/Codeblocks/include -o C:\Users\ebump\AppData\Local\Temp\ccUYYiRX.s
GNU C++ (GCC) version 4.8.3 (i686-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 (x86)/codeblocks/lib/gcc/../../lib/gcc/i686-w64-mingw32/4.8.3/../../../../include/c++/4.8.3"
ignoring duplicate directory "c:/program files (x86)/codeblocks/lib/gcc/../../lib/gcc/i686-w64-mingw32/4.8.3/../../../../include/c++/4.8.3/i686-w64-mingw32"
ignoring duplicate directory "c:/program files (x86)/codeblocks/lib/gcc/../../lib/gcc/i686-w64-mingw32/4.8.3/../../../../include/c++/4.8.3/backward"
ignoring duplicate directory "c:/program files (x86)/codeblocks/lib/gcc/../../lib/gcc/i686-w64-mingw32/4.8.3/include"
ignoring nonexistent directory "/opt/windows_32/opt/windows_32/lib/gcc/i686-w64-mingw32/4.8.3/../../../../include"
ignoring duplicate directory "c:/program files (x86)/codeblocks/lib/gcc/../../lib/gcc/i686-w64-mingw32/4.8.3/include-fixed"
ignoring duplicate directory "c:/program files (x86)/codeblocks/lib/gcc/../../lib/gcc/i686-w64-mingw32/4.8.3/../../../../i686-w64-mingw32/include"
ignoring nonexistent directory "/opt/windows_32/mingw/include"
ignoring nonexistent directory "C:/Program"
#include "..." search starts here:
#include <...> search starts here:
c:\program files (x86)\codeblocks\bin\../lib/gcc/i686-w64-mingw32/4.8.3/../../../../include/c++/4.8.3
c:\program files (x86)\codeblocks\bin\../lib/gcc/i686-w64-mingw32/4.8.3/../../../../include/c++/4.8.3/i686-w64-mingw32
c:\program files (x86)\codeblocks\bin\../lib/gcc/i686-w64-mingw32/4.8.3/../../../../include/c++/4.8.3/backward
c:\program files (x86)\codeblocks\bin\../lib/gcc/i686-w64-mingw32/4.8.3/include
c:\program files (x86)\codeblocks\bin\../lib/gcc/i686-w64-mingw32/4.8.3/include-fixed
c:\program files (x86)\codeblocks\bin\../lib/gcc/i686-w64-mingw32/4.8.3/../../../../i686-w64-mingw32/include
End of search list.
GNU C++ (GCC) version 4.8.3 (i686-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
Compiler executable checksum: c4fe4d0d4d1dfaca074c710f8d712c81
steg.cpp:6:1: fatal error: Files: No such file or directory
}
^
compilation terminated.
Solved... issue was related to incorrect PATH variables
The problem was that C:\Program Files (x86)\Codeblocks\bin existed above C:\msys64\usr\bin in the system variables, so despite having updated g++ the system continued to look at the ancient version of g++ before the up to date version.
If your program is working with Visual Studio IDE, you can compile it using VS Developer command prompt.
Please click the Start Menu, select "Developer Command Prompt for VS 2022" it will open a terminal window, then navigate to the directory where your source code is located and run the following command
cl /EHsc test.cpp # to compile the pogram
test.exe # to run the program
Visual Studio Command Prompt
Compile using cl compiler

nvptx gcc (9.0.0/trunk) for openmp 4.5 off-loading to (gpu) device cannot find libgomp.spec

I've been trying to install the OpenMP 4.5 off-loading to Nvidia GPU version of gcc for a while and so far no success, although I'm getting closer.
This time, I followed this script, where I have made two changes: First I specified the trunk version of gcc instead of 7.2, secondly nvptx-newlib is now included in nvptx-tools according to the github repository, so I removed that part of the script. For easy reference, the original script is
#!/bin/sh
#
# Build GCC with support for offloading to NVIDIA GPUs.
#
work_dir=$HOME/offload/wrk
install_dir=$HOME/offload/install
# Location of the installed CUDA toolkit
cuda=/usr/local/cuda
# Build assembler and linking tools
mkdir -p $work_dir
cd $work_dir
git clone https://github.com/MentorEmbedded/nvptx-tools
cd nvptx-tools
./configure \
--with-cuda-driver-include=$cuda/include \
--with-cuda-driver-lib=$cuda/lib64 \
--prefix=$install_dir
make
make install
cd ..
# Set up the GCC source tree
git clone https://github.com/MentorEmbedded/nvptx-newlib
svn co svn://gcc.gnu.org/svn/gcc/tags/gcc_7_2_0_release gcc
cd gcc
contrib/download_prerequisites
ln -s ../nvptx-newlib/newlib newlib
cd ..
target=$(gcc/config.guess)
# Build nvptx GCC
mkdir build-nvptx-gcc
cd build-nvptx-gcc
../gcc/configure \
--target=nvptx-none --with-build-time-tools=$install_dir/nvptx-none/bin \
--enable-as-accelerator-for=$target \
--disable-sjlj-exceptions \
--enable-newlib-io-long-long \
--enable-languages="c,c++,fortran,lto" \
--prefix=$install_dir
make -j4
make install
cd ..
# Build host GCC
mkdir build-host-gcc
cd build-host-gcc
../gcc/configure \
--enable-offload-targets=nvptx-none \
--with-cuda-driver-include=$cuda/include \
--with-cuda-driver-lib=$cuda/lib64 \
--disable-bootstrap \
--disable-multilib \
--enable-languages="c,c++,fortran,lto" \
--prefix=$install_dir
make -j4
make install
cd ..
After quite a while, this successfully exits. Per the instructions on that webpage, I added $install_dir/lib64 to my LD_LIBRARY_PATH and additionally to LIBRARY_PATH.
Then as a test, I have the following basic test program
#include <omp.h>
#include <cmath>
#include <iostream>
int main()
{
double data_array[1000000];
#pragma omp target teams distribute
for (int idx = 0; idx < 1000000; ++idx)
{
data_array[idx] = idx;
}
std::cout << "Hopefully this ran on the gpu...\n";
}
Then I try to compile this using offload/install/bin/g++ -fopenmp -foffload=nvptx-none main.cpp then it returns with the following error message:
x86_64-pc-linux-gnu-accel-nvptx-none-gcc: error: libgomp.spec: No such file or directory
mkoffload: fatal error: offload/install/bin/x86_64-pc-linux-gnu-accel-nvptx-none-gcc returned 1 exit status
compilation terminated.
lto-wrapper: fatal error: /home/over_ng/offload/install/libexec/gcc/x86_64-pc-linux-gnu/9.0.0//accel/nvptx-none/mkoffload returned 1 exit status
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
The file libgomp.spec can be found in the aforementioned $install_dir/lib64, which on my system is offload/install/lib64/.
Some more information about my system:
Ubuntu 16.04, accessed through slurm
Cuda 9.0.176
4x Nvidia Tesla V100
offload/install/bin/g++ -v reports:
Using built-in specs.
COLLECT_GCC=offload/install/bin/g++
COLLECT_LTO_WRAPPER=/home/over_ng/offload/install/libexec/gcc/x86_64-pc-linux-gnu/9.0.0/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure --enable-offload-targets=nvptx-none --with-cuda-driver-include=/tools/spack/install/linux-ubuntu16.04-x86_64/gcc-5.4.0/cuda-9.0.176-m4ivnigh5kuty6u7tcnroxr5on5lot6s/include --with-cuda-driver-lib=/tools/spack/install/linux-ubuntu16.04-x86_64/gcc-5.4.0/cuda-9.0.176-m4ivnigh5kuty6u7tcnroxr5on5lot6s/lib64 --disable-bootstrap --disable-multilib --enable-languages=c,c++,fortran,lto --prefix=/home/over_ng/offload/install
Thread model: posix
gcc version 9.0.0 20180627 (experimental) (GCC)
offload/install/bin/g++ -print-search-dirs reports
install: /home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/9.0.0/
programs: =/home/over_ng/offload/install/libexec/gcc/x86_64-pc-linux-gnu/9.0.0/:/home/over_ng/offload/install/libexec/gcc/x86_64-pc-linux-gnu/9.0.0/:/home/over_ng/offload/install/libexec/gcc/x86_64-pc-linux-gnu/:/home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/9.0.0/:/home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/:/home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/9.0.0/../../../../x86_64-pc-linux-gnu/bin/x86_64-pc-linux-gnu/9.0.0/:/home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/9.0.0/../../../../x86_64-pc-linux-gnu/bin/x86_64-linux-gnu/:/home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/9.0.0/../../../../x86_64-pc-linux-gnu/bin/
libraries: =/tools/spack/install/linux-ubuntu16.04-x86_64/gcc-5.4.0/cuda-9.0.176-m4ivnigh5kuty6u7tcnroxr5on5lot6s/lib64/x86_64-pc-linux-gnu/9.0.0/:/tools/spack/install/linux-ubuntu16.04-x86_64/gcc-5.4.0/cuda-9.0.176-m4ivnigh5kuty6u7tcnroxr5on5lot6s/lib64/x86_64-linux-gnu/:/tools/spack/install/linux-ubuntu16.04-x86_64/gcc-5.4.0/cuda-9.0.176-m4ivnigh5kuty6u7tcnroxr5on5lot6s/lib64/../lib64/:/tools/spack/install/linux-ubuntu16.04-x86_64/gcc-5.4.0/subversion-1.9.7-f5fbcx4xhwzrq5rhhco7byj7cbx2f4fs/lib/x86_64-pc-linux-gnu/9.0.0/:/tools/spack/install/linux-ubuntu16.04-x86_64/gcc-5.4.0/subversion-1.9.7-f5fbcx4xhwzrq5rhhco7byj7cbx2f4fs/lib/x86_64-linux-gnu/:/tools/spack/install/linux-ubuntu16.04-x86_64/gcc-5.4.0/subversion-1.9.7-f5fbcx4xhwzrq5rhhco7byj7cbx2f4fs/lib/../lib64/:/home/over_ng/offload/install/lib64/x86_64-pc-linux-gnu/9.0.0/:/home/over_ng/offload/install/lib64/x86_64-linux-gnu/:/home/over_ng/offload/install/lib64/../lib64/:/home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/9.0.0/:/home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/9.0.0/../../../../x86_64-pc-linux-gnu/lib/x86_64-pc-linux-gnu/9.0.0/:/home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/9.0.0/../../../../x86_64-pc-linux-gnu/lib/x86_64-linux-gnu/:/home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/9.0.0/../../../../x86_64-pc-linux-gnu/lib/../lib64/:/home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/9.0.0/../../../x86_64-pc-linux-gnu/9.0.0/:/home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/9.0.0/../../../x86_64-linux-gnu/:/home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/9.0.0/../../../../lib64/:/lib/x86_64-pc-linux-gnu/9.0.0/:/lib/x86_64-linux-gnu/:/lib/../lib64/:/usr/lib/x86_64-pc-linux-gnu/9.0.0/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib64/:/tools/spack/install/linux-ubuntu16.04-x86_64/gcc-5.4.0/cuda-9.0.176-m4ivnigh5kuty6u7tcnroxr5on5lot6s/lib64/:/tools/spack/install/linux-ubuntu16.04-x86_64/gcc-5.4.0/subversion-1.9.7-f5fbcx4xhwzrq5rhhco7byj7cbx2f4fs/lib/:/home/over_ng/offload/install/lib64/:/home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/9.0.0/../../../../x86_64-pc-linux-gnu/lib/:/home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/9.0.0/../../../:/lib/:/usr/lib/
And finally, offload/install/bin/g++ -fopenmp -foffload=nvptx-none -v main.cpp reports
Using built-in specs.
COLLECT_GCC=offload/install/bin/g++
COLLECT_LTO_WRAPPER=/home/over_ng/offload/install/libexec/gcc/x86_64-pc-linux-gnu/9.0.0/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure --enable-offload-targets=nvptx-none --with-cuda-driver-include=/tools/spack/install/linux-ubuntu16.04-x86_64/gcc-5.4.0/cuda-9.0.176-m4ivnigh5kuty6u7tcnroxr5on5lot6s/include --with-cuda-driver-lib=/tools/spack/install/linux-ubuntu16.04-x86_64/gcc-5.4.0/cuda-9.0.176-m4ivnigh5kuty6u7tcnroxr5on5lot6s/lib64 --disable-bootstrap --disable-multilib --enable-languages=c,c++,fortran,lto --prefix=/home/over_ng/offload/install
Thread model: posix
gcc version 9.0.0 20180627 (experimental) (GCC)
COLLECT_GCC_OPTIONS='-fopenmp' '-foffload=nvptx-none' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-pthread'
/home/over_ng/offload/install/libexec/gcc/x86_64-pc-linux-gnu/9.0.0/cc1plus -quiet -v -imultiarch x86_64-linux-gnu -D_GNU_SOURCE -D_REENTRANT main.cpp -quiet -dumpbase main.cpp -mtune=generic -march=x86-64 -auxbase main -version -fopenmp -foffload=nvptx-none -o /tmp/cc9FAd0p.s
GNU C++14 (GCC) version 9.0.0 20180627 (experimental) (x86_64-pc-linux-gnu)
compiled by GNU C version 8.1.0, GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.3, isl version isl-0.18-GMP
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/9.0.0/../../../../x86_64-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/tools/spack/install/linux-ubuntu16.04-x86_64/gcc-5.4.0/cuda-9.0.176-m4ivnigh5kuty6u7tcnroxr5on5lot6s/include
/tools/spack/install/linux-ubuntu16.04-x86_64/gcc-5.4.0/subversion-1.9.7-f5fbcx4xhwzrq5rhhco7byj7cbx2f4fs/include
/home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/9.0.0/../../../../include/c++/9.0.0
/home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/9.0.0/../../../../include/c++/9.0.0/x86_64-pc-linux-gnu
/home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/9.0.0/../../../../include/c++/9.0.0/backward
/home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/9.0.0/include
/usr/local/include
/home/over_ng/offload/install/include
/home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/9.0.0/include-fixed
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
GNU C++14 (GCC) version 9.0.0 20180627 (experimental) (x86_64-pc-linux-gnu)
compiled by GNU C version 8.1.0, GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.3, isl version isl-0.18-GMP
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Compiler executable checksum: 716ed3567afb9cd0b736d2b474553211
COLLECT_GCC_OPTIONS='-fopenmp' '-foffload=nvptx-none' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-pthread'
as -v --64 -o /tmp/cc2TYtU2.o /tmp/cc9FAd0p.s
GNU assembler version 2.26.1 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.26.1
COMPILER_PATH=/home/over_ng/offload/install/libexec/gcc/x86_64-pc-linux-gnu/9.0.0/:/home/over_ng/offload/install/libexec/gcc/x86_64-pc-linux-gnu/9.0.0/:/home/over_ng/offload/install/libexec/gcc/x86_64-pc-linux-gnu/:/home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/9.0.0/:/home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/
LIBRARY_PATH=/tools/spack/install/linux-ubuntu16.04-x86_64/gcc-5.4.0/cuda-9.0.176-m4ivnigh5kuty6u7tcnroxr5on5lot6s/lib64/../lib64/:/home/over_ng/offload/install/lib64/../lib64/:/home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/9.0.0/:/home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/9.0.0/../../../../lib64/:/lib/x86_64-linux-gnu/:/lib/../lib64/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib64/:/tools/spack/install/linux-ubuntu16.04-x86_64/gcc-5.4.0/cuda-9.0.176-m4ivnigh5kuty6u7tcnroxr5on5lot6s/lib64/:/tools/spack/install/linux-ubuntu16.04-x86_64/gcc-5.4.0/subversion-1.9.7-f5fbcx4xhwzrq5rhhco7byj7cbx2f4fs/lib/:/home/over_ng/offload/install/lib64/:/home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/9.0.0/../../../:/lib/:/usr/lib/
Reading specs from /home/over_ng/offload/install/lib64/../lib64/libgomp.spec
COLLECT_GCC_OPTIONS='-fopenmp' '-foffload=nvptx-none' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-pthread'
/home/over_ng/offload/install/libexec/gcc/x86_64-pc-linux-gnu/9.0.0/collect2 -plugin /home/over_ng/offload/install/libexec/gcc/x86_64-pc-linux-gnu/9.0.0/liblto_plugin.so -plugin-opt=/home/over_ng/offload/install/libexec/gcc/x86_64-pc-linux-gnu/9.0.0/lto-wrapper -plugin-opt=-fresolution=/tmp/ccnGrpRF.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lpthread -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/x86_64-linux-gnu/crt1.o /usr/lib/x86_64-linux-gnu/crti.o /home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/9.0.0/crtbegin.o /home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/9.0.0/crtoffloadbegin.o -L/tools/spack/install/linux-ubuntu16.04-x86_64/gcc-5.4.0/cuda-9.0.176-m4ivnigh5kuty6u7tcnroxr5on5lot6s/lib64/../lib64 -L/home/over_ng/offload/install/lib64/../lib64 -L/home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/9.0.0 -L/home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/9.0.0/../../../../lib64 -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib64 -L/tools/spack/install/linux-ubuntu16.04-x86_64/gcc-5.4.0/cuda-9.0.176-m4ivnigh5kuty6u7tcnroxr5on5lot6s/lib64 -L/tools/spack/install/linux-ubuntu16.04-x86_64/gcc-5.4.0/subversion-1.9.7-f5fbcx4xhwzrq5rhhco7byj7cbx2f4fs/lib -L/home/over_ng/offload/install/lib64 -L/home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/9.0.0/../../.. /tmp/cc2TYtU2.o -lstdc++ -lm -lgomp -lgcc_s -lgcc -lpthread -lc -lgcc_s -lgcc /home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/9.0.0/crtend.o /usr/lib/x86_64-linux-gnu/crtn.o /home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/9.0.0/crtoffloadend.o
/home/over_ng/offload/install/libexec/gcc/x86_64-pc-linux-gnu/9.0.0/lto-wrapper -fresolution=/tmp/ccnGrpRF.res -flinker-output=exec -foffload-objects=/tmp/ccQDi0zV.ofldlist
/home/over_ng/offload/install/libexec/gcc/x86_64-pc-linux-gnu/9.0.0//accel/nvptx-none/mkoffload #/tmp/ccJAbpMz
offload/install/bin/x86_64-pc-linux-gnu-accel-nvptx-none-gcc #/tmp/ccoh8KPc
Using built-in specs.
COLLECT_GCC=offload/install/bin/x86_64-pc-linux-gnu-accel-nvptx-none-gcc
COLLECT_LTO_WRAPPER=/home/over_ng/offload/install/libexec/gcc/x86_64-pc-linux-gnu/9.0.0/accel/nvptx-none/lto-wrapper
Target: nvptx-none
Configured with: ../gcc/configure --target=nvptx-none --with-build-time-tools=/home/over_ng/offload/install/nvptx-none/bin --enable-as-accelerator-for=x86_64-pc-linux-gnu --disable-sjlj-exceptions --enable-newlib-io-long-long --enable-languages=c,c++,fortran,lto --prefix=/home/over_ng/offload/install
Thread model: single
gcc version 9.0.0 20180627 (experimental) (GCC)
COLLECT_GCC_OPTIONS='-v' '-m64' '-mgomp' '-v' '-fno-openacc' '-foffload-abi=lp64' '-fopenmp' '-o' '/tmp/ccNVxXFz.mkoffload'
/home/over_ng/offload/install/libexec/gcc/x86_64-pc-linux-gnu/9.0.0/accel/nvptx-none/lto1 -quiet -dumpbase cc2TYtU2.o -m64 -mgomp -auxbase cc2TYtU2 -version -fno-openacc -foffload-abi=lp64 -fopenmp #/tmp/cchKIS8V -o /tmp/ccZLBhjz.s
GNU GIMPLE (GCC) version 9.0.0 20180627 (experimental) (nvptx-none)
compiled by GNU C version 8.1.0, GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.3, isl version isl-0.18-GMP
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
GNU GIMPLE (GCC) version 9.0.0 20180627 (experimental) (nvptx-none)
compiled by GNU C version 8.1.0, GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.3, isl version isl-0.18-GMP
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
COLLECT_GCC_OPTIONS='-v' '-m64' '-mgomp' '-v' '-fno-openacc' '-foffload-abi=lp64' '-fopenmp' '-o' '/tmp/ccNVxXFz.mkoffload'
/home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/9.0.0/accel/nvptx-none/../../../../../../nvptx-none/bin/as -o /tmp/ccRJFdvc.o /tmp/ccZLBhjz.s
COMPILER_PATH=/home/over_ng/offload/install/libexec/gcc/x86_64-pc-linux-gnu/9.0.0/accel/nvptx-none/:/home/over_ng/offload/install/libexec/gcc/x86_64-pc-linux-gnu/9.0.0/accel/nvptx-none/:/home/over_ng/offload/install/libexec/gcc/nvptx-none/:/home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/9.0.0/accel/nvptx-none/:/home/over_ng/offload/install/lib/gcc/nvptx-none/:/home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/9.0.0/accel/nvptx-none/../../../../../../nvptx-none/bin/
LIBRARY_PATH=/home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/9.0.0/accel/nvptx-none/mgomp/:/home/over_ng/offload/install/lib/gcc/x86_64-pc-linux-gnu/9.0.0/accel/nvptx-none/
Reading specs from libgomp.spec
x86_64-pc-linux-gnu-accel-nvptx-none-gcc: error: libgomp.spec: No such file or directory
mkoffload: fatal error: offload/install/bin/x86_64-pc-linux-gnu-accel-nvptx-none-gcc returned 1 exit status
compilation terminated.
lto-wrapper: fatal error: /home/over_ng/offload/install/libexec/gcc/x86_64-pc-linux-gnu/9.0.0//accel/nvptx-none/mkoffload returned 1 exit status
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
On the same webpage as where I found the script, somebody else reported the same problem and reverting to gcc 7.2 is apparently a solution. Since I want to include the off-loading compiler in the Spack collection, I would like to be able to use any supported version. Although I can live with gcc 8 for the time being, as 9/trunk is still experimental.
This may imply that it is a bug in gcc, in that case I would like to report it to them!
Edit 1: As requested, a 'sane' CPU only program that seems to work fine:
#include <omp.h>
#include <cmath>
#include <vector>
#include <iostream>
int main()
{
const int size = 1000;
std::vector<double> sinTable(size);
#pragma omp parallel for
for(int n=0; n<size; ++n)
{
sinTable[n] = std::sin(2 * M_PI * n / size);
std::cout << sinTable[n] << '\n';
}
// the table is now initialized
}
This was compiled with offload/install/bin/g++ -fopenmp -v main_cpu.cpp -o cpu
I have been using the package gcc-offload-nvptx in the Ubuntu repository since Ubuntu 17.10. If I compile your test code like this
g++ test.cpp -fopenmp
I get a lto-wrapper failed error. This can be fixed using -fno-stack-protector like this
g++ test.cpp -fopenmp -fno-stack-protector
Then test code compiles and runs. You can see that it runs on the GPU using nvprof like this
sudo nvprof ./a.out
Some additional comments. In your test code I would use
#pragma omp target teams distribute parallel for
See OpenMP offloading to Nvidia wrong reduction
Also in your test code you should do something with data_array or the compiler might optimize your code away.
Ubuntu 18.04 also requires -fno-stack-protector.

G++ sees float as illegal instruction

In my file "six.cpp", I try to print a float, but the compiler keeps throwing an error. Here is the file "six.cpp":
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
double f = 5.3;
cout << f << endl;
return 0;
}
Then when I try to compile using g++ six.cpp I get the following output using the -v tag.
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-cygwin/4.9.3/lto-wrapper.exe
Target: x86_64-pc-cygwin
Configured with: /cygdrive/i/szsz/tmpp/gcc/gcc-4.9.3-1.x86_64/src/gcc-4.9.3/configure --srcdir=/cygdrive/i/szsz/tmpp/gcc/gcc-4.9.3-1.x86_64/src/gcc-4.9.3 --prefix=/usr --exec-prefix=/usr --localstatedir=/var --sysconfdir=/etc --docdir=/usr/share/doc/gcc --htmldir=/usr/share/doc/gcc/html -C --build=x86_64-pc-cygwin --host=x86_64-pc-cygwin --target=x86_64-pc-cygwin --without-libiconv-prefix --without-libintl-prefix --libexecdir=/usr/lib --enable-shared --enable-shared-libgcc --enable-static --enable-version-specific-runtime-libs --enable-bootstrap --enable-__cxa_atexit --with-dwarf2 --with-tune=generic --enable-languages=ada,c,c++,fortran,lto,objc,obj-c++ --enable-graphite --enable-threads=posix --enable-libatomic --enable-libgomp --disable-libitm --enable-libquadmath --enable-libquadmath-support --enable-libssp --enable-libada --enable-libgcj-sublibs --disable-java-awt --disable-symvers --with-ecj-jar=/usr/share/java/ecj.jar --with-gnu-ld --with-gnu-as --with-cloog-include=/usr/include/cloog-isl --without-libiconv-prefix --without-libintl-prefix --with-system-zlib --enable-linker-build-id
Thread model: posix
gcc version 4.9.3 (GCC)
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-pc-cygwin/4.9.3/cc1plus.exe -quiet -v -Dunix -idirafter /usr/lib/gcc/x86_64-pc-cygwin/4.9.3/../../../../lib/../include/w32api -idirafter /usr/lib/gcc/x86_64-pc-cygwin/4.9.3/../../../../x86_64-pc-cygwin/lib/../lib/../../include/w32api six.cpp -quiet -dumpbase six.cpp -mtune=generic -march=x86-64 -auxbase six -version -o /tmp/ccfHbtlL.s
GNU C++ (GCC) version 4.9.3 (x86_64-pc-cygwin)
compiled by GNU C version 4.9.3, GMP version 6.0.0, MPFR version 3.1.2-p11, MPC version 1.0.3
warning: GMP header version 6.0.0 differs from library version 6.1.0.
warning: MPFR header version 3.1.2-p11 differs from library version 3.1.3.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-pc-cygwin/4.9.3/../../../../x86_64-pc-cygwin/include"
ignoring duplicate directory "/usr/lib/gcc/x86_64-pc-cygwin/4.9.3/../../../../x86_64-pc-cygwin/lib/../lib/../../include/w32api"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/x86_64-pc-cygwin/4.9.3/include/c++
/usr/lib/gcc/x86_64-pc-cygwin/4.9.3/include/c++/x86_64-pc-cygwin
/usr/lib/gcc/x86_64-pc-cygwin/4.9.3/include/c++/backward
/usr/lib/gcc/x86_64-pc-cygwin/4.9.3/include
/usr/lib/gcc/x86_64-pc-cygwin/4.9.3/include-fixed
/usr/include
/usr/lib/gcc/x86_64-pc-cygwin/4.9.3/../../../../lib/../include/w32api
End of search list.
GNU C++ (GCC) version 4.9.3 (x86_64-pc-cygwin)
compiled by GNU C version 4.9.3, GMP version 6.0.0, MPFR version 3.1.2-p11, MPC version 1.0.3
warning: GMP header version 6.0.0 differs from library version 6.1.0.
warning: MPFR header version 3.1.2-p11 differs from library version 3.1.3.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: a7b6fac296390f5db29d753ab65194e7
six.cpp:6:3: internal compiler error: Illegal instruction
double f = 5.3;
^
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
I just started programming in C++, and I'm very confused to as to why this is happening. I've also done a few google searches and have not found anything about this.
You've got an internal compiler error: Illegal instruction, which means the gcc compiler itself has failed. From the warnings it looks like you've mis-installed the gcc tool chain. Try removing it and reinstalling or upgrading.
The portion of source code where it failed is not especially interesting here, the important bit is "internal compiler error: Illegal instruction".
This means that your copy of g++ is built for a newer subarchitecture than the CPU you are running it on. For example, SSE4 instructions were introduced in 2006 and older CPU designs don't support them. Because SSE is used for floating-point calculations, it makes sense that finding a floating-point literal triggered the error, but the root cause is the instruction set mismatch.
If you check /proc/cpuinfo, you can find out what instruction set extensions are supported on your CPU, which will help you pick the right g++ build options (whether you build yourself or download a package built with those options).
Relevant options are the ones listed here, particularly -march=, -mfpmath=, and -m(no)fused-madd.

fatal error: Eigen/Dense: No such file or directory

I have installed libeigen3-dev in order to compile programs using Eigen 3. when I include a file, such as Eigen/Dense I get this error when I try to run g++:
user#office-debian:~/Documents/prog$ g++ src/main.cpp -MMD -std=c++11
In file included from src/main.cpp:9:0:
src/tdefs.h:16:23: fatal error: Eigen/Dense: No such file or directory
compilation terminated.
Running the following line works fine:
g++ -I /usr/include/eigen3/ src/main.cpp -MMD -std=c++11
shouldn't that include directory be automatically found by GCC because I installed the Eigen package through aptitude? Why are boost and OpenGL found automatically when I install the libraries but not Eigen? (Note that eigen is a header-only library, but that shouldn't matter right?)
Running g++ src/main.cpp -MMD -std=c++11 --verbose produces the following output:
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.7/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.7.2-5' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --with-arch-32=i586 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.7.2 (Debian 4.7.2-5)
COLLECT_GCC_OPTIONS='-MMD' '-std=c++11' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-linux-gnu/4.7/cc1plus -quiet -v -imultiarch x86_64-linux-gnu -MMD main.d -D_GNU_SOURCE src/main.cpp -quiet -dumpbase main.cpp -mtune=generic -march=x86-64 -auxbase main -std=c++11 -version -o /tmp/ccoYRPKY.s
GNU C++ (Debian 4.7.2-5) version 4.7.2 (x86_64-linux-gnu)
compiled by GNU C version 4.7.2, GMP version 5.0.5, MPFR version 3.1.0-p10, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/4.7
/usr/include/c++/4.7/x86_64-linux-gnu
/usr/include/c++/4.7/backward
/usr/lib/gcc/x86_64-linux-gnu/4.7/include
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/4.7/include-fixed
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
GNU C++ (Debian 4.7.2-5) version 4.7.2 (x86_64-linux-gnu)
compiled by GNU C version 4.7.2, GMP version 5.0.5, MPFR version 3.1.0-p10, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 66d178dd81da8c975e003e06d9f5e782
In file included from src/main.cpp:9:0:
src/tdefs.h:16:23: fatal error: Eigen/Dense: No such file or directory
compilation terminated.
I had this same problem on my Ubuntu 14 box. Ended up creating symlinks to get around it. With eigen3 installed in /usr/local/include do the following:
cd /usr/local/include
sudo ln -sf eigen3/Eigen Eigen
sudo ln -sf eigen3/unsupported unsupported
You should now be able to include the headers by:
#include <Eigen/Dense>
#include <unsupported/Eigen/FFT>
Change
#include <Eigen/Dense>
to
#include <eigen3/Eigen/Dense>
Run your compiler with the --verbose switch:
g++ --verbose ...
If your includes are relative to one of the paths shown in this output, you don't have to use -I. It depends how gcc has been configured, and it depends where that other stuff is installed.
Note that . is typically not in the -I paths.
Later
After exchanging a couple of comments it is clear that /usr/include/eigen3/Eigen/Dense should be include-able by #include <Eigen/Dense>, but not by #include <eigen3/Eigen/Dense>. Therefore, the addition of the command line option -I /usr/include/eigen3 is mandatory.
Whether some installation selects to install header files into a directory that in one of the ones compiled into gcc, depends on the default, a decision made by the distributor, or a decision made during installation. I'd say that "frequently used" header files (Boost) are well placed into /usr/local/include while some "elitist" stuff would be better off in a directory of its own.
Should use the following:
#if defined __GNUC__ || defined __APPLE__
#include <Eigen/Dense>
#else
#include <eigen3/Eigen/Dense>
#endif
This worked for me (using Macports for installing Shogun on Mac OS 10.11):
cd ${macports_prefix}/include
sudo ln -sf eigen3/Eigen Eigen
sudo ln -sf eigen3/unsupported unsupported
If you are working on a Linux server, and you have to install Eigen to a local directory, you can try to solve the problem by following the steps:
Download, install, and extract Eigen source code from the official website.
Copy the Eigen folder to a directory where your local lib is. In my case, I downloaded, unzipped and install eigen-3.4.0, and then I copied the entire folder Eigen in /eigen-3.4.0/Eigen/ to my local include /anywhere/include/Eigen.
Add this path when you run g++ -g yourcode.cpp -I /anywhere/include -L /anywhere/lib'
I'm using Ubuntu 22.04, with Eigen installed by
sudo apt install libeigen3-dev
according to the above method (the answer from scottlittle), I link the Eigen to /usr/include by
cd ~/usr/include
sudo ln -sf eigen3/Eigen Eigen
sudo ln -sf eigen3/unsupported unsupported
After this step, I can use
#include <Eigen/Dense>
instead of
#include <eigen3/Eigen/Dense>
If you follow the getting started instructions at the main Eigen site then you can't go far wrong.
To surmise, download then extract the Eigen source code into a directory of choice. Next copy the "Eigen" directory into /usr/local/include/. NOTE this is the directory named "Eigen" WITHIN the directory structure extracted, NOT the entire directory structure itself. It worked for me on an Ubuntu 14.04 virtual machine.

MinGW compiled programs crash on 64 bit Windows

I have 32bit MinGW and 64 bit Eclipse CDT installed on 64 bit Windows 7 with an Intel Core i7-3612QM. When I compile and run hello world, the string prints, but the program gets a SIGILL afterward.
Source:
#include <iostream>
using namespace std;
int main() {
cout << "Hello World!" << endl;
return 0;
}
Stacktrace:
hello.exe [C/C++ Application]
hello.exe [5532]
Thread [1] 0 (Suspended : Signal : SIGILL:Illegal instruction)
libstdc++-6!_ZSt4cout() at 0x6fccc3c0
libstdc++-6!_ZNSolsEPFRSoS_E() at 0x6fc8908c
_fu0___ZSt4cout() at hello.cpp:5 0x4013be
gdb
Adding cin causes a segfault:
Source:
#include <iostream>
#include <string>
using namespace std;
int main() {
string name;
cout << "Please type your name: ";
cin >> name;
cout << "Hello " << name << endl;
return 0;
}
Verbose compiler output:
C:\Users\Sean\temp>g++ -v main.cpp
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.6.2/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.6.2/configure --enable-languages=c,c++,ada,fortran,obj
c,obj-c++ --disable-sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgo
mp --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-r
untime-libs --build=mingw32 --prefix=/mingw
Thread model: win32
gcc version 4.6.2 (GCC)
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=i386' '-march=i386'
c:/mingw/bin/../libexec/gcc/mingw32/4.6.2/cc1plus.exe -quiet -v -iprefix c:\min
gw\bin\../lib/gcc/mingw32/4.6.2/ main.cpp -quiet -dumpbase main.cpp -mtune=i386
-march=i386 -auxbase main -version -o C:\Users\Sean\AppData\Local\Temp\ccSVBzeY.
s
GNU C++ (GCC) version 4.6.2 (mingw32)
compiled by GNU C version 4.6.2, GMP version 5.0.1, MPFR version 2.4.1,
MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../.
./mingw32/include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.2/inclu
de/c++"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.2/inclu
de/c++/mingw32"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.2/inclu
de/c++/backward"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.2/inclu
de"
ignoring duplicate directory "/mingw/lib/gcc/mingw32/4.6.2/../../../../include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.2/inclu
de-fixed"
ignoring nonexistent directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.2/../
../../../mingw32/include"
ignoring duplicate directory "/mingw/include"
#include "..." search starts here:
#include <...> search starts here:
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/mingw32
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/backward
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../include
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include-fixed
End of search list.
GNU C++ (GCC) version 4.6.2 (mingw32)
compiled by GNU C version 4.6.2, GMP version 5.0.1, MPFR version 2.4.1,
MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: f7eb4168c2cf10318cc29da8d23b7f3c
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=i386' '-march=i386'
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/as.exe -o C:\User
s\Sean\AppData\Local\Temp\ccb0vTGl.o C:\Users\Sean\AppData\Local\Temp\ccSVBzeY.s
COMPILER_PATH=c:/mingw/bin/../libexec/gcc/mingw32/4.6.2/;c:/mingw/bin/../libexec
/gcc/;c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/
LIBRARY_PATH=c:/mingw/bin/../lib/gcc/mingw32/4.6.2/;c:/mingw/bin/../lib/gcc/;c:/
mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/lib/;c:/mingw/bin/../lib/
gcc/mingw32/4.6.2/../../../;/mingw/lib/
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=i386' '-march=i386'
c:/mingw/bin/../libexec/gcc/mingw32/4.6.2/collect2.exe -Bdynamic -u ___register
_frame_info -u ___deregister_frame_info c:/mingw/bin/../lib/gcc/mingw32/4.6.2/..
/../../crt2.o c:/mingw/bin/../lib/gcc/mingw32/4.6.2/crtbegin.o -Lc:/mingw/bin/..
/lib/gcc/mingw32/4.6.2 -Lc:/mingw/bin/../lib/gcc -Lc:/mingw/bin/../lib/gcc/mingw
32/4.6.2/../../../../mingw32/lib -Lc:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../.
. -L/mingw/lib C:\Users\Sean\AppData\Local\Temp\ccb0vTGl.o -lstdc++ -lmingw32 -l
gcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -ladvapi32 -lshell32 -luser32 -lkernel
32 -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt c:/mingw/bin/../lib/gcc
/mingw32/4.6.2/crtend.o
Stacktrace:
hello.exe [C/C++ Application]
hello.exe [9092]
Thread [1] 0 (Suspended : Signal : SIGSEGV:Segmentation fault)
libstdc++-6!_ZNSs12_Alloc_hiderC1EPcRKSaIcE() at 0x6fc89542
libstdc++-6!_ZNSsC1Ev() at 0x6fc8c38b
main() at hello.cpp:7 0x4013a7
gdb
The problems also occur using 32 bit code::blocks or when compiled manually from the command line.
How can I fix this?
When I tried to run the EXE on another computer that didn't have MinGW intalled, it complained:
The program can't start because libgcc_s_dw2-1.dll is missing from you
computer. Try reinstalling the program to fix this problem.
Googling that error led me to the SO question The program can't start because libgcc_s_dw2-1.dll is missing
From the answer:
The libgcc_s_dw2-1.dll should be in the compiler's bin directory.
You can add this directory to your PATH environment variable for
runtime linking, or you can avoid the problem by adding
"-static-libgcc -static-libstdc++" to your compiler flags.
So I added the flags, and the resulting program ran normally on both systems. I'm not sure why these flags were required for it to work properly on my dev system, because the MinGW bin directory is in the PATH. Can anyone provide an explinantion? Should I create a seperate question?