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

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.

Related

wchar.h no such file or directory

I've been trying to run simple c++ program
#include<iostream.h>
void main(){
cout<<"helloworld";
}
and the error I get is :
In file included from d:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\postypes.h:40:0,
from d:\mingw\lib\gcc\mingw32\6.3.0\include\c++\iosfwd:40,
from d:\mingw\lib\gcc\mingw32\6.3.0\include\c++\ios:38,
from d:\mingw\lib\gcc\mingw32\6.3.0\include\c++\ostream:38,
from d:\mingw\lib\gcc\mingw32\6.3.0\include\c++\iostream:39,
from my.cpp:1:
d:\mingw\lib\gcc\mingw32\6.3.0\include\c++\cwchar:44:19: fatal error: wchar.h: No such file or directory
#include <wchar.h>
^
compilation terminated."
anyone know how to fix it ,I'm using the mingw to compile it.
Probably your MinGW is broken. Also, GCC 6.3.0 is very old.
Try a more recent MinGW or even better MinGW-w64.
A standalone build is available from http://winlibs.com/ with GCC 10.2.0 (both for Windows 32-bit and 64-bit).

clang cross compilation command can not find head files

I'm trying simple cross compilation with clang 10.0 followed the official tutorial, with the option --target=<triple>.
My environment is on 64-bit ubuntu16.04, clang10.0.
My source file is just the a.cpp file:
#include <iostream>
int main() {
std::cout << "hello world" << std::endl;
return 0;
}
If I comile the source for the host machine with clang++ --target=x86_64-unknown-linux-gnu a.cpp, it worked well. But if I use clang++ --target=i386-unknown-linux-gnu a.cpp for 32-bit machine, or clang++ --target=arm-unknown-linux-eabi a.cpp, it got the same errors:
a.cpp:18:10: fatal error: 'iostream' file not found
#include <iostream>
^~~~~~~~~~
1 error generated.
My question is:
1) Whether my compilation command is wrong?
2) What should the host machine prepare for cross compilation to other target machine?
Any answer would be much appreciated!
Apart from the compiler you need the sysroot, where all the header files and runtime libraries are present, to have successful compilation. If the compiler can't find the path to sysroot, it wont know where to find standard library headers etc.
If your system doesn't have a i386 toolchain then you need to download the compiler toolchain that will have the sysroot. e.g. from here: https://github.com/nativeos/i386-elf-toolchain/releases.
clang++ --target=i386-unknown-linux-gnu --sysroot /path/to/sysroot a.cpp
Similarly for arm you can download the toolchain from: https://launchpad.net/gcc-arm-embedded/+download
To learn more about toolchains and sysroot please read: https://elinux.org/Toolchains

C++ header file 'wchar.h' not found using g++ (MacOS)

Disclaimer - I am completely new to C++ and the way this language works regarding compiling / linking. Using MacOS Mojave.
For a school course we are obliged to use the g++ compiler to compile our c++ projects. G++ seems to be successfully installed; g++ -v results in the following output:
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-apple-darwin17.5.0/8.1.0/lto-wrapper
Target: x86_64-apple-darwin17.5.0
Configured with: ../gcc-8.1.0/configure --enable-languages=c++,fortran
Thread model: posix
gcc versie 8.1.0 (GCC)
I created my first "hello world" program:
#include <iostream>
using namespace std;
int main() {
cout << "Hello, World!" << endl;
return 0;
}
When I tried to compile this code (using 'g++ file.cpp), the following terminal output prompted:
In file included from /usr/local/include/c++/8.1.0/bits/postypes.h:40,
from /usr/local/include/c++/8.1.0/iosfwd:40,
from /usr/local/include/c++/8.1.0/ios:38,
from /usr/local/include/c++/8.1.0/ostream:38,
from /usr/local/include/c++/8.1.0/iostream:39,
from ex1.cpp:1:
/usr/local/include/c++/8.1.0/cwchar:44:10: fatale fout: wchar.h: No such file or directory
#include <wchar.h>
^~~~~~~~~
compilation ended.
The whcar.h file is indeed not present in the above folder. After some digging, I found the whcar file in the following folder: /Library/Developer/CommandLineTools/usr/include/c++/v1
Unfortunately I am a bit lost and don't really know what I am talking about, consindering everything is really new for me.
It is greatly appreciated if anyone can guide me in the right direction.
Kind regards,
Thijmen.
For me, reinstalling Xcode Command Line Tools and g++ solved the same issue:
xcode-select --install
brew reinstall gcc
The last line is assuming you have installed homebrew.
I just found out the easiest way of this mess is just download the missing header file to your compiler folder. It will fix everything.

MySQL Connector/C++ in Xcode 9.2 via Homebrew usage problems

I've successfully installed MySQL, Boost and mysql-connector-c++ on my macOS High Sierra 10.13.3 via Homebrew, but i've ran into problems with using those libs in Xcode.
So, my boost and connector libs are located at /usr/local/Cellar/. So i just wrote a simple code sample to check if everything "works":
#include <mysql_driver.h>
#include <mysql_error.h>
#include <mysql_connection.h>
int main()
{
return 0;
}
and compiled it with
c++ -I /usr/local/Cellar/mysql-connector-
c++/1.1.9_1/include/mysql_connection.h /usr/local/Cellar/mysql-connector-
c++/1.1.9_1/include/mysql_driver.h /usr/local/Cellar/mysql-connector-
c++/1.1.9_1/include/mysql_driver.h main.cpp
Everything seems to be working, except I get some warnings:
clang: warning: treating 'c-header' input as 'c++-header' when in C++ mode,
this behavior is deprecated [-Wdeprecated]
clang: warning: treating 'c-header' input as 'c++-header' when in C++ mode,
this behavior is deprecated [-Wdeprecated]
But that's not a huge issue, I think.
And then I try to use those libs in Xcode, so i do this:
Yet when I try to compile any code with those libs in Xcode, I get this:
'boost/scoped_ptr.hpp' file not found with include; use "quotes" instead'
and many errors alike for boost and mysql-connector-c++. Obviosly, changing all <> to "" in source files is NOT a good idea, futhermore, it's extremely tiring.
How to fix this error?

Function to_string() was not resolved using g++ mingw--w64 5.3.0

In Eclipse I am using mingw-w64 V5.3.0 as the compiler and I have enabled C++11 (which was the solution in the following related post here and here). My compilation command looks as follows (from eclipse console window):
g++ -std=c++11 -O0 -g3 -Wall -c -fmessage-length=0 -o "src\Launch.o" "..\src\Launch.cpp"
The simple code I am attempting to run is as follows:
#include <stdio.h>
#include <iostream>
#include <string>
int main()
{
std::string test = std::to_string(0);
std::cout <<"HI" << std::endl;
return 0;
}
The program compiles but for an error stated in the question. Running it without the to_string line works fine. There have been suggestions back in 2012 that MingW has a problem with to_string(), but was resolved in later versions has shown here.
Screen shot below:
And the console output is as follows:
The following is the error I receive when running the code from the .exe directly:
As mentioned in the comments, the issue is a linking issue, however it is linking correctly to iostream which is in the same directory as string.
Eclipse was looking in System32 for the library and driver files, despite PATH and Eclipse pointing to the MingW64 compiler on the computer. Eclipse is also showing it is linked to the MingW64 libraries correctly as the path to the headers when right-clicking and opening deceleration is shown to be correct. Why then it looks in System32 for the library at run-time I don't understand.
The problem was 'solved' by copying the entire MingW64 compiler driver folder into the System32 folder on Windows.