gpt4 book ai didi

c# - add_library 在 CMake 中不能用于添加 CSharp 源文件?

转载 作者:行者123 更新时间:2023-11-30 22:13:44 27 4
gpt4 key购买 nike

我正在尝试从一组 .cs 文件构建 CSharp DLL。我使用 add_library() 函数添加源文件(.cs 文件)。但它发出警告,如“add_library for library libname without any source files”。请提供解决方案以使其正常工作。

提前致谢。

CMakeLists.txt 是:

cmake_minimum_required(VERSION 2.8)

project(MyAddIn)

AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/MyAdd-In/ MyAddIn_SOURCES)


SET_SOURCE_FILES_PROPERTIES(${MyAddIn_SOURCES} PROPERTIES LANGUAGE CSharp)

ADD_LIBRARY(AddInTrg SHARED ${MyAddIn_SOURCES})

SET_TARGET_PROPERTIES(AddInTrg PROPERTIES
LINKER_LANGUAGE CSharp
RUNTIME_OUTPUT_DIRECTORY bin
RUNTIME_OUTPUT_DIRECTORY_DEBUG bin
RUNTIME_OUTPUT_NAME MyAddIn_Bin
ARCHIVE_OUTPUT_DIRECTORY lib
ARCHIVE_OUTPUT_DIRECTORY_DEBUG lib
OUTPUT_NAME MyAddIn_Bin)

add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/bin/MyAddIn_Bin.dll
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/MyAdd-In
COMMAND C:/WINDOWS/Microsoft.NET/Framework/v3.5/csc.exe
ARGS
-target:library
-out ${CMAKE_CURRENT_BINARY_DIR}/bin/MyAddIn_Bin.dll
"${CMAKE_CURRENT_SOURCE_DIR}/MyAdd-In/Ribbon.cs" "${CMAKE_CURRENT_SOURCE_DIR}/MyAdd-In/ThisAddIn.cs" "${CMAKE_CURRENT_SOURCE_DIR}/MyAdd-In/Ribbon.xml"
COMMENT "-- Generating AddIn Dll")

最佳答案

截至CMake 3.8 , CMake 现在完全支持 C# 作为一种语言。您现在应该能够使用如下内容创建 C# 程序集目标 (DLL):

# Define the DLL target, including all relevant project files.
add_library(AddInTrg SHARED ${MyAddIn_SOURCES})

# Set the .NET Framework version for the target.
set_property(TARGET AddInTrg PROPERTY VS_DOTNET_TARGET_FRAMEWORK_VERSION "v4.6.1")
# Set the C# language version (defaults to 3.0 if not set).
set(CMAKE_CSharp_FLAGS "/langversion:6")
# Add in some .NET reference libraries.
set_property(TARGET AddInTrg PROPERTY VS_DOTNET_REFERENCES
"Microsoft.CSharp"
"System"
"System.Core"
"System.Data"
"System.Deployment"
"System.Drawing"
"System.Net.Http"
"System.Xml"
)

您还可以使用 CMake 指定 .NET 和 C# 版本,并引入任何必需的 .NET 引用。

注意:此支持仅包含 Visual Studio 2010 及更高版本。

关于c# - add_library 在 CMake 中不能用于添加 CSharp 源文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18888266/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com