How to replace boost/thread/tss.hpp on Mac OSX El Capitan? - c++

I recently upgraded my Mac OSX from Yosemite to El Capitan and updated Xcode to v7.1. After the upgrades, I found that my C++ application no longer compiles due to a header file that cannot be found:
../../src/dir/sysArea.h:39:10: fatal error: 'boost/thread/tss.hpp' file not found
#include <boost/thread/tss.hpp>
The clang invocation is like this:
clang -g -std=c++11 -fno-inline -Wall -Werror -Wextra -D_LARGEFILE_SOURCE \
-D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -c \
-o ARCH.darwin_15_i86/debug/file.o file.cpp
I searched my Macintosh using the finder and the file tss.hpp no longer appears to be present. How do I port my application to El Capitan, what is the replacement of Boost's tss.hpp? I tried updating my Boost version from the prior v1.53 to the latest v1.58, but it had no impact, I get the same error when compiling.
export PATH=/usr/local/bin:$PATH
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
sudo chmod o+w /usr/local/opt /usr/local/include /usr/local/lib
brew unlink boost
brew install boost
sudo chmod o-w /usr/local/opt /usr/local/include /usr/local/lib
My C++03 application is including tss.hpp so that it can use the thread_specific_ptr<> feature:
static boost::thread_specific_ptr<Botan::AutoSeeded_RNG> _rng;
for thread local storage (e.g. each thread gets its own version of the static variable.)
The finder was not searching everywhere (would be nice if it did), I do have tss.hpp under /usr/local/include.
I tried adding -stdlib=libc++ and -stdlib=libstdc++ to the clang invocation, but neither got the complier to look in /usr/local/include for the Boost headers. What compiler flags will instruct it to look there other than hardcoding -I/user/local/include?
Note that clang says thread_local is not available as discussed here.

Doing xcode-select --install as per this answer, seems to have told clang to look in the /usr/local/include directory for headers and resolves the issue.

Related

Installing Armadillo on macOS with homebrew

I am trying to install Armadillo with Homebrew with
brew install armadillo
but when I try to compile with
g++ example.cpp -o example -std=c++11 -O2 -larmadillo
it gives the following error:
fatal error: 'armadillo' file not found
How can I solve this problem?
I'm guessing here that you have a new M1 Mac. The issue in this case is that ARM-native homebrew is installed to /opt/homebrew/ by default, meaning armadillo was installed to /opt/homebrew/include/ which is not in your search path.
To see if this is the case, try providing the paths as follows:
CPATH=/opt/homebrew/include LIBRARY_PATH=/opt/homebrew/lib g++ example.cpp -o example -std=c++11 -O2 -larmadillo
To avoid the issue in general, I'm running with those CPATH and LIBRARY_PATH variables exported in my ~/.zprofile file (using zsh). I found this answer on the apple stack exchange helpful.

How do I try out the new `<execution>` header on OSX?

Saw the <execution> header on cppreference, and wanted to try it out.
Here's what I've tried so far:
brew install cmake --HEAD
brew install llvm
Installed versions:
$ /usr/local/opt/llvm/bin/clang++ --version
clang version 7.0.0 (tags/RELEASE_700/final)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin
$ cmake --version
cmake version 3.13.20181204-gb8db7
I thought I might have got cmake flags wrong, so tried compiling directly; here's an isolated one-liner that should work:
CPPFLAGS="-I/usr/local/opt/llvm/include" LDFLAGS="-L/usr/local/opt/llvm/lib" /usr/local/opt/llvm/bin/clang++ -std=c++17 foo.cpp
And here's the (stubborn!) error I keep getting:
fatal error: 'execution' file not found
The line it's complaining about: #include <execution>
Any clues are much appreciated!
Edit: I see the header is missing from /usr/local/opt/llvm/include/c++, so of course it can't work with what I have (and doesn't seem to be present within experimental either), is there another recommended way to install this on osx?
To answer my own question:
I was missing an explicit -std=c++17 flag (interestingly, -std=c++2a doesn't work! Which may be okay, but a bit surprising if you expect that mode to be a superset of the c++17 mode)
Anyway, I can confirm that the following works for me just fine:
CPPFLAGS="-I/usr/local/opt/llvm/include" \
LDFLAGS="-L/usr/local/opt/llvm/lib" \
/usr/local/opt/llvm/bin/clang++ \
-std=c++17 \
foo.cpp

clang++ installed via homebrew (macOS): compilation errors

After installing clang++ (tried v. 6.0.1 and 7.0) with:
brew install --with-toolchain llvm
very trivial programs result to the following error:
In file included from test.cpp:1:
In file included from /usr/local/Cellar/llvm/7.0.0/include/c++/v1/iostream:38:
In file included from /usr/local/Cellar/llvm/7.0.0/include/c++/v1/ios:215:
In file included from /usr/local/Cellar/llvm/7.0.0/include/c++/v1/iosfwd:90:
/usr/local/Cellar/llvm/7.0.0/include/c++/v1/wchar.h:119:15: fatal error: 'wchar.h' file not found
#include_next <wchar.h>
Command used to compile:
clang++7() {
LDFLAGS="-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib"
CPPFLAGS="-I/usr/local/opt/llvm/include"
/usr/local/opt/llvm/bin/clang++ -std=c++11 $CPPFLAGS $LDFLAGS $1
}
Is it possible to use the official clang instead of Apple's version?
With Apple's version, we do not even know which version of LLVM it really is...
It appears that as of Mojave (10.14), Xcode doesn't install system headers in /usr/include anymore. There is a compatibility package that does, but it's not recommended.
Instead, the official solution is for tools to search for headers in /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk. That path can be obtained from
xcrun --show-sdk-path
The release notes say
The Command Line Tools package installs the macOS system headers inside the macOS SDK. Software that compiles with the installed tools will search for headers within the macOS SDK provided by either Xcode at:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
or the Command Line Tools at:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
depending on which is selected using xcode-select.
If you built clang yourself, this can be achieved by passing the -isysroot option to clang:
clang++ -isysroot "$(xcrun --show-sdk-path)" …
See also: https://github.com/Homebrew/homebrew-core/issues/32765
It works for me to add a -I (minus eye) option to the clang++ command line, pointing to /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include

Missing jpeglib.h when building pygame in Cygwin

I'm trying to install pygame with cygwin with the step by step below
http://msdl.cs.mcgill.ca/people/tfeng/svmsccdoc/node49.html
Things are going fine until the last part when I'm running theses 3 lines
export LIBRARY_PATH=/usr/local/lib:$LIBRARY_PATH
export CPATH=/usr/local/include/SDL:$CPATH
python setup.py install build
I have this issue
gcc -fno-strict-aliasing -ggdb -O2 -pipe -Wimplicit-function-declaration - fdebug-prefix-map=/usr/src/ports/python/python-2.7.8-1.i686/build=/usr/src/debug/python-2.7.8-1 -fdebug-prefix-map=/usr/src/ports/python/python-2.7.8-1.i686/src/Python-2.7.8=/usr/src/debug/python-2.7.8-1 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/NEED_INC_PATH_FIX -I/usr/include/python2.7 -c src/imageext.c -o build/temp.cygwin-1.7.33-i686-2.7/src/imageext.o
src/imageext.c:35:21: erreur fatale: jpeglib.h : No such file or directory
#include <jpeglib.h>
As you can see, the file jpeglib.h is missing
I tried to install the missing file by downloading the lib
apt-cyg install libjpeg62
But to no avail
Does anyone have seen that issue before? I browsed the net but found nothing relevant.
TIA
libjpeg62 doesn't have jpeglib.h. You need libjpeg-devel instead.
You can search for specific files in packages using the package search function on the Cygwin website.
You can download an already compiled version of PyGame and skip these steps. This can be painful sometimes.
Just check this page : http://www.lfd.uci.edu/~gohlke/pythonlibs/
or
http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame , to get directly to PyGame section.
The Python extension unofficial windows binaries. You can find alot of Python libraries on this page.
Using theses packages will make you save a lot of time.

Missing Python.h while trying to compile a C extension module

I'm following this tutorial on how to extend Python with C\C++ code.
The section named "Building the extension module with GCC for Microsoft Windows" fails for me with the following error:
fatal error: Python.h: No such file or directory
The section named "Building the extension module using Microsoft Visual C++" also fails with a similar error:
fatal error C1083: Cannot open include file: 'Python.h': No such file or directory
What should I do to solve this?
For Linux, Ubuntu users to resolve the issue of missing Python.h while compiling, simply run the following command in your terminal to install the development package of python:
In Terminal: sudo apt-get install python-dev
Good luck
Do you have the python dev files so that you can find Python.h?
Do you have the location of Python.h specified to your compiler? with gcc this is usually done through a -I path to include.
Figuring out which of those is failing will solve your problem.
from the article you linked:
gcc -c hellomodule.c -I/PythonXY/include
gcc -shared hellomodule.o -L/PythonXY/libs -lpythonXY -o hello.dll
They assumed you installed python in the default location c:\pythonXY(Where X is the major version number and Y is the minor version number).(in your case Python26) If you put python somewhere else replace /PythonXY with where ever you installed it.
The Python official documentation has already made it clear. Check it out here
The header files are typically installed with Python. On Unix, these are located in the directories prefix/include/pythonversion/ and exec_prefix/include/pythonversion/, where prefix and exec_prefix are defined by the corresponding parameters to Python’s configure script and version is '%d.%d' % sys.version_info[:2]. On Windows, the headers are installed in prefix/include, where prefix is the installation directory specified to the installer.
To include the headers, place both directories (if different) on your compiler’s search path for includes. Do not place the parent directories on the search path and then use #include ; this will break on multi-platform builds since the platform independent headers under prefix include the platform specific headers from exec_prefix.
And they have provided a convenient way to get the correct cflags that we should pass to compiler. here
So for example, here is what I got after running the command
root#36fd2072c90a:/# /usr/bin/python3-config --cflags
-I/usr/include/python3.5m -I/usr/include/python3.5m -Wno-unused-result -Wsign-compare -g -fstack-protector-strong -Wformat -Werror=format-security -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes
Pass those flags to the compiler, and it will work.