0
votes

I am currently trying to learn C++ and thought doing some OpenGL magic would be a nice idea. I saw a Premake5 tutorial and followed along, except I tried linking a library myself (GLFW). When generating the project files for Visual Studio 2017, the library I specified somehow does not get properly linked into the project. I get lots a lots of LINK errors in the likes of:

glfw3.lib(monitor.c.obj) : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "__imp__strdup" in Funktion "_glfwAllocMonitor".

glfw3.lib(win32_window.c.obj) : error LNK2001: Nicht aufgelöstes externes Symbol "__imp__strdup".

...

This is how my premake5.lua file looks like:

workspace "MojoEngine"
architecture "x64"

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

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

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

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

librarydir = "%{prj.name}/libraries/"

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

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

libdirs
{
    librarydir .. "GLFW/lib"
}

links
{
    "glfw3",
    "glfw3dll"
}

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

    defines
    {
        "ME_PLATFORM_WINDOWS",
        "ME_BUILD_DLL"
    }

    postbuildcommands
    {
        ("{COPY} %{cfg.buildtarget.relpath} ../bin/" .. outputdir .. 
    "/Sandbox"),
        ("{COPY} %{prj.name}/lib/GLFW/glfw3.dll ../bin/" .. outputdir .. 
    "/Sandbox")
    }

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

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

filter "configurations:Dist"
    defines "ME_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
{
    "MojoEngine/vendor/spdlog/include",
    "MojoEngine/src"
}

links
{
    "MojoEngine"
}

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

    defines
    {
        "ME_PLATFORM_WINDOWS",
    }

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

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

filter "configurations:Dist"
    defines "ME_DIST"
    optimize "On"
1

1 Answers

1
votes

Have a look at the glfw documentation. There it says you have to link some windows specific libraries for different compiler versions.

GLFW Documentation:

When linking a program under Windows that uses the static version of GLFW, you must link with opengl32. On some versions of MinGW, you must also explicitly link with gdi32, while other versions of MinGW include it in the set of default libraries along with other dependencies like user32 and kernel32. If you are using GLU, you must also link with glu32.

If you use MinGW you might need to link gdi32 to your "MojoEngine" project.

Note: You are linking dynamically, so you need to link opengl32. Sorry misread that.