Vezel.Zig.Sdk            
            
        
    
        View 789         | 작성일2025.07.31 15:49        
    첨부파일
- 
                
                     zig.zip
                     (83.6K)
                
                DOWN : 0 zig.zip
                     (83.6K)
                
                DOWN : 0
관련링크
본문
https://docs.vezel.dev/zig-sdk/usage
- MyZig.zigproj
<Project Sdk="Vezel.Zig.Sdk">
  <PropertyGroup>
    <TargetFramework>net9.0TargetFramework>
    <OutputType>LibraryOutputType>
    <CompilerMode>zigCompilerMode>
  PropertyGroup>
Project>
- MyZig.zig
export fn add(a: i32, b: i32) i32 {
    return a + b;
}
 - MyCs.csproj
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>ExeOutputType>
    <TargetFramework>net9.0TargetFramework>
    <ImplicitUsings>enableImplicitUsings>
    <Nullable>enableNullable>
  PropertyGroup>
  <ItemGroup>
    <ProjectReference Include="../MyZig/MyZig.zigproj" />
  ItemGroup>
  <PropertyGroup>
    <RuntimeIdentifier Condition="'$(RuntimeIdentifier)' == ''">$(MSBuildRuntimeIdentifier)RuntimeIdentifier>
  PropertyGroup>
  <Target Name="CopyZigLib" AfterTargets="Build">
    <Copy SourceFiles="..\MyZig\bin\Debug\$(RuntimeIdentifier)\libMyZig.so"
        DestinationFolder="$(OutputPath)"
        Condition="Exists('..\MyZig\bin\Debug\$(RuntimeIdentifier)\libMyZig.so')" />
  Target>
Project>
- Program.cs
using System;
using System.Runtime.InteropServices;
class Program
{
    [DllImport("MyZig", CallingConvention = CallingConvention.Cdecl)]
    public static extern int add(int a, int b);
    static void Main()
    {
        Console.WriteLine($"3 + 5 = {add(3, 5)}");
    }
}


 
 
                 라이트모드
라이트모드 다크모드
다크모드