Macports on OSX 10.9 - compile opencv with libstdc++

我是研究僧i 提交于 2019-12-08 12:46:37

问题


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.


回答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)



回答2:


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.



来源:https://stackoverflow.com/questions/24600350/macports-on-osx-10-9-compile-opencv-with-libstdc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!