In OSX 10.9 the default -stdlib option for clang++ is libc++, so that's what Macport uses when building packages.
Is there any way to tell Macports to use libstdc++ instead?
In particular I would like to build OpenCV through Macports so it's using libstdc++, but I imagine I'll run into a need to do so for other packages as well
The option is simply: -stdlib=libstdc++
If you need finer control over the build process for various ports, you can always set variables like:
CXX = "clang -std=c++11 -stdlib=libc++, CXXFLAGS = "-Wall -O2 -march=core2", etc.
And build <port> from source:
sudo port -s install <port> -universal \
configure.cc="${CC}" configure.cxx="${CXX}" \
configure.cflags="${CFLAGS}" configure.cxxflags="${CXXFLAGS}"
The other alternative, is to install the gcc48 (or above) port, and use it as the compiler. Don't use the old gcc-4.2.1 installed with older versions of Xcode. It's rubbish.
One way to accomplish this appears to be to build opencv from source, and use the configure.cxx_stdlib variable to specify libstdc++ as your C++ runtime.
Try out the following:
sudo port install -s opencv configure.cxx_stdlib="libstdc++"
Related
In OSX 10.9 the default -stdlib option for clang++ is libc++, so that's what Macport uses when building packages.
Is there any way to tell Macports to use libstdc++ instead?
In particular I would like to build OpenCV through Macports so it's using libstdc++, but I imagine I'll run into a need to do so for other packages as well
The option is simply: -stdlib=libstdc++
If you need finer control over the build process for various ports, you can always set variables like:
CXX = "clang -std=c++11 -stdlib=libc++, CXXFLAGS = "-Wall -O2 -march=core2", etc.
And build <port> from source:
sudo port -s install <port> -universal \
configure.cc="${CC}" configure.cxx="${CXX}" \
configure.cflags="${CFLAGS}" configure.cxxflags="${CXXFLAGS}"
The other alternative, is to install the gcc48 (or above) port, and use it as the compiler. Don't use the old gcc-4.2.1 installed with older versions of Xcode. It's rubbish.
One way to accomplish this appears to be to build opencv from source, and use the configure.cxx_stdlib variable to specify libstdc++ as your C++ runtime.
Try out the following:
sudo port install -s opencv configure.cxx_stdlib="libstdc++"
My OS is OS X 10.10.2 and the default compiler for C is clang.
But this version of clang does not support ubsan (undefined sanitizer) which comes in the 3.4 release of clang. I also want to use KLEE to do some analysis. AFAIK KLEE works well with LLVM-<=3.4. I decided to install
llvm-3.4 and clang-3.4 in my laptop.
After installing clang-3.4 in my system, I encountered a issue that the compiler can not locate the c++ header file. I installed clang-3.4 in /usr/local and I can find the c++ header file in /usr/local/include/c++/4.8.4. How can I add this directory to the search path of clang-3.4 and also the c++ library?
for the following demo code:
#include <iostream>
using namespace std;
int main(){
cout<<"Hellow World\n";
return 0;
}
When I compile it using command clang++ test.cpp, I got the error
test1.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
^
1 error generated.
Below is the version of clang I used
clang version 3.4 (tags/RELEASE_34/final)
Target: x86_64-apple-darwin14.1.0
Thread model: posix
I used the following shell command to install llvm-3.4 and clang-3.4:
wget http://llvm.org/releases/3.4/llvm-3.4.src.tar.gz \
http://llvm.org/releases/3.4/clang-3.4.src.tar.gz \
http://llvm.org/releases/3.4/clang-tools-extra-3.4.src.tar.gz \
http://llvm.org/releases/3.4/compiler-rt-3.4.src.tar.gz
tar zxf llvm-3.4.src.tar.gz
tar zxf clang-3.4.src.tar.gz -C llvm-3.4/tools
mv llvm-3.4/tools/clang{-3.4,}
tar zxf clang-tools-extra-3.4.src.tar.gz -C llvm-3.4/tools/clang/tools
mv llvm-3.4/tools/clang/tools/{clang-tools-extra-3.4,extra}
tar zxf compiler-rt-3.4.src.tar.gz -C llvm-3.4/projects
mv llvm-3.4/projects/compiler-rt{-3.4,}
cd llvm-3.4
./configure --enable-cxx11 \
--enable-bindings=none --enable-shared \
--enable-debug-symbols --enable-optimized
make
make install
Now I have two versions of clang in my OS, one is the default one shipped with OSX located in /usr/bin and the other is clang-3.4 located in /usr/local/bin. The previous one can find the C++ header file while the latter can not.
Did you read the user documentation of clang notably the section on command line options ? BTW, current (march 2015) version of clang is 3.6!
For C++ code you should use the clang++ command, not the clang command.
You might pass -I and -L options to clang++ but you might perhaps have misinstalled your clang compiler.
You should be aware of the -v and -H options of clang or clang++ ; they could be useful, at least to understand more your issue.
addenda
BTW, a program reported to work with Clang 3.4 is extremely likely to work with a more modern version, like Clang 3.5 or 3.6
You probably have a PATH issue; you should have configure -d your Clang-3.4 & LLvm-3.4 programs with --program-suffix=-my-3.4 (if you do that, repeat your entire compiler build and installation) and you probably should run /usr/local/bin/clang++-my-3.4 ; maybe you also need some --with-gcc-toolchain additional configure option.
I'm pretty sure that you should be able to try to compile or use your mysterious software requiring Clang-3.4 with a more modern version like 3.5 or 3.6 ; your MacOSX 10.10.2 is rumored to have a Clang-3.5 based system compiler, it very probably is able to compile and work with your mysterious software.
I have recently installed GCC 4.9.2 (port name gcc49) through MacPorts. I am quite happy with its new features such as colorized diagnostics and C++1y/C++14 support improvements, etc.
However, since I started to compile code using GCC 4.9.2, I realized that it is not generating debug symbol directory *.dSYM and gdb says "no debugging symbols found" when I try to debug a program I compiled with -g flag.
Is this a MacPorts specific bug or is there a problem with GCC 4.9?
Thanks
It is not a MacPorts specific issue. MacPorts doesn't really do much to customize the gcc ports.
If you want to create a dSYM bundle and strip your executable, you should just do something like:
gcc-mp-4.9 -g3 -c example.c
gcc-mp-4.9 example.o -o example
dsymutil --out example.dSYM example
strip -S -x example
As a side note, if you want C++11/C++14 support, I suggest you use the clang-3.5 port as that will allow you to use libc++ from the system instead of libstdc++ from MacPorts (and allow you to use system and MacPorts C++ libraries rather than just the STL). Also, lldb is really the preferred debugger for OS X these days.
I am using qmake on OSX with clang. I try to use c++11 with the following flags in the .pro file
QMAKE_CXXFLAGS += -std=c++11 -stdlib=libc++
However qmake generates the follow flag in the makefile
CXXFLAGS = ... -mmacosx-version-min=10.5 ...
This flag causes clang to raise an error
invalid deployment target for -stdlib=libc++ (requires OS X 10.7 or later)
Changing the flag to 10.7 fixed the problem
CXXFLAGS = ... -mmacosx-version-min=10.7 ...
Is there any way to stop qmake from emitting this flag in the makefile?
you can install other compiler for example gcc4.7.
There are few easy ways macports:
1. http://www.macports.org/install.php
2. Applications > Utilities > Terminal
3. In terminal: sudo port selfupdate
4. sudo port install gcc47
5. Now add new compiler in Qt (Projects tab)
6. In profile change QMAKE_CXXFLAGS += -std=c++0x
Other way brew:
1. Applications > Utilities > Terminal
2. In terminal: ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"
3. In terminal: brew doctor
4. In terminal: brew install gcc
5. Now add new compiler in Qt (Projects tab)
6. In profile change QMAKE_CXXFLAGS += -std=c++0x
Specify the target version via QMAKE_MACOSX_DEPLOYMENT_TARGET, e.g.:
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.7
If you would totally get rid of the flag, you would get some message like:
ld: warning: -macosx_version_min not specified, assuming 10.8
So, your compiler will automatically add it anyway.
That flag is there for a reason. It's written into your binary. And when you try to load that binary on an older system, it will abort.
Now, if you really want MacOSX 10.5 compatibility, you cannot use -stdlib=libc++ because that libc++ is simply not available before MacOSX 10.7.
If you need libc++ (e.g. some C++11 features) + you want to make it work on <10.7, that's not so easy. See here for a related question.
I'm trying to compile a CMake project which uses
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-Wall -std=gnu++0x")
in the CMakeLists.txt file under MacOS X Lion. I have installed XCode 4.2.1. but the compiler fails with this:
cd something/src/lib && /usr/bin/c++ -Dlib_ginacra_EXPORTS -Wall -std=gnu++0x -fPIC -o CMakeFiles/lib_ginacra.dir/utilities.cpp.o -c something/src/lib/utilities.cpp
cc1plus: error: unrecognized command line option "-std=gnu++0x"
The compiler's verion is:
c++ --version
i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)
GCC 4.2 is ancient, but Apple don't ship a newer version.
You can either install a modern GCC from somewhere like Mac Ports (which is probably simpler and quicker) or build it yourself following the instructions at http://gcc.gnu.org/wiki/InstallingGCC
For Lion users facing this issue:
Download and Install the MacPorts-2.2.1-10.7-Lion.pkg MacPorts
installer package from here
in a terminal, search for newer GCC versions:
$ port search --name --glob 'gcc*'
install a newer version (I went with gcc5)
$ sudo port install gcc5
get the name of your new version, and set it as default
$ port select --list gcc
Available versions for gcc:
llvm-gcc42
mp-gcc5
none (active)
$ sudo port select --set gcc mp-gcc5
open a new terminal and validate you're updated:
$ c++ --version
c++ (MacPorts gcc5 5.2.0_0) 5.2.0
Most of you getting that error "cc1plus: error: unrecognized command line option -std=gnu++0x" while installing nodejs extension which requires C++ compilation with node-gyp.
So how to solve this error so here is the solution. Basically you get these errors because of Nodejs different version as many node libraries requires C or C++ compilation while installing. So Nodejs older version uses python 2.7 with gcc compiler less than version 4.2 but Nodejs newer version uses gcc44 compiler that's why you get above error while installing any nodejs library.
So you need to degrade your nodejs and node-gyp version and specify the python version if you have multiple python versions installed on your system and then you will not get above error anymore.
Click here to see full tutorial