在OS X上安装C ++库 [英] Installing C++ Libraries on OS X
问题描述
我试图让我的头围绕一些基本的概念,但我似乎无法想象出来。
我真的很困惑它的意思是安装(我认为他们被称为库)为C ++。我试图安装OpenCV,但我不知道什么需要发生它安装,如何检查,或什么真正的OpenCV是(它是一个库,框架,其他?)。
我的理解是,OpenCV(和其他库/框架)仅作为源代码分发,因此能够跨平台工作。然后,下载后,你必须构建它(我不知道什么构建意味着),然后链接您的编译器对它,以便它可以访问文件?我不知道如何做任何这样做,或真的这意味着什么。我认为很多这是由CMake做的,但我不知道CMake真的做什么,如何使用它,或者你如何在你的代码中使用库/框架。此外,像OpenCV这样的库安装在哪里,clang(或任何其他编译器/链接器)如何知道在哪里找到它们,以及它们是什么类型的文件(.a,.dylib,.cpp,.hpp,可执行文件,或一个集合的一切)?这个结构是特定于C ++和OS X还是更广泛的?
我不是在寻找有关如何安装OpenCV或其他库的教程,试图学习如何实际工作,所以我不会需要教程在未来。
如果这是一个愚蠢的问题,我已经广泛搜索的答案,但歉意,找不到任何东西。
提前感谢!
-Mos Fet
$ b $在Mac上进行任何C / C ++开发工作之前,您需要访问App Store并下载 Xcode / code>免费 - 这是苹果的IDE - 集成开发环境。没有 Xcode
,您将没有编译器(即 clang
或 gcc
或 g ++
)和没有构建工具(即 make
)。
安装Xcode
如果您是Mac新手, App Store
看起来像这样:
和 Xcode
看起来像这样:
复制和粘贴单行到您的终端的问题。我不会在这里显示线,万一它有变化,有人看着这个在几年,但很容易看到,如果你去上面的链接。
查找包
然后您可以找到任何您想要的包:
brew search opencv#查找名为opencv的软件包
brew搜索boost#查找boost库
安装OpenCV
因此,对于一个vanilla OpenCV
执行此操作:
brew install opencv
如果你想要一些特殊的安装选项 OpenCV
命令查看可用的额外选项:
brew信息opencv
输出
==>选项
- 32位
仅构建32位
--c ++ 11
使用C ++ 11模式构建
--universal
构建通用二进制
--with-cuda
使用CUDA支持构建
--with-ffmpeg
使用ffmpeg支持构建
--with-gstreamer
使用gstreamer支持构建
--with-jasper
使用jasper支持构建
--with-java
使用Java支持构建
--with-libdc1394
使用libdc1394构建支持
--with-opengl
使用OpenGL支持构建
--with-openni
使用openni支持构建
--with-qt
构建到HighGUI的Qt4后端
--with-quicktime
使用QuickTime for Video I / O而不是QTKit
--with-tbb
启用并行代码OpenCV使用英特尔TBB
--with-ximea
使用XIMEA支持构建
--without-eigen
无特征支持构建
--without-numpy
使用你自己安装的numpy而不是自制的numpy
--without-opencl
使用OpenCL在OpenCV中禁用GPU代码
--without-openexr
Build没有openexr支持
--without-python
没有Python支持的构建
--without-tests
构建不精确&性能测试
--HEAD
安装HEAD版本
因此您要使用 Qt
,因此您可以执行
brew install opencv --with-qt
删除包
您可以稍后删除任何不再需要的包:
brew rm opencv
更新软件包:
您还可以使用以下内容更新所有已安装的软件包:
brew更新& brew升级 - && brew清理
构建项目
一旦你安装了它,你就可以用一个非常简单的命令开始编译和构建你自己的项目:
g ++ $(pkg-config --cflags --libs opencv)process.cpp -o process
然后你可以继续使用 Xcode
IDE以后如果你想一旦你开始。
strong>使用Xcode构建
开始基本编译后,您可能需要开始使用 Xcode
编辑你的程序,为了做到这一点,你必须告诉 Xcode
头文件,以及库在哪里和哪些库链接。这将随您的OpenCV版本而变化,但您需要更改下面两个图中标记的位置。你会发现这些容易,如果你点击它们顺序 - 绿色区域先,然后黄色,然后蓝色,然后红色。
需要进入Xcode设置区域我已经标记上面可以通过运行相同的 pkg-config
命令我建议在上一节。所以执行:
pkg-config --cflags opencv
获取标题(include)文件的位置,然后运行
pkg-config --libs opencv
获取链接器需要填写的信息在 Xcode
。
I am trying to get my head around some basic concepts, but I can't seem to figure them out.
I am really confused over what it means to install (I think they are called libraries) for C++. I am trying to install OpenCV, but I don't know what needs to happen for it to be installed, how to check, or what really OpenCV is (Is it a library, framework, something else?).
My understanding is that OpenCV (and other libraries/frameworks) is distributed as only the source code so that is is able to work cross-platform. Then, after you download it, you have to build it (I don't know what build means though), and then link your compiler against it so that it can access the files? I don't know how any of this would be done, or really what this means. I think a lot of this is done by CMake, but I don't know what CMake really does, how you would use it, or how you would then utilize the library/framework in your code. Also, where would the libraries like OpenCV be installed, how would clang (or any other compiler/linker) know where to find them, and what kind of files would they be (.a, .dylib, .cpp, .hpp, executables, or a collection of everything)? Is this structure specific to C++ and OS X or is it more widespread?
I am not looking for a tutorial on how to install OpenCV or other libraries, but I am instead trying to learn how that actually works so I won't need tutorials in the future.
I apologize if this is a stupid question, I have searched extensively for answers, but can't find anything.
Thanks in advance!
-Mos Fet
解决方案 Before you can do any C/C++ development work on a Mac, you need to go to the App Store and download Xcode
for free - it is Apple's IDE - Integrated Development Environment. Without Xcode
, you will have no compiler (i.e. clang
or gcc
or g++
) and no build tools, (i.e. make
).
Install Xcode
If you are totally new to Mac, App Store
looks like this:
and Xcode
looks like this:
Install Command Line Tools
Next you must install Xcode's command-line tools, so start a Terminal - by pressing Cmd+Spacebar
and starting to type Terminal
and when it guesses correctly, just hit Enter
. Copy and paste the following into Terminal and hit Enter
.
xcode-select --install
Install homebrew
Then, if you want to install OpenCV
on a Mac, install a package manager such as homebrew
which is a matter of copying and pasting a single line from the homebrew website into your Terminal. I will not show the line here in case it ever changes and someone looks at this in a few years, but it is easy to see if you go to the link above.
Find Packages
Then you can find any packages you want with:
brew search opencv # Look for packages called "opencv"
or
brew search boost # Look for "boost" libraries
Install OpenCV
So, for a vanilla (no special options) installation and build of OpenCV
do this:
brew install opencv
If you want some special installation options with OpenCV
you can run this command to see the extra options available:
brew info opencv
Output
==> Options
--32-bit
Build 32-bit only
--c++11
Build using C++11 mode
--universal
Build a universal binary
--with-cuda
Build with CUDA support
--with-ffmpeg
Build with ffmpeg support
--with-gstreamer
Build with gstreamer support
--with-jasper
Build with jasper support
--with-java
Build with Java support
--with-libdc1394
Build with libdc1394 support
--with-opengl
Build with OpenGL support
--with-openni
Build with openni support
--with-qt
Build the Qt4 backend to HighGUI
--with-quicktime
Use QuickTime for Video I/O instead of QTKit
--with-tbb
Enable parallel code in OpenCV using Intel TBB
--with-ximea
Build with XIMEA support
--without-eigen
Build without eigen support
--without-numpy
Use a numpy you've installed yourself instead of a Homebrew-packaged numpy
--without-opencl
Disable GPU code in OpenCV using OpenCL
--without-openexr
Build without openexr support
--without-python
Build without Python support
--without-tests
Build without accuracy & performance tests
--HEAD
Install HEAD version
so you may then decide as a result you want to use Qt
, so you would do
brew install opencv --with-qt
Remove Packages
You can later remove any packages you no longer want with:
brew rm opencv
Update Packages
You can also update all installed packages with:
brew update && brew upgrade --all && brew cleanup
Build a Project
Once you have got it installed, you can start compiling and building your own project with a really simple command like:
g++ $(pkg-config --cflags --libs opencv) process.cpp -o process
Then you can go on to use Xcode
IDE later if you want to once you get started.
Build with Xcode
Once you have got started with basic compilation, you may want to start using Xcode
to edit your programs, to do that, you must tell Xcode
where the header files are and also where the libraries are and which libraries to link. This will vary with your OpenCV version, but you will need to alter the places marked in the two diagrams below. You will find these easily if you click them in order - green area first, then the yellow, then the blue, then the red.
The actual information that will need to go in the Xcode settings areas I have marked above can be found by running the same pkg-config
command I suggested in the previous section. So run:
pkg-config --cflags opencv
to get the location of the header (include) files, and then run
pkg-config --libs opencv
to get the information you need to fill in for the linker in Xcode
.
这篇关于在OS X上安装C ++库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!