Sceadu
Sceadu

Reputation: 11

Github Actions ci not finding symbols referenced by <stdio.h> during linking

I'm compiling a C project through Github Actions using Premake5 and MsBuild. Compilation is successful using this command:

C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.42.34433\bin\HostX86\x86\CL.exe /c /nologo /W3 /WX- /diagnostics:column /sdl- /O2 /Oi /Oy- /D NDEBUG /D _HAS_EXCEPTIONS=0 /D _WINDLL /GF /Gm- /MD /GS- /Gy /fp:fast /fp:except- /Zc:wchar_t /Zc:forScope /Zc:inline /GR- /Fo"obj\\" /Fd"obj\vc143.pdb" /external:W3 /Gd /TC /analyze- /FC /errorReport:queue /kernel /Gs1000000 ..\dllmain.c

but it's currently failing during linking when running this:

C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.42.34433\bin\HostX86\x86\link.exe /ERRORREPORT:QUEUE /OUT:"..\bin\dinput.dll" /INCREMENTAL:NO /NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST:NO /PDB:"..\bin\dinput.pdb" /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /TLBID:1 /ENTRY:"DllMain" /RELEASE /DYNAMICBASE /NXCOMPAT /IMPLIB:"..\bin\dinput.lib" /MACHINE:X86 /CETCOMPAT:NO /SAFESEH:NO /kernel /SAFESEH:NO /GUARD:NO /EMITPOGOPHASEINFO /RELEASE /DEBUG:NONE /NOIMPLIB /NOEXP /IGNORE:4104 /DLL obj\dllmain.obj
     2>dllmain.obj : error LNK2019: unresolved external symbol __imp__fclose referenced in function _DllMain@12 [D:\a\khaldun.net-client\khaldun.net-client\build\khaldun.net-client.vcxproj]
     2>dllmain.obj : error LNK2019: unresolved external symbol __imp__fflush referenced in function _serverCheck [D:\a\khaldun.net-client\khaldun.net-client\build\khaldun.net-client.vcxproj]
     2>dllmain.obj : error LNK2019: unresolved external symbol __imp__fopen referenced in function _DllMain@12 [D:\a\khaldun.net-client\khaldun.net-client\build\khaldun.net-client.vcxproj]
     2>dllmain.obj : error LNK2019: unresolved external symbol __imp__fputs referenced in function _serverCheck [D:\a\khaldun.net-client\khaldun.net-client\build\khaldun.net-client.vcxproj]
     2>dllmain.obj : error LNK2019: unresolved external symbol __imp____stdio_common_vfprintf referenced in function _fprintf [D:\a\khaldun.net-client\khaldun.net-client\build\khaldun.net-client.vcxproj]
     2>..\bin\dinput.dll : fatal error LNK1120: 5 unresolved externals [D:\a\khaldun.net-client\khaldun.net-client\build\khaldun.net-client.vcxproj]
     2>Done Building Project "D:\a\khaldun.net-client\khaldun.net-client\build\khaldun.net-client.vcxproj" (default targets) -- FAILED.
     1>Done Building Project "D:\a\khaldun.net-client\khaldun.net-client\build\khaldun.net-client.sln" (default targets) -- FAILED.

This is a fork of an existing project, and the Action was set up by someone else, so I admit I don't know what most of the premake instructions mean. I'll attach it below in case it proves useful


workspace "khaldun.net-client"
  configurations { "Release" }
  platforms { "Win32" }
  location "build"
  objdir ("build/obj")
  buildlog ("build/log/%{prj.name}.log")

  characterset ("ASCII")
  staticruntime "Off"
  exceptionhandling "Off"
  floatingpoint "Fast"
  floatingpointexceptions "Off"
  intrinsics "On"
  rtti "Off"
  flags { "NoBufferSecurityCheck", "NoIncrementalLink", "NoManifest", "NoPCH", "NoRuntimeChecks" }
  buildoptions { "/kernel", "/Gs1000000" }
  linkoptions { "/kernel", "/SAFESEH:NO", "/GUARD:NO", "/EMITPOGOPHASEINFO", "/RELEASE", "/DEBUG:NONE", "/NOIMPLIB", "/NOEXP", "/IGNORE:4104" }

  filter "configurations:Release"
    runtime "Release"
    defines "NDEBUG"
    optimize "Speed"
    symbols "Off"

  architecture "x86"

project "khaldun.net-client"
  kind "SharedLib"
  language "C"
  targetextension ".dll"
  targetdir "bin"
  files { "dllmain.c", "include/*.h", "iathook/iathook.h" }
  entrypoint "DllMain"
  targetname "dinput"

if _ACTION and _ACTION >= "vs2010" then
  require "vstudio"
  premake.override(premake.vstudio.vc2010.elements, "clCompile", function(base, prj)
    local calls = base(prj)
    table.insert(calls, function() premake.vstudio.vc2010.element("SDLCheck", nil, "false") end)
    table.insert(calls, function() premake.vstudio.vc2010.element("ControlFlowGuard", nil, "false") end)
    return calls
  end)
  premake.override(premake.vstudio.vc2010.elements, "link", function(base, prj)
    local calls = base(prj)
    table.insert(calls, function() premake.vstudio.vc2010.element("SetChecksum", nil, "true") end)
    table.insert(calls, function() premake.vstudio.vc2010.element("CETCompat", nil, "false") end)
    table.insert(calls, function() premake.vstudio.vc2010.element("ImageHasSafeExceptionHandlers", nil, "false") end)
    table.insert(calls, function() premake.vstudio.vc2010.element("EnableUAC", nil, "false") end)
    return calls
  end)
end

The Github Actions ci.yml looks like this:

name: ci

on:
  workflow_dispatch: # allows manual triggering
    inputs:
      create_release:
        description: 'Create new release'
        required: true
        type: boolean
  push:
    paths: ['.github/workflows/**', '**/premake5.lua', '**/*.h', '**/*.c']
  pull_request:
    types: [opened, synchronize, reopened]
    paths: ['**/premake5.lua', '**/*.h', '**/*.c']

env:
  SOLUTION_FILE_PATH: ./build/khaldun.net-client.sln
  BUILD_CONFIGURATION: Release
  BRANCH_NAME: ${{ github.head_ref || github.ref_name }}

jobs:
  build:
    name: build-windows
    runs-on: windows-latest
    permissions:
      contents: write
      pull-requests: write
      repository-projects: write
      
    steps:
    - name: Checkout the repository
      id: checkout
      uses: actions/checkout@v3
      with:
        submodules: 'true'

    - name: Run premake '5.0.0-beta2'
      id: run_premake
      uses: eariassoto/setup-premake@v1
      with:
        version: '5.0.0-beta2'
        action: 'vs2022'  

    - name: Add MSBuild to PATH
      id: setup_msbuild
      uses: microsoft/[email protected]

    - name: Build
      id: run_msbuild
      working-directory: ${{env.GITHUB_WORKSPACE}}
      # Add additional options to the MSBuild command line here (like platform or verbosity level).
      # See https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference
      run: msbuild /m /p:Platform=Win32 /p:Configuration=${{env.BUILD_CONFIGURATION}} ${{env.SOLUTION_FILE_PATH}}
      
    - name: Upload artifact
      uses: actions/upload-artifact@v4
      with:
        name: dinput
        path: |
          .\bin\dinput.dll

I'm including stdio.h in my main source file (which is the same file I'm using the stdio functions in) with #include <stdio.h>, and when compiling locally from the Developer Powershell for VS 2022 with cl.exe /LD dllmain.c /link /OUT:build\dinput.dll, it works without issue.

I was having similar linking errors (both locally & in the cloud) with other imports, but I was able to fix them using #pragma comment:

#pragma comment(lib, "Shell32.lib")
#pragma comment(lib, "advapi32.lib")
#pragma comment(lib, "ws2_32.lib")  

Is there a specific Windows lib that includes the stdio C functions that I can explicitly link to?

This is my first question here, so any feedback on how to make this (and future) questions better is appreciated!

Upvotes: 1

Views: 48

Answers (0)

Related Questions