cmake学习-2

一些闲话

想来自己弄这个东西也就是为了用cmake下个库函数玩,结果发现自己玩却都玩不会cmake,觉得有点可惜的同时,也觉得自己学东西的路越来越长,想就单单学一下需要的吧,还学不来,看官方文档自知自己看不太懂,也不太想看。啊,就想摆烂也摆不了,想精进也难精进,就慢慢看着玩,找点能学的方法。

回顾一下上期的内容

添加可执行文件到里面
add_executable(生成的可执行文件 源码列表空格隔开或者分号隔开)

设定最低的版本要求
cmake_minimum_required(VERSION 自己写个版本号)

设定项目名称
project(直接写名称,不加引号)

啊,昨天差不多也就学了这点东西,今天早上听到室友刷课,想来我也稍微刷一下吧,点开看了一集cmake教程,不错,不过懒得我,不想看了。两倍速学的东西也挺快的,不过看不了几集不想看了,为啥,离我想看的还有很远。我需要的那个在大十几集里。啊,就有看了看官方那个教程step2,一边刷着手机,一边看了看代码。

开整


看了一眼这些英语,立马就不是那么想看了,嘶,你说我怎么就想着看官方文档了呢,不过该吐槽是吐槽,该看还得看。
大体意思就是,add library执令能制作一个库,可以通过subdirectory来给它放到子文件夹里,不用给他跟自己的代码混在一起。创玩library之后,在采用target那俩指令就能给他连接。
想想也不是特别难,开整。
看了看给的文件目录,看来就是编译库函数,然后用库函数来代替原本自己写的公式:

思想还是很好理解。在里面整一些代码的时候也发现:
add_subdirectory这类的添加子文件夹的,都不需要单引号表示目录。
过程之中,咔咔一顿复制,最后总算是把里面该有的不该有的都给他复制进去了。

TODO弄完了,看看之后再怎么给它编译一下。
官方给的教程也是简洁明了:

几个指令充分的满足了自己所有的需求。
果不其然,真的栓Q,报错了。

D:\project_code\Ccode\cmakeLearn\cmake-3.27.1-tutorial-source\step2_build>cmake ../Step2
-- Building for: Visual Studio 17 2022
-- Selecting Windows SDK version 10.0.20348.0 to target Windows 10.0.19045.
-- The C compiler identification is MSVC 19.34.31937.0
-- The CXX compiler identification is MSVC 19.34.31937.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: D:/VisualStudio/app/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: D:/VisualStudio/app/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at MathFunctions/CMakeLists.txt:7 (add_library):
add_library cannot create target "MathFunctions" because another target
with the same name already exists. The existing target is a static library
created in source directory
"D:/project_code/Ccode/cmakeLearn/cmake-3.27.1-tutorial-source/Step2/MathFunctions".
See documentation for policy CMP0002 for more details.

-- Configuring incomplete, errors occurred!
到文件里看看,发现自己add了两次library,栓Q,服了。遂删掉,结束。
D:\project_code\Ccode\cmakeLearn\cmake-3.27.1-tutorial-source\step2_build>cmake ../Step2
-- Selecting Windows SDK version 10.0.20348.0 to target Windows 10.0.19045.
-- Configuring done (0.0s)
-- Generating done (0.0s)
-- Build files have been written to: D:/project_code/Ccode/cmakeLearn/cmake-3.27.1-tutorial-source/step2_build
过程轻松愉快,觉得自己学到的东西良多,知识保留率约等于0.持续学习,再接再厉。边摆烂边努力。

posted @   aondw  阅读(48)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· .NET Core 中如何实现缓存的预热?
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性
点击右上角即可分享
微信分享提示