I have a workspace inside which there are two projects "Physx2D" and "SandBox". First one is built to a shared library and second into a console app. SandBox requires the Physx2D library and is set as start project.
I am using glfw3 library and glad for opengl functions.
The problem is that the project builds and runs successfully on windows but fails in linux. Going into more detail, the Physx2D library builds successfully. Issue came after compilation of SandBox. It fails to link and throws a warning and multiple link errors, all of them stating "undefined reference to "glad_******" in functions inside Physx2D library. e.g.
warning:
/usr/bin/ld: ../bin-int/Debug-linux-x86_64/SandBox/main.o warning: relocation against 'glad_glClearColor' in read-only section '.text._ZN7Physx2D6Window10FillScreenENS_5vec4IfEE[_ZN7Physx2D6Window10FillScreenENS_5tvec4IfEE]'
errors:
/usr/bin/ld: ../bin-int/Debug-linux-x86_64/SandBox/CA_gpu.o : in function 'Physx2D::Shader::use()':
..project_directory_of_sandbox ../Physx2D/src/renderer/shader.h:24: undefined reference to 'glad_glUseProgram'
multiple errors following same pattern are thrown in during linking.
I am using premake to generate project makefiles for gmake2.
Here is my premake script.
workspace "Physx2D"
architecture "x64"
configurations {Debug","Release"}
outputdir = "%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}"
project "Physx2D"
location "Physx2D/"
kind "SharedLib"
language "C++"
cppdialect "C++20"
staticruntime "off"
targetdir ("bin/" .. outputdir .. "/%{prj.name}")
objdir ("bin-int/" .. outputdir .. "/%{prj.name}")
pchheader "pch.h"
pchsource "%{prj.name}/src/pch.cpp"
files {
"%{prj.name}/libraries/**.*",
"%{prj.name}/src/**.*"
}
includedirs {
"%{prj.name}/libraries/include",
"%{prj.name}/src"
}
libdirs {"%{prj.name}/libraries/lib_%{cfg.system}"}
filter "system:windows"
systemversion "latest"
links {"glfw3", "opengl32"}
postbuildcommands {"{COPY} %{cfg.buildtarget.relpath} ../bin/" .. outputdir .. "/SandBox"}
defines {"PHSX2D_BUILD_DLL","PHSX2D_PLATFORM_WINDOWS"}
filter "system:linux"
systemversion "latest"
buildoptions { "-fvisibility=hidden"}
links {"glfw3", "GL"}
postbuildcommands {"{COPY} %{cfg.buildtarget.relpath} ../bin/" .. outputdir .. "/SandBox"}
defines { "PHSX2D_BUILD_DLL", "PHSX2D_PLATFORM_LINUX"}
filter "configurations:Debug"
defines {"PHSX2D_DEBUG", "PHSX2D_ASSERT_ENABLE"}
symbols "on"
filter "configurations:Release"
defines {"PHSX2D_RELEASE", "PHSX2D_ASSERT_ENABLE"}
optimize "on"
filter "files:**/libraries/src/**.*"
flags { "NoPCH" }
project "SandBox"
location "SandBox"
kind "ConsoleApp"
language "C++"
cppdialect "C++20"
staticruntime "off"
targetdir ("bin/" .. outputdir .. "/%{prj.name}")
objdir ("bin-int/" .. outputdir .. "/%{prj.name}")
files {
"%{prj.name}/src/**.*",
"%{prj.name}/res/**.*",
"%{prj.name}/applications/**.*"
}
includedirs {
"Physx2D/libraries/include",
"Physx2D/src"
}
filter "system:windows"
systemversion "latest"
links {"Physx2D"}
defines {"PHSX2D_PLATFORM_WINDOWS"}
filter "system:linux"
systemversion "latest"
links {"Physx2D"}
defines {"PHSX2D_PLATFORM_LINUX"}
filter "configurations:Debug"
defines {"PHSX2D_DEBUG", "PHSX2D_ASSERT_ENABLE"}
symbols "on"
filter "configurations:Release"
defines {"PHSX2D_RELEASE", "PHSX2D_ASSERT_ENABLE"}
optimize "on"
I do not think that the problem has anything to do with the project setup. After a quick look at the problems and few searches later, I came to know the issue is that the definitions of functions declared in glad.h are not found during linking. I have glad.c inside the Physx2D project inside a folder which I have included in project files in premake script. Also, if it is the problem why it did not create any issues while building the Physx2D.
If it is not the problem then what is and how to solve it.