Flutter windows:我可以使用相对路径在 CMakeLists.txt 中捆绑 `.dll` 库吗?
Flutter windows: can I use relative path to bundle `.dll` library in CMakeLists.txt?
我正在构建一个 flutter 插件,它从 lib.dll
文件调用本机函数,并且在我的计算机中一切正常。
但我使用 link 的相对路径 lib
例如
E:/_Projects/mahesabu/client/packages/server/windows/lib.dll
现在我想在 CI/CD 中移动构建过程,我相信使用相对路径,例如
./lib.dll
会很容易。
当然我是 cmake 配置的新手。在一条评论中写着
List of absolute paths to libraries that should be bundled with the plugin
我想知道如何在那里使用相对路径,因为如果我尝试构建失败。以下为CMakeLists.txt
cmake_minimum_required(VERSION 3.14)
set(PROJECT_NAME "server")
project(${PROJECT_NAME} LANGUAGES CXX)
# This value is used when generating builds using this plugin, so it must
# not be changed
set(PLUGIN_NAME "server_plugin")
add_library(${PLUGIN_NAME} SHARED
"server_plugin.cpp"
)
apply_standard_settings(${PLUGIN_NAME})
set_target_properties(${PLUGIN_NAME} PROPERTIES
CXX_VISIBILITY_PRESET hidden)
target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)
target_include_directories(${PLUGIN_NAME} INTERFACE
"${CMAKE_CURRENT_SOURCE_DIR}/include")
target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin)
# List of absolute paths to libraries that should be bundled with the plugin
set(server_bundled_libraries
""
"E:/_Projects/mahesabu/client/packages/server/windows/lib.dll" #USE RELATIVE PATH HERE
PARENT_SCOPE
)
我们将不胜感激。
只需使用:
set(server_bundled_libraries "${CMAKE_CURRENT_SOURCE_DIR}/lib.dll" PARENT_SCOPE)
CMAKE_CURRENT_SOURCE_DIR
变量将扩展到 add_subdirectory
跟踪的当前源目录。这通常是当前 CMakeLists.txt
所在的目录,但并非总是如此。据推测,这是 E:/_Projects/mahesabu/client/packages/server/windows
在您的计算机上(根据您的评论,您希望 ./lib.dll
可以工作),但会在 CI 或其他地方。
我正在构建一个 flutter 插件,它从 lib.dll
文件调用本机函数,并且在我的计算机中一切正常。
但我使用 link 的相对路径 lib
例如
E:/_Projects/mahesabu/client/packages/server/windows/lib.dll
现在我想在 CI/CD 中移动构建过程,我相信使用相对路径,例如
./lib.dll
会很容易。
当然我是 cmake 配置的新手。在一条评论中写着
List of absolute paths to libraries that should be bundled with the plugin
我想知道如何在那里使用相对路径,因为如果我尝试构建失败。以下为CMakeLists.txt
cmake_minimum_required(VERSION 3.14)
set(PROJECT_NAME "server")
project(${PROJECT_NAME} LANGUAGES CXX)
# This value is used when generating builds using this plugin, so it must
# not be changed
set(PLUGIN_NAME "server_plugin")
add_library(${PLUGIN_NAME} SHARED
"server_plugin.cpp"
)
apply_standard_settings(${PLUGIN_NAME})
set_target_properties(${PLUGIN_NAME} PROPERTIES
CXX_VISIBILITY_PRESET hidden)
target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)
target_include_directories(${PLUGIN_NAME} INTERFACE
"${CMAKE_CURRENT_SOURCE_DIR}/include")
target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin)
# List of absolute paths to libraries that should be bundled with the plugin
set(server_bundled_libraries
""
"E:/_Projects/mahesabu/client/packages/server/windows/lib.dll" #USE RELATIVE PATH HERE
PARENT_SCOPE
)
我们将不胜感激。
只需使用:
set(server_bundled_libraries "${CMAKE_CURRENT_SOURCE_DIR}/lib.dll" PARENT_SCOPE)
CMAKE_CURRENT_SOURCE_DIR
变量将扩展到 add_subdirectory
跟踪的当前源目录。这通常是当前 CMakeLists.txt
所在的目录,但并非总是如此。据推测,这是 E:/_Projects/mahesabu/client/packages/server/windows
在您的计算机上(根据您的评论,您希望 ./lib.dll
可以工作),但会在 CI 或其他地方。