Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 如何为源添加带有模式的_库?_Linux_Cmake - Fatal编程技术网

Linux 如何为源添加带有模式的_库?

Linux 如何为源添加带有模式的_库?,linux,cmake,Linux,Cmake,我想使用正则表达式将所有文件添加到添加库中,但它不起作用 我试过这个: add_library(8021qbg SHARED 8021QBG/"*.h" 8021QBG/"*.cpp" ) 得到这个: CMake Error at CMakeLists.txt:128 (add_library): Cannot find source file: 8021QBG/"*.h" Tried extensions .c .C .c+

我想使用正则表达式将所有文件添加到添加库中,但它不起作用

我试过这个:

add_library(8021qbg SHARED
        8021QBG/"*.h"
        8021QBG/"*.cpp"
        )
得到这个:

CMake Error at CMakeLists.txt:128 (add_library):
  Cannot find source file:

    8021QBG/"*.h"

  Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
  .hxx .in .txx
我试过这个:

file(GLOB 8021x
        8021x/"*.h"
        8021x/"*.cpp"
        )
add_library(8021x SHARED
        ${8021x}
        )
编译时,make命令看不到要编译的源代码

我想用一些东西来构建共享库,而不是写下每个源文件(我想是正则表达式)


如何操作?

您需要让cmake将所有匹配的文件列在一个变量中:

file(GLOB SOURCE_FILES
    8021QBG/*.h
    8021QBG/*.cpp
)
add_library(8021qbg SHARED
    ${SOURCE_FILES}
)
然后使用这个变量:

file(GLOB SOURCE_FILES
    8021QBG/*.h
    8021QBG/*.cpp
)
add_library(8021qbg SHARED
    ${SOURCE_FILES}
)
更多关于命令

生成与匹配的文件列表,并将其存储到。全局表达式与正则表达式类似,但更简单


您需要让cmake将所有匹配的文件列在一个变量中:

file(GLOB SOURCE_FILES
    8021QBG/*.h
    8021QBG/*.cpp
)
add_library(8021qbg SHARED
    ${SOURCE_FILES}
)
然后使用这个变量:

file(GLOB SOURCE_FILES
    8021QBG/*.h
    8021QBG/*.cpp
)
add_library(8021qbg SHARED
    ${SOURCE_FILES}
)
更多关于命令

生成与匹配的文件列表,并将其存储到。全局表达式与正则表达式类似,但更简单


通过以下添加,cmake能够确定要添加的库的名称,从而使脚本上下文不可知

# libname = current directory name
get_filename_component(libname "${CMAKE_CURRENT_SOURCE_DIR}" NAME)

# .c and .h files
file(GLOB thislibsrc ${CMAKE_CURRENT_SOURCE_DIR}/*.c ${CMAKE_CURRENT_SOURCE_DIR}/*.h)

# include it only once
include_guard(GLOBAL)

# and use it 
add_library(${libname} STATIC ${thislibsrc} )
...
我将这些小组件保存在某个中心目录中,以便稍后调用它们,如:

include(../addlibscr.cmake)

通过以下添加,cmake能够确定要添加的库的名称,从而使脚本上下文不可知

# libname = current directory name
get_filename_component(libname "${CMAKE_CURRENT_SOURCE_DIR}" NAME)

# .c and .h files
file(GLOB thislibsrc ${CMAKE_CURRENT_SOURCE_DIR}/*.c ${CMAKE_CURRENT_SOURCE_DIR}/*.h)

# include it only once
include_guard(GLOBAL)

# and use it 
add_library(${libname} STATIC ${thislibsrc} )
...
我将这些小组件保存在某个中心目录中,以便稍后调用它们,如:

include(../addlibscr.cmake)

只是在整个文件路径上加引号,而不仅仅是文件名?@AlanBirtles,不起作用,同样的错误可能与@AlanBirtles重复,我看到这篇文章,我不需要可执行文件,而是共享库。如果有什么方法可以通过add_executable命令来实现-如何实现?只需在整个文件路径上加引号,而不仅仅是文件名?@AlanBirtles,不工作,相同的错误可能与@AlanBirtles重复,我看到了这篇文章,我不需要可执行文件,而是共享库。如果有什么方法可以通过add_executable命令执行-如何执行?@YSC,非常感谢。这是我知道如何在主机上开发project并使用IDE功能远程构建它的一种方法。@YSC,非常感谢。这是我知道如何在主机上开发project并使用IDE功能远程构建它的一种方法。