How can I solve this error on macOS catalina? - c++

I am trying to compile a Cpp program with g++ compiler, but I am getting this error:
Yuliam-MBP:Documents yuliamosh$ g++-9 -std=c++17 -Wall -Wextra -pedantic vector.cpp -o vector
In file included from /usr/local/Cellar/gcc/9.2.0_3/include/c++/9.2.0/bits/postypes.h:40,
from /usr/local/Cellar/gcc/9.2.0_3/include/c++/9.2.0/iosfwd:40,
from /usr/local/Cellar/gcc/9.2.0_3/include/c++/9.2.0/ios:38,
from /usr/local/Cellar/gcc/9.2.0_3/include/c++/9.2.0/ostream:3,
from /usr/local/Cellar/gcc/9.2.0_3/include/c++/9.2.0/iostream:39,
from vector.cpp:1:
/usr/local/Cellar/gcc/9.2.0_3/include/c++/9.2.0/cwchar:44:10: fatal error: wchar.h: No such file or directory
44 | #include <wchar.h>
| ^~~~~~~~~
compilation terminated.

It seems like "wchar.h" was not found.
I would suggest to follow the instructions from this thread.

INSTALL
xcode-select --install
THEN SWITCH TO NEWLY INSTALLED TOOLS
sudo xcode-select --switch /Library/Developer/CommandLineTools/
You might need to reset the default location of the compile tools:
xcode-select --reset
These are the usual fixes. SADLY, NONE OF THEM WORKED FOR ME!
THIS IS WHAT WORKED FOR ME:
Homebrew Solution

Related

Issue with Intel compilation on macOS 10.15 Catalina : catastrophic error: cannot open source file "stdlib.h"

I try desperatly to compile with c++ intel compiler (icpc) a simple code that I was used to compile on my previous macBook 10.14.
Now, since Headers don't exist anymore with 10.15 Catalina, the compiler has difficulties to find stdlib.h. Here the output I get :
icpc -std=c++11 -O3 -xHost -fp-model strict -prec-div -prec-sqrt -fma -ftz -mp1 -qopenmp -Wall -c -I/opt/intel/compilers_and_libraries_2020.2.258/mac/mkl/include -mkl=parallel main.cpp -o main.o
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/math.h(301),
from /opt/intel/compilers_and_libraries_2020.2.258/mac/compiler/include/math.h(177),
from /Library/Developer/CommandLineTools/usr/include/c++/v1/cmath(304),
from TSAF.h(1),
from main.cpp(1):
/Library/Developer/CommandLineTools/usr/include/c++/v1/stdlib.h(20): catastrophic error: cannot open source file "stdlib.h"
#include_next <stdlib.h>
^
compilation aborted for main.cpp (code 4)
make: *** [Makefile:13: main.o] Error 4
./main_intel.exe: No such file or directory
I tried a lot of potential workarounds from the net but none works. I would like to avoid to create a directory /usr/include/ by removing the security system of my macBook.
I thought maybe this would work by downloading XCode_12.0.1 but same problems remain.
For the moment, I have the version Catalina OS 10.15.7, all has been updated.
EDIT 1: There is something that I don't understand : on my previous macBook 10.14, I didn't need to use the headers of clang c++ for intel compilation.
If anyone could give me a suggestion/clue/track, this would be fine.
Run the command in the Terminal
sudo xcode-select --reset
And then check if proper developer tools are selected instead of the command line tools
xcode-select -p

how to build liburing

I am build liburing which is a user interface for io_uring features.
But when I run ./configure it throws this error:
/tmp/fio-conf--21449-.c:2:10: fatal error: linux/time_types.h: No such file or directory
#include <linux/time_types.h>
^~~~~~~~~~~~~~~~~~~~
compilation terminated.
but I found in
/usr/src/linux-headers-5.3.0-46-generic/include/uapi/linux$ ls time_types.h
time_types.h
My kernal version is
uname -rs
Linux 5.3.0-46-generic
I'm sure that the 5.3 version is supporting io_uring (which has already been supported by 5.1)
so how to Update kernel/libc headers to support this?
First, you have to clone the repo:
git clone https://github.com/axboe/liburing.git
Then you can build:
make -C ./liburing
After that, you can compile your program.c with liburing:
gcc program.c -o ./program -I./liburing/src/include/ -L./liburing/src/ -Wall -O2 -D_GNU_SOURCE -luring

Error: sigjmp_buf does not name a type. When Compiling my project with Poco C++ libraries

I'm working on a C++ project under Windows10_x86_64.
I'm using Poco C++ libraries installed using Msys2 for a MinGW64 compiler.
All my project's dependencies were installed successfully by using Msys2.
However when I'm trying to compile my project I got next error:
In file included from /mingw64/include/Poco/Thread_POSIX.h:23,
from /mingw64/include/Poco/Thread.h:35,
from /mingw64/include/Poco/ThreadPool.h:22,
from /mingw64/include/Poco/ActiveStarter.h:22,
from /mingw64/include/Poco/ActiveMethod.h:24,
from /mingw64/include/Poco/AbstractEvent.h:25,
from /mingw64/include/Poco/BasicEvent.h:21,
from /mingw64/include/Poco/Util/AbstractConfiguration.h:25,
from /mingw64/include/Poco/Util/LoggingConfigurator.h:24,
from ../../prompt/common/PLogger.h:41,
from PLogger.cpp:15:
/mingw64/include/Poco/SignalHandler.h:80:2: error: 'sigjmp_buf' does not name a type; did you mean 'jmp_buf'?
80 | sigjmp_buf& jumpBuffer();
| ^~~~~~~~~~
| jmp_buf
/mingw64/include/Poco/SignalHandler.h:99:3: error: 'sigjmp_buf' does not name a type; did you mean 'jmp_buf'?
99 | sigjmp_buf buf;
| ^~~~~~~~~~
| jmp_buf
After reviewing SignalHandler.h I saw that this file includes:
#include <setjmp.h>
And that file includes:
#include <machine/setjmp.h>
which define sigjmp_buf:
/* POSIX sigsetjmp/siglongjmp macros */
#ifdef _JBTYPE
typedef _JBTYPE sigjmp_buf[_JBLEN+1+((sizeof (_JBTYPE) + sizeof (sigset_t) - 1)
/sizeof (_JBTYPE))];
#else
typedef int sigjmp_buf[_JBLEN+1+(sizeof (sigset_t)/sizeof (int))];
#endif
I'm including:
-Ic:/msys64/usr/include for setjmp.h and machine/setjmp.h and
-Ic:/msys64/mingw64/include for Poco headers
into my Makefile, but the errors persists.
I don't understand where's the error.
Thanks in advance.
To compile project files I used statements like:
g++ -o ../../../../target/build/debug/PLogger.o PLogger.cpp -I../../ -std=c++14 -Werror -pedantic -Wall -Wformat -Winline -Wunused -g -D_DEBUG -DPCOM_EXPORTS -fpic -c
And I resolve this error removing: -std=c++14 option. However I got a new error:
relocation truncated to fit: R_X86_64_PC32 against undefined symbol
WTF?
As I said before I'm using Msys2 to port this project to MS Windows (my first experience with Msys2). And I started installing every package manually:
gcc, gdb, make, boost, poco, etc.
My final solution (PROBLEM RESOLVED) was uninstall Msys2 deleting all files from my computer. Reinstall it, and then firstly:
$ pacman -Syu
$ pacman -Su
$ pacman -S mingw-w64-x86_64-toolchain -> instead of install manually gcc
...
$ pacman -S mingw-w64-x86_64-poco
$ pacman -S git
Now everything is working fine.
Thanks #CookieButter for your comment.

clang++ 9.0.1 with -stdlib=libc++ cannot find <optional>

I'm on Manjaro Linux with clang++ 9.0.1.
I'm testing std::optional in C++17. When I compile without -stdlib=libc++, the test cpp file compiles without error. However, if I specify -stdlib=libc++, clang++ shows the following error:
$ clang++ -std=c++17 --stdlib=libc++ test.cpp
test.cpp:4:10: fatal error: 'optional' file not found
#include <optional>
^~~~~~~~~~
1 error generated.
Could you please tell me what I should do if I need to compile it with -stdlib=libc++? Thanks in advance!
Thanks to #nathanoliver and #rian-quinn. I find myself so stupid -- I haven't installed libc++. The error got solved by sudo pacman -S libc++.

fatal error: GL/glx.h: No such file or directory libgl1-mesa-dev already installed

I'm trying to compile skia to compile aseprite on Ubuntu 19.10, I keep getting the error
c++ -MMD -MF obj/src/gpu/gl/glx/gpu.GrGLMakeNativeInterface_glx.o.d -DNDEBUG -DSK_SAMPLES_FOR_X -DSK_GAMMA_APPLY_TO_A8 -DSK_ALLOW_STATIC_GLOBAL_INITIALIZERS=0 -DSK_ENABLE_DISCRETE_GPU -DSKIA_IMPLEMENTATION=1 -I../../include/android -I../../include/c -I../../include/codec -I../../include/config -I../../include/core -I../../include/docs -I../../include/effects -I../../include/encode -I../../include/gpu -I../../include/atlastext -I../../include/pathops -I../../include/ports -I../../include/svg -I../../include/utils -I../../include/utils/mac -I../../include/private -I../../src/c -I../../src/codec -I../../src/core -I../../src/effects -I../../src/fonts -I../../src/image -I../../src/images -I../../src/lazy -I../../src/opts -I../../src/pathops -I../../src/pdf -I../../src/ports -I../../src/sfnt -I../../src/shaders -I../../src/shaders/gradients -I../../src/sksl -I../../src/utils -I../../src/utils/win -I../../src/xml -I../../third_party/gif -I../../src/gpu -fstrict-aliasing -fPIC -O3 -fdata-sections -ffunction-sections -Wno-unused-parameter -std=c++14 -fno-exceptions -fno-rtti -c ../../src/gpu/gl/glx/GrGLMakeNativeInterface_glx.cpp -o obj/src/gpu/gl/glx/gpu.GrGLMakeNativeInterface_glx.o
../../src/gpu/gl/glx/GrGLMakeNativeInterface_glx.cpp:15:10: fatal error: GL/glx.h: No such file or directory
15 | #include <GL/glx.h>
| ^~~~~~~~~~
all the posts I've found have said to install libgl1-mesa-dev using apt-get, but I've already done that and I'm still getting the error. I've also tried running install_dependencies.sh in the tools folder, which installed a bunch of other stuff.
You could download the glx file file and copy it to your project file this will fix the error but us not recommended
I figured it out, I had set apt-get to use the oibaf ppa for graphics drivers, purging the ppa and reinstalling from the standard sources fixed it.