测试程序没有运行

时间:2021-01-17 08:19:40

标签: c++ dll game-engine

我一直在创建游戏引擎。当我测试代码时,我收到以下错误: enter image description here

应用程序.cpp

namespace SkyEngine {
    __declspec(dllimport)void Print();
}

void main() {
    SkyEngine::Print();
}

测试.cpp

#include "Test.h"
#include<stdio.h>
namespace SkyEngine {

    void Print() {
        printf("Welcome to the Sky Engine!");
    }
}

测试.h

#pragma once

namespace SkyEngine {
    __declspec(dllexport)void Print();
}

enter image description here

文件的位置附在下面。:

enter image description here

enter image description here

enter image description here

这里是引擎的解决方案文件。

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30907.101
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Sandbox", "Sandbox\Sandbox\Sandbox.vcxproj", "{891DE6BF-51D7-4567-AC16-1DB5D2031CBE}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SkyEngine", "SkyEngine\SkyEngine.vcxproj", "{3B9FCA09-C542-4F44-8107-823A690EF0D6}"
EndProject
Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|x64 = Debug|x64
        Release|x64 = Release|x64
    EndGlobalSection
    GlobalSection(ProjectConfigurationPlatforms) = postSolution
        {3B9FCA09-C542-4F44-8107-823A690EF0D6}.Debug|x64.ActiveCfg = Debug|x64
        {3B9FCA09-C542-4F44-8107-823A690EF0D6}.Debug|x64.Build.0 = Debug|x64
        {3B9FCA09-C542-4F44-8107-823A690EF0D6}.Release|x64.ActiveCfg = Release|x64
        {3B9FCA09-C542-4F44-8107-823A690EF0D6}.Release|x64.Build.0 = Release|x64
        {891DE6BF-51D7-4567-AC16-1DB5D2031CBE}.Debug|x64.ActiveCfg = Debug|x64
        {891DE6BF-51D7-4567-AC16-1DB5D2031CBE}.Debug|x64.Build.0 = Debug|x64
        {891DE6BF-51D7-4567-AC16-1DB5D2031CBE}.Release|x64.ActiveCfg = Release|x64
        {891DE6BF-51D7-4567-AC16-1DB5D2031CBE}.Release|x64.Build.0 = Release|x64
    EndGlobalSection
    GlobalSection(SolutionProperties) = preSolution
        HideSolutionNode = FALSE
    EndGlobalSection
    GlobalSection(ExtensibilityGlobals) = postSolution
        SolutionGuid = {239872E8-05BB-4D0E-A724-11648DD172D0}
    EndGlobalSection
EndGlobal

1 个答案:

答案 0 :(得分:0)

在我看来,您的构建设置不正确。

  1. 如我所见,您的入口点位于“SkyEngine”项目中,但它是作为 dll 构建的。
  2. 据我所知,项目“Sandbox”依赖于“SkyEngine.dll”文件,但包含导出。我猜它是您的解决方案中的可执行文件。
  3. 由于您没有提供“构建”步骤的日志,我不能 100% 确定“SkyEngine”是否在“Sandbox”之前编译。

我是怎么得出这个结论的?
“错误”选项卡中的“项目”列显示了引发该错误的项目。第二行显示了要编译到的文件(即“SkyEngine.dll”)。

造成这种情况的主要原因是在链接器可以解析依赖项以链接它之前没有编译导出函数。所以我想你需要做的是,考虑到你正在构建一个游戏引擎,

  1. 获取导出函数并将其移至“SkyEngine”(我猜是引擎)。
  2. 获取入口点(位于“Application.cpp”文件中)并将其移动到“沙箱”(我猜是使用引擎的应用程序/可执行文件)。

如果我的假设是正确的,这应该可以解决问题。

相关问题