gpt4 book ai didi

c++ - 预制链接链接到 SharedLib 不起作用

转载 作者:行者123 更新时间:2023-12-03 12:47:20 28 4
gpt4 key购买 nike

我目前正在尝试学习 C++,并认为做一些 OpenGL 魔法是一个好主意。我看到了 Premake5 教程并继续进行,除了我尝试自己链接一个库(GLFW)。为 Visual Studio 2017 生成项目文件时,我指定的库以某种方式无法正确链接到项目中。我收到很多链接错误,例如:

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".

...

这就是我的 premake5.lua 文件的样子:

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"

最佳答案

查看 glfw 文档。那里说你必须为不同的编译器版本链接一些特定于 Windows 的库。

GLFW Documentation:

When linking a program under Windows that uses the static version ofGLFW, you must link with opengl32. On some versions of MinGW, you mustalso explicitly link with gdi32, while other versions of MinGW includeit in the set of default libraries along with other dependencies likeuser32 and kernel32. If you are using GLU, you must also link withglu32.

如果您使用 MinGW,您可能需要将 gdi32 链接到您的“MojoEngine”项目。

注意:您正在动态链接,因此需要链接 opengl32。抱歉看错了。

关于c++ - 预制链接链接到 SharedLib 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55387519/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com