0

I am having some issues linking GLFW to my project. I have spent about 3 1/2 Hours trying to find out what I have done wrong. It is a compile time error, so I cannot find out which functions are causing the issues. Here is my error log

2>GLFW.lib(window.obj) : error LNK2019: unresolved external symbol __imp_strncpy referenced in function glfwWindowHintString
2>GLFW.lib(input.obj) : error LNK2001: unresolved external symbol __imp_strncpy
2>GLFW.lib(win32_joystick.obj) : error LNK2001: unresolved external symbol __imp_strncpy
2>GLFW.lib(osmesa_context.obj) : error LNK2001: unresolved external symbol __imp__wassert
2>GLFW.lib(monitor.obj) : error LNK2001: unresolved external symbol __imp__wassert
2>GLFW.lib(vulkan.obj) : error LNK2001: unresolved external symbol __imp__wassert
2>GLFW.lib(wgl_context.obj) : error LNK2001: unresolved external symbol __imp__wassert
2>GLFW.lib(egl_context.obj) : error LNK2001: unresolved external symbol __imp__wassert
2>GLFW.lib(window.obj) : error LNK2001: unresolved external symbol __imp__wassert
2>GLFW.lib(context.obj) : error LNK2001: unresolved external symbol __imp__wassert
2>GLFW.lib(input.obj) : error LNK2001: unresolved external symbol __imp__wassert
2>GLFW.lib(win32_thread.obj) : error LNK2001: unresolved external symbol __imp__wassert
2>GLFW.lib(context.obj) : error LNK2019: unresolved external symbol __imp___stdio_common_vsscanf referenced in function sscanf
2>GLFW.lib(input.obj) : error LNK2019: unresolved external symbol __imp_strspn referenced in function glfwUpdateGamepadMappings

I am using premake, and Have a script for the engine/sandbox and another one for GLFW. Here is the main premake script

workspace "Gluten"
    architecture "x64"

    configurations
    {
        "Debug",
        "Release",
        "Dist"
    }

outputdir = "%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}"

IncludeDir = {}
IncludeDir["GLFW"] = "Gluten/vendor/GLFW/include"

include "Gluten/vendor/GLFW"

project "Gluten"
    location "Gluten"
    kind "SharedLib"
    language "C++"

    targetdir ("bin/" .. outputdir .. "/%{prj.name}")
    objdir ("bin-int/" .. outputdir .. "/%{prj.name}")

    pchheader "glutpch.h"
    pchsource "Gluten/src/glutpch.cpp"

    files
    {
        "%{prj.name}/src/**.h",
        "%{prj.name}/src/**.cpp"
    }

    includedirs
    {
        "%{prj.name}/src",
        "%{prj.name}/vendor/spdlog/include",
        "%{IncludeDir.GLFW}"
    }

    links 
    { 
        "GLFW",
        "opengl32.lib"
    }

    filter "system:windows"
        cppdialect "C++17"
        staticruntime "On"
        systemversion "latest"

        defines
        {
            "GLUT_PLATFORM_WINDOWS",
            "GLUT_BUILD_DLL"
        }

        postbuildcommands
        {
            ("{COPY} %{cfg.buildtarget.relpath} ../bin/" .. outputdir .. "/Sandbox")
        }

    filter "configurations:Debug"
        defines "GLUT_DEBUG"
        symbols "On"

    filter "configurations:Release"
        defines "GLUT_RELEASE"
        optimize "On"

    filter "configurations:Dist"
        defines "GLUT_DIST"
        optimize "On"

project "Sandbox"
    location "Sandbox"
    kind "ConsoleApp"
    language "C++"

    targetdir ("bin/" .. outputdir .. "/%{prj.name}")
    objdir ("bin-int/" .. outputdir .. "/%{prj.name}")

    files
    {
        "%{prj.name}/src/**.h",
        "%{prj.name}/src/**.cpp"
    }

    includedirs
    {
        "Gluten/vendor/spdlog/include",
        "Gluten/src"
    }

    links
    {
        "Gluten"
    }

    filter "system:windows"
        cppdialect "C++17"
        staticruntime "On"
        systemversion "latest"

        defines
        {
            "GLUT_PLATFORM_WINDOWS"
        }

    filter "configurations:Debug"
        defines "GLUT_DEBUG"
        symbols "On"

    filter "configurations:Release"
        defines "GLUT_RELEASE"
        optimize "On"

    filter "configurations:Dist"
        defines "GLUT_DIST"
        optimize "On"

And here is the script for glfw

project "GLFW"
    kind "StaticLib"
    language "C"

    targetdir ("bin/" .. outputdir .. "/%{prj.name}")
    objdir ("bin-int/" .. outputdir .. "/%{prj.name}")

    files
    {
        "include/GLFW/glfw3.h",
        "include/GLFW/glfw3native.h",
        "src/glfw_config.h",
        "src/context.c",
        "src/init.c",
        "src/input.c",
        "src/monitor.c",
        "src/vulkan.c",
        "src/window.c"
    }
    filter "system:linux"
        pic "On"

        systemversion "latest"
        
        files
        {
            "src/x11_init.c",
            "src/x11_monitor.c",
            "src/x11_window.c",
            "src/xkb_unicode.c",
            "src/posix_time.c",
            "src/posix_thread.c",
            "src/glx_context.c",
            "src/egl_context.c",
            "src/osmesa_context.c",
            "src/linux_joystick.c"
        }

        defines
        {
            "_GLFW_X11"
        }

    filter "system:windows"
        systemversion "latest"

        files
        {
            "src/win32_init.c",
            "src/win32_joystick.c",
            "src/win32_monitor.c",
            "src/win32_time.c",
            "src/win32_thread.c",
            "src/win32_window.c",
            "src/wgl_context.c",
            "src/egl_context.c",
            "src/osmesa_context.c"
        }

        defines 
        { 
            "_GLFW_WIN32",
            "_CRT_SECURE_NO_WARNINGS"
        }

        links
        {
            "Dwmapi.lib"
        }

    filter "configurations:Debug"
        runtime "Debug"
        symbols "on"

    filter "configurations:Release"
        runtime "Release"
        optimize "on"

The only code that I have to implement GLFW into the engine is a few lines of code


        if (!s_GLFWInitialized)
        {
            // TODO: Error Checking
            int success = glfwInit();

            s_GLFWInitialized = true;
        }

        m_Window = glfwCreateWindow((int)props.Width, (int)props.Height, m_Data.Title.c_str(), nullptr, nullptr);
        glfwMakeContextCurrent(m_Window);
        glfwSetWindowUserPointer(m_Window, &m_Data);
        SetVSync(true);

Thank you, any help is very much appreciated

DevStuffz
  • 19
  • 9
  • *>GLFW.lib(window.obj) : error LNK2019: unresolved external symbol __imp_strncpy...* -- This is telling you that `strncpy`, a regular C library function, cannot be found by the linker. The `__imp` implies it is an import library that your build settings is not including. It is not a compiler error, it is a linker error. Also, you probably don't even need GLFW to see the problem. A simple `Hello World` program that calls `strncpy` would also probably have the same issue. – PaulMcKenzie Nov 29 '21 at 20:47
  • @PaulMcKenzie I see, how would I be able to fix this? What Library would I need to include that is not already being included? – DevStuffz Nov 29 '21 at 20:52
  • I am not sure. I just let you know what the error is and what it means. You need to take a step back, create a simple Hello World program, and try to get that to build. `#include #include int main() { char s[] = "abc"; char s2[] = "123"; strncpy(s, s2, 3); }` -- something simple like that. – PaulMcKenzie Nov 29 '21 at 20:57
  • 1
    @DevStuffz You don't need to `#include`, you need to **link** the appropriate runtime library. Are you using Microsoft Visual Studio? Then look under _C/C++ → Code Generation → Runtime Library_ and make sure the correct type (Release vs Debug) is specified there. – heap underrun Nov 29 '21 at 21:02
  • @heapunderrun that fixed it, if you want to put it as an answer I will mark it correct. Thank you for your help! – DevStuffz Nov 29 '21 at 21:06

0 Answers0