将 lua 嵌入到 c++ 中,但得到未解析的外部问题:floor、freopen 和 strcoll

Embedding lua into c++ but getting unresolved externals : floor, freopen & strcoll

提问人:Martian 提问时间:8/26/2020 最后编辑:JabberwockyMartian 更新时间:8/26/2020 访问量:304

问:

我正在将 lua 嵌入到 c++ vs2019 解决方案中,它会导致链接到基本 c 库的错误 ( 和 )。__imp_freopen__imp_floor__imp_strcoll

lua 在它自己的项目中编译为静态 C 库并链接到主项目,但是在使用时,我得到了 、 和 的未解析外部符号。luaL_newstate();freopen(...)floor(...)strcmp(...)

我最好的猜测是这个错误来自我的构建系统(premake5),因为当我使用 vs2019 手动添加项目时,没有链接错误,但由于我经常跨操作系统处理这个项目,因此没有正确地进行预制工作会带来很多问题。 我将不胜感激关于如何缩小问题范围的任何想法。

Lua 的预制件:

project "lua"
    kind "StaticLib"
    language "C"

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

    files
    {
        "src/**.c",
        "src/**.h",
        "src/lua.hpp"
    }

    excludes
    {
        "src/lua.c",
        "src/luac.c"
    }

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

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

解决方案的相关预制件:

workspace "solution"
    architecture "x86_64"
    startproject "test"

    configurations
    {
        "Debug",
        "Release"
    }
    
    flags
    {
        "MultiProcessorCompile"
    }

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

IncludeDir = {}
IncludeDir["GLFW"] = "engine/vendor/GLFW/include"
IncludeDir["Glad"] = "engine/vendor/Glad/include"
IncludeDir["ImGui"] = "engine/vendor/imgui"
IncludeDir["glm"] = "engine/vendor/glm"
IncludeDir["stb_image"] = "engine/vendor/stb_image"
IncludeDir["lua"] = "engine/vendor/lua"

group "dependencies"
    include "engine/vendor/GLFW"
    include "engine/vendor/Glad"
    include "engine/vendor/imgui"
    include "engine/vendor/lua"

group ""

project "engine"
    location "engine"
    kind "StaticLib"
    language "C++"
    cppdialect "C++17"
    staticruntime "on"

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

    pchheader "pch.h"
    pchsource "engine/src/pch.cpp"

    files
    {
        "%{prj.name}/src/**.h",
        "%{prj.name}/src/**.cpp",
        "%{prj.name}/vendor/stb_image/**.h",
        "%{prj.name}/vendor/stb_image/**.cpp",
        "%{prj.name}/vendor/glm/glm/**.hpp",
        "%{prj.name}/vendor/glm/glm/**.inl"
    }

    defines
    {
        "_CRT_SECURE_NO_WARNINGS",
        "GLFW_INCLUDE_NONE"
    }

    includedirs
    {
        "%{prj.name}/src",
        "%{prj.name}/vendor/spdlog/include",
        "%{IncludeDir.GLFW}",
        "%{IncludeDir.Glad}",
        "%{IncludeDir.ImGui}",
        "%{IncludeDir.glm}",
        "%{IncludeDir.stb_image}",
        "%{IncludeDir.lua}"
    }

    links
    {
        "GLFW",
        "Glad",
        "ImGui",
        "opengl32.lib",
        "lua"
    }


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

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


project "test"
    location "test"
    kind "ConsoleApp"
    language "C++"
    cppdialect "C++17"
    staticruntime "on"

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

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

    includedirs
    {
        "engine/vendor/spdlog/include",
        "engine/src",
        "engine/vendor",
        "%{IncludeDir.GLFW}",
        "%{IncludeDir.Glad}",
        "%{IncludeDir.ImGui}",
        "%{IncludeDir.glm}"
    }

    links
    {
        "engine"
    }
        
    filter "configurations:Debug"
        runtime "Debug"
        symbols "on"

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

lua.hpp 仅lua_script.cpp包含在class lua_script {...};

C++ Lua 未解析的外部 预制

评论

3赞 Alan Birtles 8/26/2020
可能是 lua 和主项目之间的运行时库的混合
1赞 Egor Skriptunoff 8/27/2020
将 Lua(适用于 Windows)构建为动态库而不是静态库不太容易出错。
0赞 Martian 8/28/2020
好的,所以我的临时解决方案是将所有 lua 文件直接包含在引擎项目中,但这并不理想,因为 lua 确实应该是它自己的项目

答: 暂无答案