GCC version versus basic string - c++

I'm running a .cpp code where I get some string dependence error
"basic_string.tcc: No such file or directory"
which should come from some compatibility issue. On my MAC machine "clang version 11.0.0" it works but on my linux machine with gcc 6.3.0 its fails. This happens on function
line read_in(std::string filename_begin, std::string fileformat, size_type n_files)
Any idea how to debug this perhaps,
thanks, Damir

Related

intel C++ cannot open "wchar.h" on mac osx

System OSX 10.14.6, macbook pro
Trying to compile this simple C++ program:
#include <iostream>
int main() {
sdt::cout << "hello world" << std::endl;
return 0;
}
Have gcc 9 installed via homebrew, as well as XCode command line tools.
Both of the following work
c++ main.cpp
g++-9 main.cpp
Trying out the latest Intel Parallel Studio, the following fails:
> icpc main.cpp
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/iosfwd(90),
from /Library/Developer/CommandLineTools/usr/include/c++/v1/ios(215),
from /Library/Developer/CommandLineTools/usr/include/c++/v1/iostream(38),
from main.cpp(1):
/Library/Developer/CommandLineTools/usr/include/c++/v1/wchar.h(119): catastrophic error: cannot open source file "wchar.h"
#include_next <wchar.h>
^
compilation aborted for main.cpp (code 4)
Can someone tell me what I am missing here?
EDIT RESPONSE TO COMMENT ABOUT find
searching from / for wchar.h yields many wchar.h files, including the one from the error:
./usr/local/Cellar/gcc/9.2.0_3/include/c++/9.2.0/tr1/wchar.h
./Library/Developer/CommandLineTools/usr/include/c++/v1/wchar.h
./Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/wchar.h
./Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/usr/include/wchar.h
./Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/wchar.h
./Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS.sdk/usr/include/wchar.h
./Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/wchar.h
./Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/DriverKit19.0.sdk/System/DriverKit/usr/include/wchar.h
./Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator.sdk/usr/include/wchar.h
./Applications/Xcode.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/usr/include/wchar.h
./Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/wchar.h
./Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/wchar.h
./opt/intel/intelpython3/include/c++/v1/support/solaris/wchar.h
./opt/intel/intelpython3/include/c++/v1/wchar.h
./opt/intel/intelpython3/pkgs/libcxx-4.0.1-hcfea43d_1/include/c++/v1/support/solaris/wchar.h
./opt/intel/intelpython3/pkgs/libcxx-4.0.1-hcfea43d_1/include/c++/v1/wchar.h
./dev/fd/3/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/usr/include/wchar.h
./dev/fd/3/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/wchar.h
./dev/fd/3/Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS.sdk/usr/include/wchar.h
./dev/fd/3/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/wchar.h
./dev/fd/3/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/DriverKit19.0.sdk/System/DriverKit/usr/include/wchar.h
./dev/fd/3/Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator.sdk/usr/include/wchar.h
./dev/fd/3/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/usr/include/wchar.h
./dev/fd/3/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/wchar.h
./dev/fd/3/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/wchar.h
./dev/fd/3/opt/intel/intelpython3/include/c++/v1/support/solaris/wchar.h
./dev/fd/3/opt/intel/intelpython3/include/c++/v1/wchar.h
./dev/fd/3/opt/intel/intelpython3/pkgs/libcxx-4.0.1-hcfea43d_1/include/c++/v1/support/solaris/wchar.h
./dev/fd/3/opt/intel/intelpython3/pkgs/libcxx-4.0.1-hcfea43d_1/include/c++/v1/wchar.h
As per the comments, this solved the problem:
icpc main.cpp -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk
Intel C++ compiler on macOS is highly sensitive to the version of Xcode being used. For example, I receive the same errors as above when using icpc 2020 Initial Release and Xcode 11.3.1, but the code compiles and executes just fine with "icpc main.cpp" when using Xcode 11.2.1.
This has been the situation with Intel C++ compilers for some time on macOS... check your Xcode version and try again.

Why cannot I compile my code with g+ in my terminal [duplicate]

I just started using MinGW for Windows. When trying to create executable using
g++ a.cpp -o a.exe -std=c++14
for the code below:
#include <string>
using namespace std;
int main()
{
string x = to_string(123);
return 0;
}
I'm getting following error:
C:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../libmingwex.a(vsnprintf.o):(.text+0x0): multiple definition of vsnprintf
C:\Users\..\Local\Temp\cc4sJDvK.o:c:/mingw/include/stdio.h:426: first defined here
collect2.exe: error: ld returned 1 exit status
What is the root cause for this error and how can I make it go away? While I can easily find a replacement for to_string() function I'm not sure what is causing this error to occur in the first place.
Installing MinGW packages mingw32-libmingwex-* will link an appropriate version of vsnprintf and avoid the linker error.
This issue, i.e. multiple definition of vsnprintf, still exists in MinGW as December 2019.
After investigating a lot, I found the solution in the official mailing list.
It's a bug in mingwrt-5.2.2. Downgrading to the mingwrt-5.2.1 version solves that issue.
To do that, just input the following command:
mingw-get upgrade mingwrt=5.2.1
Then restart the MinGW shell.
Read the full story here.
Note: MinGW-w64 and MinGW are separate projects, so the accepted solution is not so helpful to me, as I want to keep MinGW and not to move to MinGW-w64.
I solved this issue using MinGW w64 compiler
download mingw-w64-install.exe
setup to Version: 6.3.0, Architecture: i686, Threads: posix, Exception: dwarf and Build revision: 2.
I hope this will be of some help.
There are multiple definitions of vsnprintf in both stdio.h and libmingwex.a. I am able to work this around by adding #define __USE_MINGW_ANSI_STDIO 0 to the start of the code, before any includes, which disables the definition of vsnprintf in stdio.h.

std::regex issue with gcc 5.1

I have the following regex expression:
(.*)[[:space:]]+(.+)[[:space:]]+(Error|Information|Trace)([[:space:]]+[1234567890]+)?([[:space:]]+[ndmptl]{1,6})?
When I try to initialize an std::regex variable with that expression, it intermittently crashes.
Here is some test code:
std::string matchRegex ("(.*)[[:space:]]+(.+)[[:space:]]+(Error|Information|Trace)([[:space:]]+[1234567890]+)?([[:space:]]+[ndmptl]{1,6})?");
std::regex rm (matchRegex); // intermittently crashes on this line
I am using gcc 5.1 on Windows 7 64-bit. In particular, I am using the TDM gcc 64 MinGW flavor of gcc.
The crash only happens when I generate 32-bit code (via the gcc flag -m32).
64-bit code always works.
Is there a bug in the std::regex implementation that might be causing this?
I checked my regex with several online regex checkers and it passed 100% of the time.

Migrating GCC from 4.1.2 to 6.2.0 and from RHEL 5.5 to CentOS 7.2

I have RHEL with GCC 4.1.2 and my C++ code is compiling as expected. But same code when I try to compile on CentOS 7.2 with GCC 6.2.0 it fails with below error:
compiling UpcSummarization.o ...
UpcSummarization.cpp: In member function âvoid UpcSummarization::LoadUpcList(std::__cxx11::string)â:
UpcSummarization.cpp:480:40: error: âmemsetâ was not declared in this scope
memset(&pBuffer, 0, sizeof(100));
^
I am including below header file:
string
If I include string.h or cstring it will pass.
Any idea how to make it work with just string include file? Migrating code base to include string.h or cstring is not an option
EDIT
Yes it was string.
May be I should have phrased it as second option instead of not an option
Before starting code migration, I need to rule out the any possibility of compiler options to make it work work as is.
I can install extra libs if required and change the way it is being compile. Not actually editing the code.
I am including below header file:
sting
string?
Any idea how to make it work with just string include file?
You can create a dummy string file and store it with your other headers. Inside string you do for example
#include <string.h>
Migrating code base to include string.h or cstring is not an option
Note that you most probably won't be able to port your code to 6.2 if you can't modify it even to this small extent. 4.1 and 6.2 are 10 years apart so your code will definitely require changes/fixes to work with newer compiler.

inotify on Linux kernel 3.8 with g++

I am trying to use inotify to detect file system changes on an Ubuntu 12.04 OS with Linux 3.8 kernel in a C++ program.
When I compile the program with gcc, it works as expected.
But when I compile the program with g++, it shows errors like -
inotify_test.cpp:23:21: error: ‘inotify_init’ was not declared in this scope
inotify_test.cpp:31:61: error: ‘inotify_add_watch’ was not declared in this scope
Any ideas on how to resolve this is appreciated.
P.S. Some internet links indicate the use of <sys/inotify.h>, but I do not have that file. I only have <linux/inotify.h>.
Thanks!