CMake教程-第 2 步 添加一个库
CMake教程-第 2 步 添加一个库
- 1 CMake教程介绍
- 2 学习步骤
- Step 1: A Basic Starting Point
- Step 2: Adding a Library
- Step 3: Adding Usage Requirements for a Library
- Step 4: Adding Generator Expressions
- Step 5: Installing and Testing
- Step 6: Adding Support for a Testing Dashboard
- Step 7: Adding System Introspection
- Step 8: Adding a Custom Command and Generated File
- Step 9: Packaging an Installer
- Step 10: Selecting Static or Shared Libraries
- Step 11: Adding Export Configuration
- Step 12: Packaging Debug and Release
- 3 Step 2: Adding a Library
- 3.1 Exercise 1 - Creating a Library(练习 1 - 创建一个库)
- 3.1.1 目标
- 3.1.2 Helpful Resources(有用的资源)
- 3.1.3 Files to Edit(需编辑的文件)
- 3.1.4 Getting Started(入门指南)
- 3.1.5 Build and Run(构建并运行)
- 3.1.6 解决方案
- 3.1.7 CMakeLists.txt
- 3.1.8 MathFunctions/CMakeLists.txt
- 3.1.9 tutorial.cxx
- 3.2 Exercise 2 - Adding an Option(练习2 - 添加一个选项)
- 3.2.1 目标
- 3.2.2 Helpful Resources(有用的资源)
- 3.2.3 Files to Edit(需要编辑的文件)
- 3.2.4 Getting Started(入门指南)
- 3.2.5 Build and Run(构建并运行)
- 3.2.6 解决方案
- 3.2.7 CMakeLists.txt
- 3.2.8 MathFunctions/CMakeLists.txt
- 3.2.9 MathFunctions/MathFunctions.cxx
该文档是基于CMake的官方教程翻译而来,并稍微添加了自己的理解:
cmake的官方网站为:CMake Tutorial
1 CMake教程介绍
The CMake tutorial provides a step-by-step guide that covers common build system issues that CMake helps address. Seeing how various topics all work together in an example project can be very helpful.
CMake 教程提供了一个循序渐进的指南,涵盖了 CMake 可帮助解决的常见构建系统问题。在一个示例项目中了解各个主题是如何协同工作的,会非常有帮助。
2 学习步骤
The tutorial source code examples are available in this archive. Each step has its own subdirectory containing code that may be used as a starting point. The tutorial examples are progressive so that each step provides the complete solution for the previous step.
本文档中提供了教程源代码示例。每个步骤都有自己的子目录,其中包含可用作起点的代码。教程示例是循序渐进的,因此每一步都提供了前一步的完整解决方案。
Step 1: A Basic Starting Point
- Exercise 1 - Building a Basic Project
- Exercise 2 - Specifying the C++ Standard
- Exercise 3 - Adding a Version Number and Configured Header File
Step 2: Adding a Library
- Exercise 1 - Creating a Library
- Exercise 2 - Adding an Option
Step 3: Adding Usage Requirements for a Library
- Exercise 1 - Adding Usage Requirements for a Library
- Exercise 2 - Setting the C++ Standard with Interface Libraries
Step 4: Adding Generator Expressions
- Exercise 1 - Adding Compiler Warning Flags with Generator Expressions
Step 5: Installing and Testing
- Exercise 1 - Install Rules
- Exercise 2 - Testing Support
Step 6: Adding Support for a Testing Dashboard
- Exercise 1 - Send Results to a Testing Dashboard
Step 7: Adding System Introspection
- Exercise 1 - Assessing Dependency Availability
Step 8: Adding a Custom Command and Generated File
Step 9: Packaging an Installer
Step 10: Selecting Static or Shared Libraries
Step 11: Adding Export Configuration
Step 12: Packaging Debug and Release
3 Step 2: Adding a Library
At this point, we have seen how to create a basic project using CMake. In this step, we will learn how to create and use a library in our project. We will also see how to make the use of our library optional.
至此,我们已经了解了如何使用 CMake 创建一个基本项目。在这一步中,我们将学习如何在项目中创建和使用库。我们还将了解如何选择使用库。
3.1 Exercise 1 - Creating a Library(练习 1 - 创建一个库)
To add a library in CMake, use the add_library() command and specify which source files should make up the library.
要在 CMake 中添加一个库,请使用 add_library()
命令并指定组成该库的源文件。
Rather than placing all of the source files in one directory, we can organize our project with one or more subdirectories. In this case, we will create a subdirectory specifically for our library. Here, we can add a new CMakeLists.txt file and one or more source files. In the top level CMakeLists.txt file, we will use the add_subdirectory() command to add the subdirectory to the build.
我们可以用一个或多个子目录来组织项目,而不是将所有源文件放在一个目录中。在本例中,我们将专门为库创建一个子目录。在这里,我们可以添加一个新的 CMakeLists.txt
文件和一个或多个源文件。在顶层 CMakeLists.txt
文件中,我们将使用 add_subdirectory()
命令将子目录添加到构建中。
Once the library is created, it is connected to our executable target with target_include_directories() and target_link_libraries().
一旦创建了库,就可以使用 target_include_directories()
和 target_link_libraries()
将其连接到我们的可执行目标。
3.1.1 目标
Add and use a library.
添加并使用库。
3.1.2 Helpful Resources(有用的资源)
- add_library()
- add_subdirectory()
- target_include_directories()
- target_link_libraries()
- PROJECT_SOURCE_DIR
3.1.3 Files to Edit(需编辑的文件)
- CMakeLists.txt
- tutorial.cxx
- MathFunctions/CMakeLists.txt
3.1.4 Getting Started(入门指南)
In this exercise, we will add a library to our project that contains our own implementation for computing the square root of a number. The executable can then use this library instead of the standard square root function provided by the compiler.
在本练习中,我们将在项目中添加一个库,其中包含我们自己实现的数字平方根计算方法。然后,可执行文件就可以使用这个库,而不是编译器提供的标准平方根函数。
For this tutorial we will put the library into a subdirectory called MathFunctions. This directory already contains the header files MathFunctions.h and mysqrt.h. Their respective source files MathFunctions.cxx and mysqrt.cxx are also provided. We will not need to modify any of these files. mysqrt.cxx has one function called mysqrt that provides similar functionality to the compiler’s sqrt function. MathFunctions.cxx contains one function sqrt which serves to hide the implementation details of sqrt.
在本教程中,我们将把函数库放到名为 MathFunctions 的子目录中。这个目录已经包含了头文件 MathFunctions.h 和 mysqrt.h。我们还提供了它们各自的源文件 MathFunctions.cxx
和 mysqrt.cxx
,我们不需要修改任何这些文件。mysqrt.cxx
有一个名为 mysqrt 的函数,提供与编译器的 sqrt 函数类似的功能。MathFunctions.cxx
包含一个函数 sqrt,用于隐藏 sqrt 的实现细节。
From the Help/guide/tutorial/Step2 directory, start with TODO 1 and complete through TODO 6.
从 Help/guide/tutorial/Step2 目录中的 TODO 1 开始,完成 TODO 6。
First, fill in the one line CMakeLists.txt in the MathFunctions subdirectory.
首先,在 MathFunctions 子目录下填写一行 CMakeLists.txt。
Next, edit the top level CMakeLists.txt.
接下来,编辑顶层的 CMakeLists.txt 文件。
Finally, use the newly created MathFunctions library in tutorial.cxx
最后,在 tutorial.cxx 中使用新创建的 MathFunctions 库
3.1.5 Build and Run(构建并运行)
Run the cmake executable or the cmake-gui to configure the project and then build it with your chosen build tool.
运行 cmake 可执行文件或 cmake-gui 配置项目,然后使用所选的构建工具构建项目。
Below is a refresher of what that looks like from the command line:
下面是命令行的简要说明:
mkdir Step2_build
cd Step2_build
cmake ../Step2
cmake --build .
Try to use the newly built Tutorial and ensure that it is still producing accurate square root values.
尝试使用新建的 Tutorial,确保它仍能生成准确的平方根值。
3.1.6 解决方案
In the CMakeLists.txt file in the MathFunctions directory, we create a library target called MathFunctions with add_library(). The source files for the library are passed as an argument to add_library(). This looks like the following line:
在 MathFunctions 目录下的 CMakeLists.txt
文件中,我们使用 add_library()
创建了一个名为 MathFunctions 的目标库。库的源文件作为参数传递给 add_library()。如下行所示
- TODO 1: MathFunctions/CMakeLists.txt
add_library(MathFunctions MathFunctions.cxx mysqrt.cxx)
To make use of the new library we will add an add_subdirectory() call in the top-level CMakeLists.txt file so that the library will get built.
- TODO 2: Click to show/hide answer
TODO 2: CMakeLists.txt
add_subdirectory(MathFunctions)
Next, the new library target is linked to the executable target using target_link_libraries().
接下来,使用 target_link_libraries()
将新目标库链接到可执行目标。
- TODO 3: Click to show/hide answer
TODO 3: CMakeLists.txt
target_link_libraries(Tutorial PUBLIC MathFunctions)
Finally we need to specify the library’s header file location. Modify target_include_directories() to add the MathFunctions subdirectory as an include directory so that the MathFunctions.h header file can be found.
最后,我们需要指定库的头文件位置。修改 target_include_directories()
,将 MathFunctions 子目录添加为包含目录,以便找到 MathFunctions.h
头文件。
- TODO 4: Click to show/hide answer
TODO 4: CMakeLists.txt
target_include_directories(Tutorial PUBLIC"${PROJECT_BINARY_DIR}""${PROJECT_SOURCE_DIR}/MathFunctions")
Now let’s use our library. In tutorial.cxx, include MathFunctions.h:
现在,让我们使用我们的函数库。在 tutorial.cxx 中,包含 MathFunctions.h:
- TODO 5: Click to show/hide answer
TODO 5: tutorial.cxx
#include "MathFunctions.h"
Lastly, replace sqrt with our library function mathfunctions::mysqrt.
最后,将 sqrt 替换为我们的库函数 mathfunctions::mysqrt。
- TODO 6: Click to show/hide answer
TODO 6: tutorial.cxxconst double outputValue = mathfunctions::sqrt(inputValue);
3.1.7 CMakeLists.txt
cmake_minimum_required(VERSION 3.10)# set the project name and version
project(Tutorial VERSION 1.0)# specify the C++ standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)# configure a header file to pass some of the CMake settings
# to the source code
configure_file(TutorialConfig.h.in TutorialConfig.h)# TODO 2: Use add_subdirectory() to add MathFunctions to this project
add_subdirectory(MathFunctions)# add the executable
add_executable(Tutorial tutorial.cxx)# TODO 3: Use target_link_libraries to link the library to our executable
target_link_libraries(Tutorial PUBLIC MathFunctions)# TODO 4: Add MathFunctions to Tutorial's target_include_directories()
# Hint: ${PROJECT_SOURCE_DIR} is a path to the project source. AKA This folder!
target_include_directories(Tutorial PUBLIC"${PROJECT_BINARY_DIR}""${PROJECT_SOURCE_DIR}/MathFunctions")# add the binary tree to the search path for include files
# so that we will find TutorialConfig.h
target_include_directories(Tutorial PUBLIC"${PROJECT_BINARY_DIR}")
3.1.8 MathFunctions/CMakeLists.txt
# TODO 14: Remove mysqrt.cxx from the list of sources# TODO 1: Add a library called MathFunctions with sources MathFunctions.cxx
# and mysqrt.cxx
# Hint: You will need the add_library command
add_library(MathFunctions MathFunctions.cxx mysqrt.cxx)# TODO 7: Create a variable USE_MYMATH using option and set default to ON# TODO 8: If USE_MYMATH is ON, use target_compile_definitions to pass
# USE_MYMATH as a precompiled definition to our source files# TODO 12: When USE_MYMATH is ON, add a library for SqrtLibrary with
# source mysqrt.cxx# TODO 13: When USE_MYMATH is ON, link SqrtLibrary to the MathFunctions Library
3.1.9 tutorial.cxx
// A simple program that computes the square root of a number
#include <cmath>
#include <iostream>
#include <string>// TODO 5: Include MathFunctions.h
#include "TutorialConfig.h"
#include "MathFunctions.h"int main(int argc, char* argv[])
{if (argc < 2) {// report versionstd::cout << argv[0] << " Version " << Tutorial_VERSION_MAJOR << "." << Tutorial_VERSION_MINOR << std::endl;std::cout << "Usage: " << argv[0] << " number" << std::endl;return 1;}// convert input to doubleconst double inputValue = std::stod(argv[1]);// TODO 6: Replace sqrt with mathfunctions::sqrtconst double outputValue = mathfunctions::sqrt(inputValue);// calculate square root//const double outputValue = sqrt(inputValue);std::cout << "The square root of " << inputValue << " is " << outputValue<< std::endl;return 0;
}
3.2 Exercise 2 - Adding an Option(练习2 - 添加一个选项)
Now let us add an option in the MathFunctions library to allow developers to select either the custom square root implementation or the built in standard implementation. While for the tutorial there really isn’t any need to do so, for larger projects this is a common occurrence.
现在,让我们在 MathFunctions 库中添加一个选项,允许开发人员选择自定义平方根实现或内置标准实现。虽然在教程中确实没有必要这样做,但对于大型项目来说,这是经常发生的事情。
CMake can do this using the option() command. This gives users a variable which they can change when configuring their cmake build. This setting will be stored in the cache so that the user does not need to set the value each time they run CMake on a build directory.
CMake 可以使用 option() 命令实现这一功能。这样,用户就可以在配置 cmake 编译时更改一个变量。该设置将保存在缓存中,因此用户无需每次在构建目录上运行 CMake 时都设置该值。
3.2.1 目标
Add the option to build without MathFunctions.
增加不使用 MathFunctions 的构建选项。
3.2.2 Helpful Resources(有用的资源)
- if()
- option()
- target_compile_definitions()
3.2.3 Files to Edit(需要编辑的文件)
- MathFunctions/CMakeLists.txt
- MathFunctions/MathFunctions.cxx
3.2.4 Getting Started(入门指南)
Start with the resulting files from Exercise 1. Complete TODO 7 through TODO 14.
从练习 1 的结果文件开始。完成 TODO 7 到 TODO 14。
First create a variable USE_MYMATH using the option() command in MathFunctions/CMakeLists.txt. In that same file, use that option to pass a compile definition to the MathFunctions library.
首先,使用 MathFunctions/CMakeLists.txt
中的 option()
命令创建一个变量 USE_MYMATH
。在同一文件中,使用该选项将编译定义传递给 MathFunctions
库。
Then, update MathFunctions.cxx to redirect compilation based on USE_MYMATH.
然后,更新 MathFunctions.cxx
,根据 USE_MYMATH
重定向编译。
Lastly, prevent mysqrt.cxx from being compiled when USE_MYMATH is on by making it its own library inside of the USE_MYMATH block of MathFunctions/CMakeLists.txt.
最后,通过在 MathFunctions/CMakeLists.txt
的 USE_MYMATH
代码段中将 mysqrt.cxx
设为自己的库,防止在 USE_MYMATH
启用时编译 mysqrt.cxx
。
3.2.5 Build and Run(构建并运行)
Since we have our build directory already configured from Exercise 1, we can rebuild by simply calling the following:
由于我们已经在练习 1 中配置好了构建目录,因此只需调用以下命令即可重建:
cd ../Step2_build
cmake --build .
Next, run the Tutorial executable on a few numbers to verify that it’s still correct.
接下来,用几个数字去运行 Tutorial 可执行文件,以验证它是否仍然正确。
Now let’s update the value of USE_MYMATH to OFF. The easiest way is to use the cmake-gui or ccmake if you’re in the terminal. Or, alternatively, if you want to change the option from the command-line, try:
现在,让我们将 USE_MYMATH 的值更新为 OFF。最简单的方法是在终端使用 cmake-gui 或 ccmake。或者,如果你想通过命令行更改选项,可以尝试
cmake ../Step2 -DUSE_MYMATH=OFF
Now, rebuild the code with the following:
现在,使用以下代码重建代码:
cmake --build .
Then, run the executable again to ensure that it still works with USE_MYMATH set to OFF. Which function gives better results, sqrt or mysqrt?
然后,再次运行可执行文件,确保在将 USE_MYMATH 设置为 OFF 时仍能运行。sqrt 和 mysqrt 哪个函数的结果更好?
3.2.6 解决方案
The first step is to add an option to MathFunctions/CMakeLists.txt. This option will be displayed in the cmake-gui and ccmake with a default value of ON that can be changed by the user.
第一步是在 MathFunctions/CMakeLists.txt 中添加一个选项。该选项将显示在 cmake-gui 和 ccmake 中,默认值为 ON,用户可以更改。
- TODO 7: Click to show/hide answer
TODO 7: MathFunctions/CMakeLists.txt
option(USE_MYMATH "Use tutorial provided math implementation" ON)
Next, make building and linking our library with mysqrt function conditional using this new option.
接下来,使用这一新选项使我们的程序库与 mysqrt 函数的构建和链接成为有条件的。
Create an if() statement which checks the value of USE_MYMATH. Inside the if() block, put the target_compile_definitions() command with the compile definition USE_MYMATH.
创建一条 if()
语句,检查 USE_MYMATH
的值。在 if()
块中,将 target_compile_definitions()
命令与编译定义 USE_MYMATH
放在一起。
- TODO 8: Click to show/hide answer
TODO 8: MathFunctions/CMakeLists.txt
if (USE_MYMATH)target_compile_definitions(MathFunctions PRIVATE "USE_MYMATH")
endif()
When USE_MYMATH is ON, the compile definition USE_MYMATH will be set. We can then use this compile definition to enable or disable sections of our source code.
当 USE_MYMATH
开启时,编译定义 USE_MYMATH
将被设置。然后,我们就可以使用这个编译定义来启用或禁用源代码的各个部分。
The corresponding changes to the source code are fairly straightforward. In MathFunctions.cxx, we make USE_MYMATH control which square root function is used:
对源代码的相应修改相当简单。在 MathFunctions.cxx 中,我们让 USE_MYMATH 控制使用哪个平方根函数:
- TODO 9: Click to show/hide answer
TODO 9: MathFunctions/MathFunctions.cxx
#ifdef USE_MYMATHreturn detail::mysqrt(x);
#elsereturn std::sqrt(x);
#endif
Next, we need to include mysqrt.h if USE_MYMATH is defined.
接下来,如果定义了 USE_MYMATH,我们需要包含 mysqrt.h。
- TODO 10: Click to show/hide answer
TODO 10: MathFunctions/MathFunctions.cxx
#ifdef USE_MYMATH
# include "mysqrt.h"
#endif
Finally, we need to include cmath now that we are using std::sqrt.
最后,既然我们使用了 std::sqrt,就需要加入 cmath。
- TODO 11: Click to show/hide answer
TODO 11 : MathFunctions/MathFunctions.cxx
#include <cmath>
At this point, if USE_MYMATH is OFF, mysqrt.cxx would not be used but it will still be compiled because the MathFunctions target has mysqrt.cxx listed under sources.
此时,如果关闭 USE_MYMATH,就不会使用 mysqrt.cxx,但它仍会被编译,因为 MathFunctions 目标程序的源代码中列出了 mysqrt.cxx。
There are a few ways to fix this. The first option is to use target_sources() to add mysqrt.cxx from within the USE_MYMATH block. Another option is to create an additional library within the USE_MYMATH block which is responsible for compiling mysqrt.cxx. For the sake of this tutorial, we are going to create an additional library.
有几种方法可以解决这个问题。第一种方法是使用 target_sources()
,在 USE_MYMATH
代码块中添加 mysqrt.cxx
。另一种方法是在 USE_MYMATH
代码块中创建一个额外的库,负责编译 mysqrt.cxx
。在本教程中,我们将创建一个附加库。
First, from within USE_MYMATH create a library called SqrtLibrary that has sources mysqrt.cxx.
首先,在 USE_MYMATH 中创建一个名为 SqrtLibrary 的库,其源代码为 mysqrt.cxx。
- TODO 12: Click to show/hide answer
TODO 12 : MathFunctions/CMakeLists.txtadd_library(SqrtLibrary STATICmysqrt.cxx)
Next, we link SqrtLibrary onto MathFunctions when USE_MYMATH is enabled.
接下来,当启用 USE_MYMATH
时,我们将 SqrtLibrary
链接到 MathFunctions
。
- TODO 13: Click to show/hide answer
TODO 13 : MathFunctions/CMakeLists.txttarget_link_libraries(MathFunctions PUBLIC SqrtLibrary)
Finally, we can remove mysqrt.cxx from our MathFunctions library source list because it will be pulled in when SqrtLibrary is included.
最后,我们可以从 MathFunctions
库源代码列表中删除 mysqrt.cxx
,因为当 SqrtLibrary
被包含时,它将被调入。
- TODO 14: Click to show/hide answer
TODO 14 : MathFunctions/CMakeLists.txt
add_library(MathFunctions MathFunctions.cxx)
With these changes, the mysqrt function is now completely optional to whoever is building and using the MathFunctions library. Users can toggle USE_MYMATH to manipulate what library is used in the build.
有了这些更改,mysqrt 函数现在对于构建和使用 MathFunctions 函数库的用户来说完全是可选的了。用户可以切换 USE_MYMATH 来控制在构建过程中使用哪个库。
3.2.7 CMakeLists.txt
cmake_minimum_required(VERSION 3.10)# set the project name and version
project(Tutorial VERSION 1.0)# specify the C++ standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)# configure a header file to pass some of the CMake settings
# to the source code
configure_file(TutorialConfig.h.in TutorialConfig.h)# TODO 2: Use add_subdirectory() to add MathFunctions to this project
add_subdirectory(MathFunctions)# add the executable
add_executable(Tutorial tutorial.cxx)# TODO 3: Use target_link_libraries to link the library to our executable
target_link_libraries(Tutorial PUBLIC MathFunctions)# TODO 4: Add MathFunctions to Tutorial's target_include_directories()
# Hint: ${PROJECT_SOURCE_DIR} is a path to the project source. AKA This folder!
target_include_directories(Tutorial PUBLIC"${PROJECT_BINARY_DIR}""${PROJECT_SOURCE_DIR}/MathFunctions")# add the binary tree to the search path for include files
# so that we will find TutorialConfig.h
target_include_directories(Tutorial PUBLIC"${PROJECT_BINARY_DIR}")
3.2.8 MathFunctions/CMakeLists.txt
# TODO 14: Remove mysqrt.cxx from the list of sources
add_library(MathFunctions MathFunctions.cxx)# TODO 1: Add a library called MathFunctions with sources MathFunctions.cxx
# and mysqrt.cxx
# Hint: You will need the add_library command
# add_library(MathFunctions MathFunctions.cxx mysqrt.cxx)# TODO 7: Create a variable USE_MYMATH using option and set default to ON# TODO 8: If USE_MYMATH is ON, use target_compile_definitions to pass
# USE_MYMATH as a precompiled definition to our source files
if (USE_MYMATH)target_compile_definitions(MathFunctions PRIVATE "USE_MYMATH")
endif()# TODO 12: When USE_MYMATH is ON, add a library for SqrtLibrary with
# source mysqrt.cxx
add_library(SqrtLibrary STATICmysqrt.cxx)# TODO 13: When USE_MYMATH is ON, link SqrtLibrary to the MathFunctions Library
target_link_libraries(MathFunctions PUBLIC SqrtLibrary)
3.2.9 MathFunctions/MathFunctions.cxx
#include "MathFunctions.h"// TODO 11: include cmath
#include <cmath>// TODO 10: Wrap the mysqrt include in a precompiled ifdef based on USE_MYMATH
#ifdef USE_MYMATH
#include "mysqrt.h"
#endifnamespace mathfunctions {
double sqrt(double x)
{// TODO 9: If USE_MYMATH is defined, use detail::mysqrt.
#ifdef USE_MYMATHreturn detail::mysqrt(x);
#elsereturn std::sqrt(x);
#endif// Otherwise, use std::sqrt.// return detail::mysqrt(x);
}
}
相关文章:
CMake教程-第 2 步 添加一个库
CMake教程-第 2 步 添加一个库 1 CMake教程介绍2 学习步骤Step 1: A Basic Starting PointStep 2: Adding a LibraryStep 3: Adding Usage Requirements for a LibraryStep 4: Adding Generator ExpressionsStep 5: Installing and TestingStep 6: Adding Support for a Testin…...
DS 顺序表--类实现(C++数据结构题)
实现顺序表的用 C 语言和类实现顺序表 属性包括:数组、实际长度、最大长度(设定为 1000 ) 操作包括:创建、插入、删除、查找 类定义参考 #include<iostream> using namespace std; #define ok 0 #define error -1 // 顺…...

0.UML
1.图 1.1类图含义 第一层显示类的名称,如果是抽象类,则就用斜体显示。第二层是类的特性,通常就是字段和属性。第三层是类的操作,通常是方法或行为。注意前面的符号, ,表示public,-,表示private,#,表示protected。 1.2接口图 与类图的区别主要是顶端有<< interface >…...

PostgreSQL设置主键为自增
1、创建自增序列 CREATE SEQUENCE table_name_id_seq START 1; 2、设置字段默认值 字段默认值中设置 nextval(table_name_id_seq) 3、常用查询 -- 查询所有序列 select * from information_schema.sequences where sequence_schema public; -- 查询自增序列的当前值 select cu…...

input修改checkbox复选框默认选中样式
问题描述: <input type"checkbox" /> input修改checkbox默认选中样式,直接设置选中后的样式不生效,需要先给复选框设置-webkit-appearance: none(取消默认样式), 再设置样式才会生效。 …...

高云FPGA系列教程(10):letter-shell移植
文章目录 letter-shell简介letter-shell源码获取letter-shell移植函数和变量应用示例 本文是高云FPGA系列教程的第10篇文章。 shell,中文是外壳的意思,就是操作系统的外壳。通过shell命令可以操作和控制操作系统,比如Linux中的Shell命令就包括…...
【C语言学习笔记---指针进阶02】
C语言程序设计笔记---017 C语言进阶之回调函数1、函数指针数组2、回调函数3、 回调函数的应用 --- qsort库函数4、模拟qsort函数5、结语 C语言进阶之回调函数 前言: 通过C语言进阶前篇的指针进阶01的知识,继续学习。这篇引用一个简易计算器的程序进行深…...

低功耗蓝牙物联网:未来连接的无限可能
物联网是连接各种设备和传感器的网络,其目的是实现信息的交换和共享,提高效率并优化生活。在这个领域,低功耗蓝牙(BLE)正在发挥着越来越重要的作用。 低功耗蓝牙是一种无线通信技术,它的主要特点是低功耗和…...

安装社区版本OB
获取一键安装包 https://www.oceanbase.com/softwarecenter 离线安装 [admintest001 ~]$ tar -xzf oceanbase-all-in-one-*.tar.gz [admintest001 ~]$ cd oceanbase-all-in-one/bin/ [admintest001 bin]$ ./install.sh [admintest001 bin]$ source ~/.oceanbase-all-in-one/…...

JSON 串和 Java 对象的相互转换
JSON 串和 Java 对象的相互转换 以 json 格式的数据进行前后端交互 前端发送请求时,如果是复杂的数据就会以 json 提交给后端; 而后端如果需要响应一些复杂的数据时,也需要以 json 格式将数据响应回给浏览器 为达到以上目的就需要重点学习…...

爬虫 — App 爬虫(一)
目录 一、介绍二、APP 爬虫常见反爬三、APP 抓包常用工具四、模拟器五、安装 APP1、下载 APP2、安装 APP 六、fiddler1、工作原理2、安装3、基本介绍 七、环境配置1、fiddler 的配置2、夜神模拟器的配置 八、案例 一、介绍 爬虫分类——数据来源 1、PC 端爬虫(网页…...
如何使用正则表达式实现Java日志信息的抓取与收集
首先,什么是Java日志信息?简单来说,Java应用程序在运行过程中会输出一些信息,这些信息可以用来追踪程序运行状态、调试错误等。而Java日志信息就是这些输出信息的集合。 那么为什么要抓取和收集Java日志信息呢?一方面…...
C/C++算法入门 | 简单模拟
不爱生姜不吃醋⭐️ 如果本文有什么错误的话欢迎在评论区中指正 与其明天开始,不如现在行动! 文章目录 🌴前言🌴一、害死人不偿命的(3n1)猜想1.题目(PAT B1001)2.思路3.代码实现 &am…...

stm32学习-芯片系列/选型/开发方式
【03】STM32HAL库开发-初识STM32 | STM概念、芯片分类、命名规则、选型 | STM32原理图设计、看数据手册、最小系统的组成 、STM32IO分配_小浪宝宝的博客-CSDN博客 STM32:ST是意法半导体,M是MCU/MPU,32是32位。 ST累计推出了:…...
mnist数据集
训练模型 import tensorflow as tfimport keras from keras.models import Sequential from keras.layers import Dense,Dropout, Flatten,Conv2D, MaxPooling2D # from keras.optimizers import SGD from tensorflow.keras.optimizers import Adam,Nadam, SGDfrom PIL import…...

Java之IO概述以及
1.1 什么是IO 生活中,你肯定经历过这样的场景。当你编辑一个文本文件,忘记了ctrls ,可能文件就白白编辑了。当你电脑上插入一个U盘,可以把一个视频,拷贝到你的电脑硬盘里。那么数据都是在哪些设备上的呢?键…...
Spring WebFlux—Reactive 核心
一、概述 spring-web 模块包含以下对响应式Web应用的基础支持: 对于服务器请求处理,有两个级别的支持。 HttpHandler: 用于HTTP请求处理的基本约定,具有非阻塞I/O和Reactive Streams背压,以及Reactor Netty、Undertow、Tomcat、…...

由于找不到d3dx9_43.dll,无法继续执行代码要怎么解决
D3DX9_43.dll是一个动态链接库文件,它是DirectX的一个组件,主要用于支持一些旧版本的游戏和软件。当电脑缺少这个文件时,可能会导致这些游戏和软件无法正常运行。例如,一些老游戏可能需要D3DX9_43.dll来支持图形渲染等功能。此外&…...

git安装配置教程
目录 git安装配置1. 安装git2. git 配置3.生成ssh key:4. 获取生产的密钥3. gitee或者github添加ssh-key4.git使用5. git 使用-本地仓库与远程仓库建立连接第一步:进入项目文件夹,初始化本地仓库第二步:建立远程仓库。 建立远程连接的小技巧 …...

要如何选择报修工单管理系统?需要注意哪些核心功能?
现如今,越来越多的企业已经离不开报修工单管理系统,但市面上的产品繁多,很难寻找到一款特别符合企业需求的系统。企业采购报修工单管理系统的主要目的在于利用其核心功能,如工单流转等,来解决工作事件的流程问题&#…...

【Python】 -- 趣味代码 - 小恐龙游戏
文章目录 文章目录 00 小恐龙游戏程序设计框架代码结构和功能游戏流程总结01 小恐龙游戏程序设计02 百度网盘地址00 小恐龙游戏程序设计框架 这段代码是一个基于 Pygame 的简易跑酷游戏的完整实现,玩家控制一个角色(龙)躲避障碍物(仙人掌和乌鸦)。以下是代码的详细介绍:…...
在鸿蒙HarmonyOS 5中实现抖音风格的点赞功能
下面我将详细介绍如何使用HarmonyOS SDK在HarmonyOS 5中实现类似抖音的点赞功能,包括动画效果、数据同步和交互优化。 1. 基础点赞功能实现 1.1 创建数据模型 // VideoModel.ets export class VideoModel {id: string "";title: string ""…...
uni-app学习笔记二十二---使用vite.config.js全局导入常用依赖
在前面的练习中,每个页面需要使用ref,onShow等生命周期钩子函数时都需要像下面这样导入 import {onMounted, ref} from "vue" 如果不想每个页面都导入,需要使用node.js命令npm安装unplugin-auto-import npm install unplugin-au…...
鸿蒙中用HarmonyOS SDK应用服务 HarmonyOS5开发一个生活电费的缴纳和查询小程序
一、项目初始化与配置 1. 创建项目 ohpm init harmony/utility-payment-app 2. 配置权限 // module.json5 {"requestPermissions": [{"name": "ohos.permission.INTERNET"},{"name": "ohos.permission.GET_NETWORK_INFO"…...

PL0语法,分析器实现!
简介 PL/0 是一种简单的编程语言,通常用于教学编译原理。它的语法结构清晰,功能包括常量定义、变量声明、过程(子程序)定义以及基本的控制结构(如条件语句和循环语句)。 PL/0 语法规范 PL/0 是一种教学用的小型编程语言,由 Niklaus Wirth 设计,用于展示编译原理的核…...
鱼香ros docker配置镜像报错:https://registry-1.docker.io/v2/
使用鱼香ros一件安装docker时的https://registry-1.docker.io/v2/问题 一键安装指令 wget http://fishros.com/install -O fishros && . fishros出现问题:docker pull 失败 网络不同,需要使用镜像源 按照如下步骤操作 sudo vi /etc/docker/dae…...

UR 协作机器人「三剑客」:精密轻量担当(UR7e)、全能协作主力(UR12e)、重型任务专家(UR15)
UR协作机器人正以其卓越性能在现代制造业自动化中扮演重要角色。UR7e、UR12e和UR15通过创新技术和精准设计满足了不同行业的多样化需求。其中,UR15以其速度、精度及人工智能准备能力成为自动化领域的重要突破。UR7e和UR12e则在负载规格和市场定位上不断优化…...

QT: `long long` 类型转换为 `QString` 2025.6.5
在 Qt 中,将 long long 类型转换为 QString 可以通过以下两种常用方法实现: 方法 1:使用 QString::number() 直接调用 QString 的静态方法 number(),将数值转换为字符串: long long value 1234567890123456789LL; …...
Java多线程实现之Thread类深度解析
Java多线程实现之Thread类深度解析 一、多线程基础概念1.1 什么是线程1.2 多线程的优势1.3 Java多线程模型 二、Thread类的基本结构与构造函数2.1 Thread类的继承关系2.2 构造函数 三、创建和启动线程3.1 继承Thread类创建线程3.2 实现Runnable接口创建线程 四、Thread类的核心…...

基于Java+MySQL实现(GUI)客户管理系统
客户资料管理系统的设计与实现 第一章 需求分析 1.1 需求总体介绍 本项目为了方便维护客户信息为了方便维护客户信息,对客户进行统一管理,可以把所有客户信息录入系统,进行维护和统计功能。可通过文件的方式保存相关录入数据,对…...