Error "fatal error: 'sys/sysmacros.h' file not found" - macos

I have a compilation error on macOS v11 (Big Sur) with the standard Clang compiler (version 13.0.0).
I am trying to include the sys/sysmacros.h to use the makedev() function which surprisingly is mentioned on the Apple developer website and should be compatible with macOS 15.5+.
Including sys/types.h also gives me an error, however sys/stat.h works. Sadly it still doesn't give me the makedev(), major() and minor() functions that I need.
The Linux manual page of makedev states there were some changes in the glibc library, but as far as I know, macOS does not use the glibc library.
There should be a simple way of installing glibc on macOS using Homebrew (brew) as described here, but I get the same error as was mentioned in this question. So apparently currently there is no proper way of doing it and then I am not sure if this will solve my problem.
Is there a solution to this?

The macro makedev is defined in sys/types.h. Just add #include <sys/types.h> into your files. sys/types.h is a header file of Kernel.framework. You should set it in the Clang invocation, like clang -framework Kernel ....
You can also define these macros as they are defined in sys/types.h:
#define major(x) ((int32_t)(((u_int32_t)(x) >> 24) & 0xff))
#define minor(x) ((int32_t)((x) & 0xffffff))
#define makedev(x, y) ((dev_t)(((x) << 24) | (y)))

Related

MinGW g++: Multiple definition of vsnprintf when using to_string

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.

macOS Sierra CoreFoundation error while compiling wxWidgets for SimSpark

I am trying to to compile wxWidgets 3.0.2 found here.
I need this library, so that I can compile SimSpark.
I have tried installing the library via MacPorts - this does work. But when I try to compile SimSpark, the compiler states the following:
In file included from /opt/local/include/gcc49/c++/type_traits:35:0,
from /opt/local/Library/Frameworks/wxWidgets.framework/Versions/wxWidgets/3.0/include/wx-3.0/wx/strvararg.h:25,
from /opt/local/Library/Frameworks/wxWidgets.framework/Versions/wxWidgets/3.0/include/wx-3.0/wx/string.h:46,
from /opt/local/Library/Frameworks/wxWidgets.framework/Versions/wxWidgets/3.0/include/wx-3.0/wx/memory.h:15,
from /opt/local/Library/Frameworks/wxWidgets.framework/Versions/wxWidgets/3.0/include/wx-3.0/wx/object.h:19,
from /opt/local/Library/Frameworks/wxWidgets.framework/Versions/wxWidgets/3.0/include/wx-3.0/wx/event.h:16,
from /Users/YEED/Downloads/simspark-0.2.4/plugin/inputwx/inputwx.cpp:23:
/opt/local/include/gcc49/c++/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
I believe that I need to compile wxWidgets with C++11 support, since I already included the C++11 relevant flags when making SimSpark.
When I try to compile wxWidgets, I get a bunch of compiler errors that refer to the same .h file - which is part of CoreFoundation:
In file included from /usr/include/Availability.h:184:0,
from /usr/include/stdlib.h:61,
from /usr/include/assert.h:44,
from ../include/wx/debug.h:13,
from ../include/wx/defs.h:743,
from ../include/wx/wxprec.h:12,
from ../src/common/filefn.cpp:20:
/System/Library/Frameworks/CoreFoundation.framework/Headers/CFDateFormatter.h:53:34: error: expected '}' before '__attribute__'
kCFISO8601DateFormatWithYear API_AVAILABLE(macosx(10.12), ios(10.0), watchos(3.0), tvos(10.0)) = (1UL << 0),
When you look into that specific file, there are a bunch of lines that miss a closing ) and resemble the one printed by the compiler as well. (There should be a closing ) before the comma at the end of the line, right?)
So my question is, is this an actual error in CoreFoundation? If so, how can I fix this or work around it? Or am I actually completely misunderstanding the compiler error thrown when compiling SimSpark in the first place?
EDIT:
I couldn't get wxWidgets to compile, but I have fixed my issues compiling SimSpark with the MacPorts version of wxWidgets. The problem lay within using different compilers (gcc and clang) for the two.

c++ thread-local storage clang-503.0.40 (Mac OSX)

After I declared a variable in this way:
#include <thread>
namespace thread_space
{
thread_local int s;
} //etc.
i tried to compile my code using 'g++ -std=c++0x -pthread [sourcefile]'. I get the following error:
example.C:6:8: error: thread-local storage is unsupported for the current target
static thread_local int s;
^
1 error generated.
If i try to compile the same code on Linux with GCC 4.8.1 whit the same flags, i get a functioning executable file. I'm using clang-503.0.40 (the one which comes with Xcode 5.1.1) on a MacBook Pro running OSX 10.9.3. Can anybody explain me what i'm doing wrong?
Thank you!!
Try clang++ -stdlib=libc++ -std=c++11. OS X's outdated libstdc++ doesn't support TLS.
Edit
Ok, this works for the normal clang version but not for the Xcode one.
I did a diff against Apple's clang (503.0.38) and the normal released one and found the following difference:
.Case("cxx_thread_local",
- LangOpts.CPlusPlus11 && PP.getTargetInfo().isTLSSupported() &&
- !PP.getTargetInfo().getTriple().isOSDarwin())
+ LangOpts.CPlusPlus11 && PP.getTargetInfo().isTLSSupported())
So I think this is a bug in Apple's clang version (or they kept it in there on purpose - but still weird, because -v says based on 3.4).
Alternatively, you can use compiler extensions such as __thread (GCC/Clang) or __declspec(thread) (Visual Studio).
Wrap it in a macro and you can easily port your code across different compilers and language versions:
#if HAS_CXX11_THREAD_LOCAL
#define ATTRIBUTE_TLS thread_local
#elif defined (__GNUC__)
#define ATTRIBUTE_TLS __thread
#elif defined (_MSC_VER)
#define ATTRIBUTE_TLS __declspec(thread)
#else // !C++11 && !__GNUC__ && !_MSC_VER
#error "Define a thread local storage qualifier for your compiler/platform!"
#endif
...
ATTRIBUTE_TLS static unsigned int tls_int;
The clang compiler included in the Xcode 8 Beta and GM releases supports the C++11 thread_local keyword with both -std=c++11 and -std=c++14 (as well as the GCC variants).
Earlier versions of Xcode apparently supported C-style thread local storage using the keywords __thread or _Thread_local, according to the WWDC 2016 video "What's New in LLVM" (see the discussion beginning at 5:50).
Seems like you might need to set the minimum OS X version you target to 10.7 or higher.

Intel C++ compiler and cannot open stdarg.h on OS X

OS X 10.6.8, XCode 3.2.6, Base SDK 10.5, Intel Compiler 11.1
I am getting a weird message when I try to compile that says:
catastrophic error: could not open source file "stdarg.h"
I am using a PCH, I did find: Xcode Intel compiler icc cannot find #include <algorithm>
which is a similar issue and I think that the source file type is set to .c.c instead of .c
From what I can see stdarg.h is:
/* This file is public domain. */
/* GCC uses its own copy of this header */
#if defined(__GNUC__)
#include_next <stdarg.h>
#elif defined(__MWERKS__)
#include "mw_stdarg.h"
#else
#error "This header only supports __MWERKS__."
#endif
so must be GNUC is defined, obviously.
Can anyone help me figure out how to better compile since this works without changes in GCC 4.0? Is there a global way one might have XCode re-evaluate the source file type to not be .c.c or .cpp.cpp I am not even sure how this would happen.
Also, is there a #define that I can check to see if the Intel compilers are being used to make special cases if I need to?
I looked at a few of the files referenced in the build results and looking at the source file type in XCode it says source.c.c and I think if I change that to source.c that compiler error goes away.

Xcode Intel compiler icc cannot find #include <algorithm>

Hi I'm trying to compile a gcc based code on Xcode with the icc compiler (11.1.088)
but i have the following error:
catastrophic error: could not open source file "algorithm"
After looking to this file, it is located in the gcc include directory, but i get hundreds of errors...
Does anyone have suggestions ?
Thanks.
I was having a really stubborn error very similar to this question but with a different solution.
Algorithm: No such file or directory
My solution:
#ifdef __cplusplus
#include <algorithm>
#endif
I had the #include in a prefix header file (such as the .pch file Xcode gives you in a new project) which was causing it to be included in an Objective-C file, and apparently algorithm is C++ only. Either make sure all your Objective-C files are Objective-C++ (.mm) or add that directive to make sure it doesn't get included in those files.
What do you have set as your base SDK ? And what version of Xcode ?
FWIW I just tried a test with Xcode 3.2.3 and ICC 11.1 (under OS X 10.6 of course) - created a new C++ console application using the standard Xcode template, added #include <algorithm> to main.cc, switched from the default gcc 4.2 to ICC, and it compiles and runs without warnings or errors. The base SDK is the system default (10.6).
It may just be that you have a bad installation of Xcode and/or ICC, or perhaps you have changed a project setting such as base SDK, and this is causing problems.
This problem occurred on my machine, while developing an iOS app.
Xcode Version 4.6.3 (4H1503) & iOS version 6.0
I'm using AppCode for development and the IDE added (by accident) the following import statement:
#import <c++/4.2.1/ext/algorithm>
I met this error too, I just forget to change the source from .m to .mm. so, if adjust C++ complier cannot work, try to change the source file.

Resources