This question already has an answer here:
Unexpected exception in std::ifstream
(1 answer)
Closed 7 years ago.
Take this simple program:
#include <fstream>
int main()
{
std::ifstream in(".");
int x;
if (in)
in >> x;
}
on Redhat 6, gcc 4.4.7 this runs without error
on Ubuntu 14.04 LTS , gcc 4.8.2 this runs without error
on Redhat 7, gcc 4.8.2 I get:
terminate called after throwing an instance of 'std::ios_base::failure'
what(): basic_filebuf::underflow error reading the file
Aborted (cored dumped)
I think this is related to:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53984
However, then I don't understand why it works on Ubuntu.
Ideas?
The difference isn't the compiler, the difference is the C++ library. One of them has a buggy version of libstdc++, and the other has a working version of either libstdc++ or libc++ or another version.
I've just tested on my Trusty Tahr system. It blows up, just as on Red Hat. So it doesn't "work on Ubuntu".
To verify we're both getting the same results, here's the output of various commands I've used:
cky#sunflower:~/tmp$ g++ -O2 -Wall -o test test.cc
cky#sunflower:~/tmp$ ./test
terminate called after throwing an instance of 'std::ios_base::failure'
what(): basic_filebuf::underflow error reading the file
Aborted (core dumped)
cky#sunflower:~/tmp$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.8.2-19ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.8 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libmudflap --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --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.8.2 (Ubuntu 4.8.2-19ubuntu1)
cky#sunflower:~/tmp$ dpkg -l libstdc++\*
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-======================================-========================-========================-==================================================================================
ii libstdc++-4.8-dev:amd64 4.8.2-19ubuntu1 amd64 GNU Standard C++ Library v3 (development files)
un libstdc++-4.8-doc <none> <none> (no description available)
un libstdc++-dev <none> <none> (no description available)
un libstdc++2.10-dev <none> <none> (no description available)
un libstdc++2.8-dev <none> <none> (no description available)
un libstdc++2.9-dev <none> <none> (no description available)
un libstdc++2.9-glibc2.1-dev <none> <none> (no description available)
un libstdc++3.0-dev <none> <none> (no description available)
ii libstdc++6:amd64 4.8.2-19ubuntu1 amd64 GNU Standard C++ Library v3
un libstdc++6-4.8-dbg <none> <none> (no description available)
Related
Here is the simple C++ code.
#include <iostream>
#include <locale>
int main() {
std::wcout.sync_with_stdio(false);
std::wcout.imbue(std::locale(""));
std::cout << std::locale("").name() << std::endl; // C.UTF-8
wchar_t s {L'\xd0b8'};
std::wcout << s << std::endl;
// expected: и
// actual: 킸
}
'\xd0b8' is и in UTF-8 and is 킸 in UTF-16
The reference mentioned:
The encoding of narrow multibyte string literals (1) and wide string literals (2) is implementation-defined. For example, gcc selects them with the commandline options -fexec-charset and -fwide-exec-charset.
I complied and executed the code with g++ -O3 -fwide-exec-charset=UTF-8 source.cc -o out.a && out.a in Ubuntu 20.04.1 LTS (WSL) and expected the output is и, however, the actual output is 킸. g++ doesn't treat the hex in the literal string which was used to directly initialize the wide char s. How to make g++ consider the wide char in UTF-8?
System Infomation:
> lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.1 LTS
Release: 20.04
Codename: focal
> g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.3.0-10ubuntu2' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 9.3.0 (Ubuntu 9.3.0-10ubuntu2)
man gcc says
-fwide-exec-charset=charset
Set the wide execution character set, used for wide string and character
constants. The default is UTF-32 or UTF-16, whichever corresponds to the width
of "wchar_t". As with -fexec-charset, charset can be any encoding supported by
the system's "iconv" library routine; however, you will have problems with
encodings that do not fit exactly in "wchar_t".
UTF-8 is a multi-byte encoding which does not fit exactly in wchar_t. So you've got exactly what is specified in the documentation: problems. Since sizeof(wchar_t) on Linux is 4, you need to specify a 4-bytes-wide encoding such as UTF-32.
There is no real reason to use wchar_t for anything except interfacing with legacy code anyway.
I am working on a legacy project for my company that requires me to use a specific version of boost and that version is 1.47.0. I have downloaded and run:
./b2 --toolset=gcc variant=debug
and it compiled the majority of the static libraries I needed with the exception of a few. One being libboost_iostreams. I did some research and found that it appeared i was missing some dependencies.
whereis bzip2
bzip2: /bin/bzip2 /usr/share/man/man1/bzip2.1.gz
whereis zlib
zlib: /usr/include/zlib.h /usr/share/man/man3/zlib.3.gz
However when I attempt to run:
./b2 --with-iostreams -s BZIP2_SOURCE=/bin -s ZLIB_SOURCE=/usr/include
I am getting the following error:
Building the Boost C++ Libraries.
error: Unable to find file or target named
error: '/bin/libbz2.def'
error: referred from project at
error: 'libs/iostreams/build'
Update:
Linux Version: 16.04
Gcc Version Info:
gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.4.0-
6ubuntu1~16.04.9' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --
enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --
program-suffix=-5 --enable-shared --enable-linker-build-id --
libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --
libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-
libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new
--enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-
plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --
enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --
enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --
with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-
directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-
objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-
abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --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 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.9)
I upgraded yesterday Ubuntu 16.04 to 17.04 and made a new compliation of my C++ projects. But it ouputs me a shared object file and it supposed to output an executable file of course.
I can execute it from command line but I can't launch the soft from the UI. It worked well in version 16.04.
Here is the end of the compilation:
echo Linking wxFlasher...
mkdir -p /home/barnaud/dev/wxFlasher/wxFlasher/out_gcc/releaseu/
rm -f /home/barnaud/dev/wxFlasher/wxFlasher/out_gcc/releaseu/wxFlasher
g++ -s -o /home/barnaud/dev/wxFlasher/wxFlasher/out_gcc/releaseu/wxFlasher /home/barnaud/dev/wxFlasher/wxFlasher/build_gcc/releaseu/Main/Application.o /home/barnaud/dev/wxFlasher/wxFlasher/build_gcc/releaseu/Main/ResourceManager.o /home/barnaud/dev/wxFlasher/wxFlasher/build_gcc/releaseu/Main/Event.o /home/barnaud/dev/wxFlasher/wxFlasher/build_gcc/releaseu/Main/Thread.o /home/barnaud/dev/wxFlasher/wxFlasher/build_gcc/releaseu/Main/Utils.o /home/barnaud/dev/wxFlasher/wxFlasher/build_gcc/releaseu/HMI/MainFrame.o /home/barnaud/dev/wxFlasher/wxFlasher/build_gcc/releaseu/HMI/PnlFlasher.o /home/barnaud/dev/wxFlasher/wxFlasher/build_gcc/releaseu/HMI/DlgAbout.o /home/barnaud/dev/wxFlasher/wxFlasher/build_gcc/releaseu/HMI/PnlUpdater.o /home/barnaud/dev/wxFlasher/wxFlasher/build_gcc/releaseu/HMI/PnlDump.o /home/barnaud/dev/wxFlasher/wxFlasher/build_gcc/releaseu/HMI/PnlRegen.o /home/barnaud/dev/wxFlasher/wxFlasher/build_gcc/releaseu/Protocol/PlfManagement.o /home/barnaud/dev/wxFlasher/wxFlasher/build_gcc/releaseu/Protocol/UpdaterThread.o /home/barnaud/dev/wxFlasher/wxFlasher/build_gcc/releaseu/Protocol/UpdaterFactory.o /home/barnaud/dev/wxFlasher/wxFlasher/build_gcc/releaseu/Protocol/UartUpdaterProtocol.o /home/barnaud/dev/wxFlasher/wxFlasher/build_gcc/releaseu/Protocol/UartBootloaderProtocol.o /home/barnaud/dev/wxFlasher/wxFlasher/build_gcc/releaseu/Protocol/UsbUpdaterProtocol.o /home/barnaud/dev/wxFlasher/wxFlasher/build_gcc/releaseu/Protocol/UsbBootloaderProtocol.o /home/barnaud/dev/wxFlasher/wxFlasher/build_gcc/releaseu/Protocol/UsbOmap3630Protocol.o /home/barnaud/dev/wxFlasher/wxFlasher/build_gcc/releaseu/Protocol/TestProtocolThread.o /home/barnaud/dev/wxFlasher/wxFlasher/build_gcc/releaseu/Protocol/RegenProtocolThread.o /home/barnaud/dev/wxFlasher/wxFlasher/build_gcc/releaseu/Protocol/posix_crc.o /home/barnaud/dev/wxFlasher/wxFlasher/build_gcc/releaseu/Communication/libusb.o /home/barnaud/dev/wxFlasher/wxFlasher/build_gcc/releaseu/Communication/Uart.o /home/barnaud/dev/wxFlasher/wxFlasher/build_gcc/releaseu/Config/ProductCfg.o /home/barnaud/dev/wxFlasher/wxFlasher/build_gcc/releaseu/Config/ProductXml.o /home/barnaud/dev/wxFlasher/wxFlasher/build_gcc/releaseu/Config/UpdaterCfg.o -L/usr/lib/x86_64-linux-gnu -pthread -lwx_gtk2u_xrc-3.0 -lwx_gtk2u_html-3.0 -lwx_gtk2u_qa-3.0 -lwx_gtk2u_adv-3.0 -lwx_gtk2u_core-3.0 -lwx_baseu_xml-3.0 -lwx_baseu_net-3.0 -lwx_baseu-3.0
Any ideas ?
EDIT :
Here is the output of file command:
wxFlasher: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=3c57f7ee667e4ba8be74a0392d9574a91918fa0e, not stripped
And here is the output of g++ -v command:
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 6.3.0-12ubuntu2' --with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-6 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-6-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-6-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-6-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --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 6.3.0 20170406 (Ubuntu 6.3.0-12ubuntu2)
I have a piece of code that works on my laptop but not on our Linux cluster. It's pretty straight forward.
open(11,file=trim(openfile),form='unformatted',access='STREAM')
throws a runtime error:
Fortran runtime error: Bad ACCESS parameter in OPEN statement
What is happening?
gcc was build as:
gfortran -v Using built-in specs. Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-libgcj-multifile
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada
--enable-java-awt=gtk --disable-dssi --disable-plugin
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre
--with-cpu=generic --host=x86_64-redhat-linux
Thread model: posix gcc version 4.1.2 20080704 (Red Hat 4.1.2-55)
I'm debugging somebody else's Qt program and ran into the following error message which I don't understand:
DWARF-2 expression error: DW_OP_reg operations must be used either alone or in
conjuction with DW_OP_piece or DW_OP_bit_piece.
I'm not sure what that means and Google isn't of much help.
Here's the context - sLocation is a QString that was declared a few lines earlier. However, it was created from functions which were inlined, so I'm not sure of its value and am attempting to check before being appended to:
(gdb) printqstring suffix
(QString)0xffffbd80: "sorted"
(gdb) next
1241 sLocation += suffix;
(gdb) printqstring sLocation
Can't take address of "sLocation" which isn't an lvalue.
(gdb) info local
sLocation = <error reading variable sLocation (DWARF-2 expression error:
DW_OP_reg operations must be used either alone or in conjuction with
DW_OP_piece or DW_OP_bit_piece.)>
Could somebody please explain what that error message means or what could cause it?
The error message means that GDB is reading DWARF2 debug info from the executable, and is rejecting that info as invalid (not following the DWARF2 standard).
The invalid info is likely due to a bug in GCC, fixed in SVN revision 147187:
2009-05-06 Jakub Jelinek <jakub#redhat.com>
* dwarf2out.c (new_reg_loc_descr): Don't ever create DW_OP_regX.
(one_reg_loc_descriptor): Create DW_OP_regX here instead of calling
new_reg_loc_descr.
(loc_by_reference): If loc is DW_OP_regX, change it into DW_OP_bregX 0
instead of appending DW_OP_deref*.
I got the same problem running a Ubuntu 10.10 64bit. However, the same code on a 10.04 LTS 32bit works perfectly.
Here is the version output of both setups
Ubuntu 10.10:
$ gcc -v
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.4.4-14ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --disable-werror --with-arch-32=i686 --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.4.5 (Ubuntu/Linaro 4.4.4-14ubuntu5)
GCC on 10.04 LTS:
$ gcc -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.3-4ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-plugin --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i486 --with-tune=generic --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5
Cheers,
Andre