You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为现有C项目创建Visual Studio解决方案文件

为SM64反编译项目创建Visual Studio 2022解决方案

方法1:创建空Visual C++项目关联现有Makefile

这是适配现有Makefile最省心的方式,无需重构项目结构:

  • 打开Visual Studio 2022,选择「创建新项目」,搜索空项目(属于Visual C++分类),命名项目(如sm64),可将项目文件直接放在SM64源码根目录。
  • 右键项目(非解决方案)进入「属性」,在「配置属性」→「常规」中,将「平台工具集」设为对应版本(如v143),「C语言标准」选择C99或更高(SM64依赖C99特性)。
  • 切换到「配置属性」→「生成事件」→「预生成事件」,在「命令行」中填入Makefile构建指令,比如make -j4(-j4为多核编译参数,可根据CPU核心数调整);若需清理,可在「生成后事件」或单独配置清理命令。
  • 右键解决方案选择「添加」→「现有项」,将SM64源码目录下的.c、.h、Makefile等文件按原文件夹结构添加到项目,方便浏览管理。
  • 保存解决方案后,点击VS的「生成」按钮即可触发Makefile编译,也可在项目属性中修改编译参数(如指定make VERSION=us构建美版ROM)。

方法2:手动编写MSBuild项目文件(让VS完全接管构建)

若想摆脱Makefile依赖,让VS原生管理构建流程,可手动创建.vcxproj文件:

  • 在SM64源码根目录新建sm64.vcxproj文件,参考以下模板(需根据实际源码路径、编译需求调整):
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Debug|x64">
      <Configuration>Debug</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|x64">
      <Configuration>Release</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <PropertyGroup Label="Globals">
    <VCProjectVersion>16.0</VCProjectVersion>
    <ProjectGuid>{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}</ProjectGuid> <!-- 替换为自定义GUID,可通过VS「工具→创建GUID」生成 -->
    <RootNamespace>sm64</RootNamespace>
    <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v143</PlatformToolset>
    <CStandard>c99</CStandard>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v143</PlatformToolset>
    <CStandard>c99</CStandard>
    <WholeProgramOptimization>true</WholeProgramOptimization>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <IncludePath>$(ProjectDir);$(ProjectDir)\include;$(VCIncludePath);$(WindowsSDK_IncludePath)</IncludePath>
    <LibraryPath>$(ProjectDir)\lib;$(VCLibraryPath);$(WindowsSDK_LibraryPath_x64)</LibraryPath>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <IncludePath>$(ProjectDir);$(ProjectDir)\include;$(VCIncludePath);$(WindowsSDK_IncludePath)</IncludePath>
    <LibraryPath>$(ProjectDir)\lib;$(VCLibraryPath);$(WindowsSDK_LibraryPath_x64)</LibraryPath>
  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>Disabled</Optimization>
      <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <AdditionalOptions>-ffreestanding -march=mips64r2 -mabi=64 %(AdditionalOptions)</AdditionalOptions> <!-- 适配N64交叉编译选项 -->
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <AdditionalDependencies>libsm64.a;%(AdditionalDependencies)</AdditionalDependencies>
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>MaxSpeed</Optimization>
      <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <AdditionalOptions>-ffreestanding -march=mips64r2 -mabi=64 %(AdditionalOptions)</AdditionalOptions>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <AdditionalDependencies>libsm64.a;%(AdditionalDependencies)</AdditionalDependencies>
    </Link>
  </ItemDefinitionGroup>
  <ItemGroup>
    <ClCompile Include="src\**\*.c" /> <!-- 匹配所有源码目录下的C文件 -->
  </ItemGroup>
  <ItemGroup>
    <ClInclude Include="include\**\*.h" /> <!-- 匹配所有头文件 -->
  </ItemGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ImportGroup Label="ExtensionTargets">
  </ImportGroup>
</Project>
  • 生成自定义GUID:打开VS「工具→创建GUID」,选择「注册表格式」,复制去掉大括号的字符串替换模板中的{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}。
  • 在VS中选择「打开项目/解决方案」,选中新建的.vcxproj文件,VS会自动生成对应的.sln解决方案文件。
  • 进入项目属性,根据SM64的交叉编译需求,指定N64工具链的路径(可在「VC++目录→可执行文件目录」添加工具链路径),并调整编译、链接选项。

关键注意事项

  • SM64依赖N64交叉编译工具链,需确保VS环境能访问mips64-elf-gcc等工具,可通过系统PATH或项目属性配置路径。
  • 方法1的代码提示、调试功能可能受限,需手动配置包含目录;方法2能实现VS原生支持,但需同步Makefile中的编译选项和源码文件,维护成本较高。

内容的提问来源于stack exchange,提问作者Stevoisiak

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 13:43:12