Printing in Makefiles: @echo vs $(info )

What is the difference between these two commands in makefiles:

@echo "Hello World"
$(info Hello World)

As it seems, echo and info print the same output, so where is the difference? And when to use which one?

Well, echo is a shell command. So if you put it in a recipe, a shell will be invoked to run it and the shell command will generate the output:

info is a GNU make function. It is handled directly by make: no shell is invoked. It can appear anywhere in a makefile, not just in a recipe. It is not portable to other versions of make. Because no shell is invoked, there are no quoting issues.

How to print out a variable in makefile

As per the GNU Make manual and also pointed by 'bobbogo' in the below answer, you can use info / warning / error to display text.

$(error   text…)
$(warning text…)
$(info    text…)

To print variables,

$(error   VAR is $(VAR))
$(warning VAR is $(VAR))
$(info    VAR is $(VAR))

'error' would stop the make execution, after showing the error string

### 配置 VSCode 使用 OpenCV #### 软件准备 为了顺利配置 VSCode 和 OpenCV 的开发环境,需确认已安装适当版本的 Visual Studio Code、CMake 及编译器工具链(如 MinGW 或 MSVC)。对于 Windows 用户而言,在尝试集成之前应先通过官方渠道获取并安装最新版 OpenCV 库文件[^1]。 #### 创建项目结构 建立一个新的工作区来容纳 C++ 文件和其他必要的构建脚本。推荐的做法是在根目录下创建 `src` 文件夹用于放置源码,并设置 `.vscode` 文件夹保存特定于编辑器的配置项。 #### 安装扩展插件 利用 Extensions 功能面板搜索 "C/C++" 插件由 Microsoft 提供的支持 IntelliSense 特性的调试体验;另外建议启用 CMake Tools 扩展以便简化多平台项目的管理流程。 #### 设置 launch.json 与 tasks.json 针对不同操作系统定制化 JSON 文件中的参数选项,确保能够正确调用本地环境中存在的 g++ 编译程序以及链接至预设路径下的静态/动态库资源: ```json { "version": "0.2.0", "configurations": [ { "name": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/build/${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "/path/to/gdb", // Linux/MacOS or path to gdb on windows "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "cmake-build-debug" } ] } ``` ```json { "version": "2.0.0", "tasks": [ { "label": "cmake-build-debug", "command": "cmake", "args": [ "-DCMAKE_BUILD_TYPE=Debug", "-G", "MinGW Makefiles", // Or other generator like Ninja, Unix Makefiles etc. ".." ], "group": { "kind": "build", "isDefault": true }, "detail": "Generated task from CMakeLists.txt", "problemMatcher": ["$gcc"], "presentation": { "echo": true, "reveal": "always", "focus": false, "panel": "shared" } } ] } ``` #### 修改 CMakeLists.txt 编写简单的 CMake 构建描述文档以指导自动化处理依赖关系解析过程,同时指定目标可执行文件名称及其关联源代码位置: ```cmake cmake_minimum_required(VERSION 3.8) project(MyOpenCVProject VERSION 0.1 LANGUAGES CXX) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(OpenCV REQUIRED) add_executable(${PROJECT_NAME} src/main.cpp) target_link_libraries(${PROJECT_NAME} PRIVATE ${OpenCV_LIBS}) include_directories(${OpenCV_INCLUDE_DIRS}) ``` #### 测试验证 完成上述步骤之后即可运行一段基础测试案例检验整个链条是否通畅无阻。例如加载图像显示窗口功能片段如下所示: ```cpp #include <opencv2/core.hpp> #include <opencv2/highgui.hpp> int main() { cv::Mat image = cv::imread("example.jpg"); if (image.empty()) { std::cerr << "Could not open or find the image!" << std::endl; return -1; } cv::namedWindow("Display window", cv::WINDOW_AUTOSIZE); cv::imshow("Display window", image); cv::waitKey(0); // Wait indefinitely until a key is pressed. return 0; } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值