Linking Error only with tgui::Textures

Started by LeeDev, 07 January 2024, 07:36:24

LeeDev

I am currently working on a project using TGUI with SFML in Visual Studio and have encountered a linker error that I'm unable to resolve. The error occurs specifically when I try to use the tgui::Texture class. Other components of TGUI seem to work fine in my project, but any attempt to use tgui::Texture results in a linker error.

LNK2001: unresolved external symbol "private: static bool tgui::Texture::m_defaultSmooth" (?m_defaultSmooth@Texture@tgui@@0_NA)


Project Setup:

IDE: Visual Studio 2022
TGUI Version: TGUI 1.1.0
SFML Version: 2.6.1
Build Configuration: Debug
Platform: Win32

I have checked that my project is set up according to the TGUI documentation:

The TGUI library is correctly linked in the project settings.
I am using the correct build configuration (Debug/Release) for both TGUI and SFML.
The include and library directories are properly set in Visual Studio.
I have tried the following steps to troubleshoot the issue:

Rechecked all linker settings in Visual Studio.
Verified that there are no multiple definitions of TGUI symbols.
Rebuilt the TGUI library to ensure it matches my project settings.
Created a minimal test case where I only use tgui::Texture.
Despite these efforts, the linker error persists. It's puzzling that this issue is specific to tgui::Texture and does not affect other TGUI components.

I would greatly appreciate any insights or suggestions on how to resolve this issue. Has anyone else encountered a similar problem, or can anyone spot something I might be missing in my setup?

Thank you in advance for your help!

texus

I'm assuming you would also get a linking error when using e.g. tgui::Color::Black in your code?

While I haven't seen this issue with TGUI yet, I remember seeing similar issues before with SFML (where people got linking errors only for the "static" variables). I think the cause might have been mixing libraries like shared vs static ones.

Can you maybe share the .vcxproj file of your project so that I can check if I can see something unusual about it?

LeeDev

Yeah, no problem. Thanks for being so active just in general.

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Debug|Win32">
      <Configuration>Debug</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|Win32">
      <Configuration>Release</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Debug|x64">
      <Configuration>Debug</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|x64">
      <Configuration>Release</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <PropertyGroup Label="Globals">
    <VCProjectVersion>17.0</VCProjectVersion>
    <Keyword>Win32Proj</Keyword>
    <ProjectGuid>{298ee5a2-233e-466c-9e60-a36352de2fa0}</ProjectGuid>
    <RootNamespace>Simple2DDrawingApplication</RootNamespace>
    <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v143</PlatformToolset>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v143</PlatformToolset>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v143</PlatformToolset>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v143</PlatformToolset>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <ImportGroup Label="ExtensionSettings">
  </ImportGroup>
  <ImportGroup Label="Shared">
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <PropertyGroup Label="UserMacros" />
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions);SMFL_STATIC;TGUI_STATIC</PreprocessorDefinitions>
      <ConformanceMode>true</ConformanceMode>
      <AdditionalIncludeDirectories>D:\Dev\LocalRepos\Simple2D-DrawingApplication\TGUI\include;D:\Dev\LocalRepos\Simple2D-DrawingApplication\Src;D:\Dev\LocalRepos\Simple2D-DrawingApplication\SMFL\include</AdditionalIncludeDirectories>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <AdditionalDependencies>sfml-graphics-d.lib;sfml-window-d.lib;sfml-audio-d.lib;sfml-network-d.lib;sfml-system-d.lib;tgui-d.lib</AdditionalDependencies>
      <AdditionalLibraryDirectories>D:\Dev\LocalRepos\Simple2D-DrawingApplication\TGUI\lib;D:\Dev\LocalRepos\Simple2D-DrawingApplication\SMFL\lib;</AdditionalLibraryDirectories>
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions);SMFL_STATIC;TGUI_STATIC</PreprocessorDefinitions>
      <ConformanceMode>true</ConformanceMode>
      <AdditionalIncludeDirectories>D:\Dev\LocalRepos\Simple2D-DrawingApplication\TGUI\include;D:\Dev\LocalRepos\Simple2D-DrawingApplication\SMFL\include;</AdditionalIncludeDirectories>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <AdditionalDependencies>sfml-graphics.lib;sfml-window.lib;sfml-audio.lib;sfml-network.lib;sfml-system.lib;%(AdditionalDependencies);tgui.lib</AdditionalDependencies>
      <AdditionalLibraryDirectories>D:\Dev\LocalRepos\Simple2D-DrawingApplication\TGUI\lib;D:\Dev\LocalRepos\Simple2D-DrawingApplication\SMFL\lib;</AdditionalLibraryDirectories>
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions);SMFL_STATIC;TGUI_STATIC</PreprocessorDefinitions>
      <ConformanceMode>true</ConformanceMode>
      <AdditionalIncludeDirectories>D:\Dev\LocalRepos\Simple2D-DrawingApplication\TGUI\include;D:\Dev\LocalRepos\Simple2D-DrawingApplication\SMFL\include;D:\Dev\LocalRepos\Simple2D-DrawingApplication\SMFL\include;</AdditionalIncludeDirectories>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <AdditionalLibraryDirectories>D:\Dev\LocalRepos\Simple2D-DrawingApplication\TGUI\lib;D:\Dev\LocalRepos\Simple2D-DrawingApplication\SMFL\lib;D:\Dev\LocalRepos\Simple2D-DrawingApplication\SMFL\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
      <AdditionalDependencies>sfml-graphics-d.lib;sfml-window-d.lib;sfml-audio-d.lib;sfml-network-d.lib;sfml-system-d.lib;tgui-d.lib</AdditionalDependencies>
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions);SMFL_STATIC;TGUI_STATIC</PreprocessorDefinitions>
      <ConformanceMode>true</ConformanceMode>
      <AdditionalIncludeDirectories>D:\Dev\LocalRepos\Simple2D-DrawingApplication\TGUI\include;D:\Dev\LocalRepos\Simple2D-DrawingApplication\SMFL\include;D:\Dev\LocalRepos\Simple2D-DrawingApplication\SMFL\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <AdditionalLibraryDirectories>D:\Dev\LocalRepos\Simple2D-DrawingApplication\TGUI\lib;D:\Dev\LocalRepos\Simple2D-DrawingApplication\SMFL\lib;D:\Dev\LocalRepos\Simple2D-DrawingApplication\SMFL\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
      <AdditionalDependencies>sfml-graphics.lib;sfml-window.lib;sfml-audio.lib;sfml-network.lib;sfml-system.lib;%(AdditionalDependencies);tgui.lib</AdditionalDependencies>
    </Link>
  </ItemDefinitionGroup>
  <ItemGroup>
    <ClCompile Include="Src\DrawingApp.cpp" />
    <ClCompile Include="Src\GuiManager.cpp" />
    <ClCompile Include="Src\MathHelpers.cpp" />
    <ClCompile Include="Src\ShapeTool.cpp" />
    <ClCompile Include="Simple2D-DrawingApplication.cpp" />
  </ItemGroup>
  <ItemGroup>
    <ClInclude Include="Src\DrawingApp.h" />
    <ClInclude Include="Src\GuiManager.h" />
    <ClInclude Include="Src\MathHelpers.h" />
    <ClInclude Include="Src\ShapeTool.h" />
  </ItemGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ImportGroup Label="ExtensionTargets">
  </ImportGroup>
</Project>


texus

You are defining SMFL_STATIC (which even has a typo) and TGUI_STATIC, but you are linking to the dynamic libraries (i.e. the ones that don't end have "-s" in the name). So you should remove SMFL_STATIC and TGUI_STATIC from the PreprocessorDefinitions.

LeeDev

Oh duh. I remember seeing that in the docs and thought I skipped it, but apparently not. I didn't know all of that information was in the vcxproj either.

Thanks for the help, and keep up the great work!