[英]Trouble understanding this CMakeLists.txt file
I'm absolutely new to C++/CMake and from all the tutorials I've read, there should be an add_executable()
line in the top-level CMakeLists.txt file.我对 C++/CMake 完全陌生,从我读过的所有教程中,顶级 CMakeLists.txt 文件中应该有一个
add_executable()
行。 However, in this project that I'm working on, there isn't one:但是,在我正在进行的这个项目中,没有一个:
cmake_minimum_required (VERSION 2.8.11)
set(CMAKE_CXX_STANDARD 17)
set(VERSION dev)
find_package(PkgConfig REQUIRED)
include_directories(SYSTEM $ENV{HOME}/usr/local/include)
project(engine)
add_subdirectory(common)
add_subdirectory(matching)
add_subdirectory(matching_test)
add_subdirectory(matching_tcp_client)
add_subdirectory(matching_tcp_service)
add_subdirectory(md_tcp_service)
add_subdirectory(matching_zmq_service)
add_subdirectory(net)
add_subdirectory(proxy_ws)
add_subdirectory(proxy_md_ws)
add_subdirectory(zmq_proxy)
add_subdirectory(test_tcp_matching_client)
add_subdirectory(test_tcp_matching_server)
add_subdirectory(test_md_tcp_server)
add_subdirectory(test_zmq_matching_server)
add_subdirectory(xpubxsub)
add_subdirectory(md)
A few questions I have:我有几个问题:
main()
function in the entire project but can't seem to find it.main()
function 但似乎找不到。there should be an add_executable() line in the top-level CMakeLists.txt file
顶层 CMakeLists.txt 文件中应该有一个 add_executable() 行
This is a wrong assumption.这是一个错误的假设。
add_executable
is not mandatory at all. add_executable
根本不是强制性的。 For example, a project that produces only library will have add_library
and no add_executable
.例如,仅生成库的项目将具有
add_library
并且没有add_executable
。 Moreover this function could be in a subdirectory, there is no need to put it in the top level CMakeLists.txt
.此外,这个 function 可以在子目录中,不需要放在顶层
CMakeLists.txt
中。
In your example, there are lost of add_subdirectory
with a folder name as argument.在您的示例中,以文件夹名称作为参数的
add_subdirectory
丢失了。 Those folder should contain a CMakeLists.txt
file.这些文件夹应该包含一个
CMakeLists.txt
文件。 You should look at them for a add_executable
command.您应该查看它们以获取
add_executable
命令。 There might be several: one project could produce several executable.可能有几个:一个项目可以产生多个可执行文件。 A common use case is a project that produce one main executable and several test executables.
一个常见的用例是一个生成一个主要可执行文件和几个测试可执行文件的项目。
Only executable needs to have a main()
function and only one.只有可执行文件需要有一个
main()
function 并且只有一个。 If your project doesn't produce any executable, then there is no need to define a main()
function.如果您的项目不产生任何可执行文件,则无需定义
main()
function。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.