I'm embedding lua into a c++ vs2019 solution and it results in linking errors to basic c libraries
( __imp_freopen
, __imp_floor
and __imp_strcoll
).
lua compiles as a static c library in it's own project and is linked to the main project, but when using luaL_newstate();
I get unresolved external symbols for freopen(...)
, floor(...)
and strcmp(...)
.
My best guess is that this error comes from my build system (premake5) as when I manually add the project using vs2019 there are no linking errors but since I frequently work on this project across operating systems, not having premake work properly presents many problems. I'd appreciate any ideas on how to narrow down the problem.
premake for 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"
relevant premake for solution :
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 is only included in the lua_script.cpp of class lua_script {...};