0

My situation is very similar to what's discussed in this thread. The reason I want to do this is that I am using OpenCV with CUDA 6.0, but CUDA is currently linked against libstdc++. I followed the answer that suggested putting the flag -stdlib=libstdc++ as well as the other approach where we set CXX and CXXFLAGS but as it was being commented: Macports did not seem to acknowledge the flags and still built with libc++ instead of intended libstdc++.

I would like to comment on that thread to ask for a follow-up, but unfortunately I do not have enough reputation yet.

Does anyone know how to get Macports to install OpenCV with libstdc++?

Edited 1: I have not gone back to check whether or not one of the answers provided below works. Compiling OpenCV with libstdc++ will cause issues with a few other non-CUDA projects that use libc++ primarily, so it is unlikely I will try. I will, however, accept an answer if someone can try out an answer below and comment to me if it works.

Edited 2: This question no longer applies to my situation since CUDA 7.0 RC has libc++ support by default. I will still accept an answer per Edited 1.

Community
  • 1
  • 1
HuaTham
  • 7,486
  • 5
  • 31
  • 50
  • Reconsidering the answer I gave, it might be necessary to use the gcc-4.8.2 port, and pass `gcc -std=c99` and/or `g++ -std=c++11` as the `CC`, `CXX` variables. You also need to ensure that any dependencies are build with libstdc++. `port rdeps OpenCV` lists a *lot* of packages, and some have C++ components unfortunately. – Brett Hale Jul 07 '14 at 07:47

2 Answers2

1

In the case of boost, I was able to force MacPorts to link against libstdc++ like so:

sudo port -s install boost configure.cxx_stdlib="libstdc++" configure.compiler="macports-gcc-4.7"

And that was it! Apparently there's no need to pass "-stdlib=libstdc++" yourself. otool -L shows what I was hoping to see:

$ otool -L /opt/local/lib/libboost_date_time-mt.dylib
/opt/local/lib/libboost_date_time-mt.dylib:
        /opt/local/lib/libboost_date_time-mt.dylib (compatibility version 0.0.0, current version 0.0.0)
        /opt/local/lib/libgcc/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.18.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)
        /opt/local/lib/libgcc/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
Bill Agee
  • 3,606
  • 20
  • 17
  • 1
    MacPorts dev here – if any, this is the correct answer. Note that you don't need to force the use of MacPorts GCC, setting `configure.cxx_stdlib` should be enough. Note that doing this may break dependent packages, but you're probably aware of that. – neverpanic Aug 16 '14 at 00:07
  • I disagree. The original report states "CUDA is currently linked against libstdc++" ... *WHICH* libstdc++ is it linked against? If it is linked against the host libstdc++, then you should not link against both the host libstdc++ and MacPorts libstdc++ and expect to pass objects between CUDA and OpenCV. – Jeremy Huddleston Sequoia Jan 11 '15 at 09:21
0

If CUDA is linked against /usr/lib/libsdtd++.6.dylib, then you cannot use the macports-gcc ports as indicated in the other answer as doing so would result in CUDA using a different C++ runtime than OpenCV which can result in issues.

If you have a fresh install of MacPorts, you can edit macports.conf and set up your install to use libstdc++ instead of libc++. Just edit /opt/local/etc/macports.conf to contain the line:

cxx_stdlib libstdc++

Note that doing so will mean that you won't have access to ports that require C++11 or newer functionality.

Also note, that libstdc++ is deprecated, and MacPorts does not support officially support its use in Mavericks and later.

Jeremy Huddleston Sequoia
  • 22,938
  • 5
  • 78
  • 86