Search code examples
c++dllgame-engine

Test Programs are not running


I've been creating a game engine. When I was testing the code I was receiving following errors: enter image description here

Application.cpp

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

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

Test.cpp

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

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

Test.h

#pragma once

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

enter image description here

The location of the files are attached below.:

enter image description here

enter image description here

enter image description here

Here is the solution file of the engine.

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

Solution

  • It looks to me like you have set up the build incorrectly.

    1. As I could see, your entry point is in the project "SkyEngine" but its built as a dll.
    2. Project "Sandbox" as I guess, depends on the "SkyEngine.dll" file but contains the exports. I guess its the executable file in your solution.
    3. Since you have not provided a log of the "Build" step, I cant be 100% sure if "SkyEngine" is compiled before "Sandbox".

    How did I come to this conclusion?
    The "project" column in the "Error" tab shows you what project throwed that error. And the second row showed what file it was meant to be compiled to (which was "SkyEngine.dll").

    The main reason for this is that the exporting functions are not compiled before the linker could resolve the dependencies to link it. So I guess what you need to do is, and considering that your building a game engine,

    1. Take the export functions and move it to "SkyEngine" (which I guess is the engine).
    2. Take the entry point (which is in the "Application.cpp" file) and move it to "Sandbox" (which I guess is the application/ executable which uses the engine).

    This should resolve the issue if my hypothesis is correct.