简体   繁体   English

CMake帮助find_path find_library-我只是不明白

[英]CMake Help find_path find_library - I just don't understand

I am trying to learn CMake. 我正在尝试学习CMake。 I have the Mastering CMake book and I'm trying to go through my first "easy" tutorial. 我有一本掌握CMake的书,并且正在尝试阅读我的第一个“简单”教程。 Using CMake: Hello World Example 使用CMake:Hello World示例

I made it through the first part alright, but when I tried to add the sub folders for the "Building a library" part of the tutorial I'm just not getting it. 我已经顺利完成了第一部分,但是当我尝试为教程的“ Building a library”部分添加子文件夹时,我只是没有得到它。 I followed the instructions all the way to the very end. 我一直按照指示进行操作,直到最后。

**We've seen an example of how to build a program. **我们已经看到了如何构建程序的示例。 Now let's make a library as well. 现在,我们还要建立一个库。 The library will be called "namer" and it will have a single function "getWorld" that returns the name of the nearest planet. 该库将被称为“命名器”,并且它将具有单个函数“ getWorld”,该函数返回最近的行星的名称。 We choose to put this library in a subdirectory called "namer" - it doesn't really matter where we put it, this is just an example. 我们选择将这个库放在一个名为“ namer”的子目录中-放在哪里并不重要,这只是一个例子。

I made it a subfolder in my HelloWorld project. 我在HelloWorld项目中将其作为子文件夹。 Should I be making this a separate project? 我应该将其作为一个单独的项目吗?

**One way we can help CMake find the Namer package (which will be our namer library) is by writing a helper script called FindNamer.cmake. **我们可以通过写一个名为FindNamer.cmake的帮助脚本来帮助CMake查找Namer包(这将是我们的Namer库)的一种方法。 This is just another file written in the CMake language that pokes around in all the places our library might be hiding. 这只是用CMake语言编写的另一个文件,它在我们的库可能隐藏的所有地方都在四处查找。 Here is an example (put this in "hello/FindNamer.cmake"): 这是一个示例(将其放在“ hello / FindNamer.cmake”中):

This is my FindNamer.cmake file: 这是我的FindNamer.cmake文件:

   find_path(Namer_INCLUDE_DIRS world.h /usr/include "$ENV{NAMER_ROOT}")

   find_library(Namer_LIBRARIES namer /usr/lib "$ENV{NAMER_ROOT}")

   set(Namer_FOUND TRUE)

   if (NOT Namer_INCLUDE_DIRS)
     set(Namer_FOUND FALSE)
   endif (NOT Namer_INCLUDE_DIRS)

   if (NOT Namer_LIBRARIES)
     set(Namer_FOUND FALSE)
   endif (NOT Namer_LIBRARIES)

**The important parts here are the "find_path" and "find_library" commands, which look for the header file world.h and the namer library. **这里重要的部分是“ find_path”和“ find_library”命令,它们查找头文件world.h和命名程序库。

I followed the next instructions and at the very end the tutorial includes this: 我按照以下说明进行操作,并且在最后,本教程包括以下内容:

**If we try again, configuration will still fail since the search path we gave for "find_path" and "find_library" doesn't actually include the needed files. **如果再次尝试,由于我们为“ find_path”和“ find_library”指定的搜索路径实际上未包含所需的文件,因此配置仍将失败。 We could copy them, or have added a hard-coded directory to find_path and find_library pointing to where the files are on our hard drive - but better, in the CMake GUI on windows or by running "ccmake ." 我们可以复制它们,也可以在find_path和find_library中添加硬编码目录,以指向文件在硬盘驱动器上的位置-但更好的是,在Windows上的CMake GUI中或通过运行“ ccmake”。 on Linux, we can just fill in the directories there. 在Linux上,我们可以只在其中填写目录。

At this point I am completely confused (Newbie!!!!). 在这一点上,我完全感到困惑(新手!!!!)。 I don't have a NamerConfig.cmake or namer-config.cmake file and I don't know what the find_path and find_library is supposed to be pointing to. 我没有NamerConfig.cmake或namer-config.cmake文件,我也不知道find_path和find_library应该指向什么。

Thank you in advance for your help, Severely Confused :-( 预先感谢您的帮助,严重困惑:-(

I said I was a newbie. 我说我是新手。 I guess I'm a little tired too! 我想我也有点累! Yes, these must be in two separate projects. 是的,这些必须在两个单独的项目中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM