xcode 如何在 Mac 上使用 cmake
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29727770/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to use cmake on mac
提问by martinerk0
this may seems obvious for someone, but not for me.
这对某人来说似乎很明显,但对我来说却不是。
How to use cmake on Mac? Let's say I have a project in Xcode and I want that project link with assimp library.
如何在 Mac 上使用 cmake?假设我在 Xcode 中有一个项目,并且我想要该项目与 assimp 库的链接。
So I download assimp source, generate build with cmake, point Xcode to /include in downloaded source and what then? Where are built libraries? What I only have is Xcode project of that library. Does it generate libraries?
所以我下载了 assimp 源代码,用 cmake 生成构建,将 Xcode 指向下载的源代码中的 /include ,然后呢?建库在哪里?我只有那个库的 Xcode 项目。它会生成库吗?
If I use brewto install assimp, I only set this in my Xcode project:
如果我使用brew安装 assimp,我只在我的 Xcode 项目中设置它:
- header path is:
/usr/local/include - library search path is:
/usr/local/lib - set liner flag to:
-lassimp
- 头文件路径是:
/usr/local/include - 库搜索路径为:
/usr/local/lib - 将班轮标志设置为:
-lassimp
and I'm finished.
我已经完成了。
What are benefits of cmake for building libraries from source besides that source is "fresh" and I'm unable to do it right?
除了源是“新鲜的”而且我无法正确执行之外,cmake 从源构建库有什么好处?
Could somebody post step-by-step what to do when building things with Cmake, with explanation?
有人可以在使用 Cmake 构建东西时分步发布要做什么,并附上解释吗?
Most importantly where does Cmake put libraries, and how to link with them?
最重要的是 Cmake 将库放在哪里,以及如何与它们链接?
回答by m.s.
CMake does not build the libraries, it "only" generates platform specific Makefiles (or equivalents). You still need to compile and install the compiled libraries and headers.
CMake 不构建库,它“仅”生成特定于平台的 Makefile(或等效文件)。您仍然需要编译和安装已编译的库和头文件。
For the library you want to build the following steps are necessary (I am doing them on Linux, but this should be applicable to Mac OS X as well).
对于要构建的库,必须执行以下步骤(我在 Linux 上执行这些步骤,但这应该也适用于 Mac OS X)。
git clone https://github.com/assimp/assimp.git
cd assimp
mkdir build
cd build
cmake ..
The build
folder now contains a Makefile
, and when you run make
, the library will be compiled.
该build
文件夹现在包含一个Makefile
,当您运行时make
,将编译该库。
After this step, the freshly built library is located at build/code/libassimp.so
.
在这一步之后,新构建的库位于build/code/libassimp.so
.
You could leave the library as well as the include files there and reference them when compiling/linking your project. Usually, you want to install
them, so they are available systemwide and can be found automatically.
您可以将库和包含文件留在那里,并在编译/链接项目时引用它们。通常,您需要install
它们,因此它们在系统范围内可用并且可以自动找到。
This is done using sudo make install
.
这是使用sudo make install
.
The library should now be in /usr/local/lib
, the include files in /usr/local/include
. You can change these locations using CMake.
库现在应该在/usr/local/lib
,包含文件在/usr/local/include
. 您可以使用 CMake更改这些位置。