Page 1 of 1

unable to load c2.dll when importing a static library

Posted: Sun Apr 07, 2024 9:14 pm
by Quin
I'm attempting to link against libgit2 (https://github.com/libgit2/libgit2) in my app. I cloned it, built it as a static library with CMake, put it in my PureLibraries/Windows/Libraries folder, and have this code:

Code: Select all

CompilerIf #PB_Compiler_IsMainFile
	ImportC "git2.lib"
		git_libgit2_init()
	EndImport
	
	git_libgit2_init()
CompilerEndIf
However, when attempting to run this, I get:
git2.lib(libgit2.obj) : MSIL .netmodule or module compiled with /GL found; restarting link with /LTCG; add /LTCG to the link command line to improve linker performance
LINK : fatal error LNK1171: unable to load c2.dll (error code: 126)
So that's fine, I make a linker options file with /LTCG in it, and use it. Gets rid of that error, but this one still remains:
LINK : fatal error LNK1171: unable to load c2.dll (error code: 126)
I'm utterly lost on what to do here. I have no idea what c2.dll is. Googling was inconclusive, I found a few references to it in Everything search, but haven't been able to figure it out. SO I turn to you, amazing community! :) What does this mean, and how can I fix it?
Thanks in advance for any help!

Re: unable to load c2.dll when importing a static library

Posted: Mon Apr 08, 2024 1:02 pm
by fryquez
c2.dll is an optional dependency of link.exe. Final release of PB 6.10 remove the VC linker and switch to polink.exe again.

Either reinstall PB or grab the c2.dll (and properly more dlls) from a Visual Studio installation:

C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\bin\Hostx64\x64

Re: unable to load c2.dll when importing a static library

Posted: Mon Apr 08, 2024 2:34 pm
by Quin
I reverted back to polink, it's just easier. However, now I get this:
error: Unsupported anonymous format in object 'C:\Users\Quin\code3\libgit2\build\src\libgit2\libgit2.dir\Release\libgit2.obj'.

:twisted:

Re: unable to load c2.dll when importing a static library

Posted: Tue Apr 09, 2024 1:24 pm
by Justin
Hi,
i tried to build with mingw, it creates the satic lib but when calling git_libgit2_init() polink shows no errors but the debugger quits unexpectedly.

i thought that with the new linker these things would be easier but not in this case.

Re: unable to load c2.dll when importing a static library

Posted: Tue Apr 09, 2024 8:10 pm
by chi
@Quin: In VisualStudio you have to set "Whole Program Optimization" to No, or remove /GL in cmake to make static libs work in PB

Re: unable to load c2.dll when importing a static library

Posted: Tue Apr 09, 2024 8:22 pm
by Quin
chi wrote: Tue Apr 09, 2024 8:10 pm @Quin: In VisualStudio you have to set "Whole Program Optimization" to No, or remove /GL in cmake to make static libs work in PB
Thanks, this made it link properly, and also shrank the .lib by like 70 MB :shock:
And now, this happens. Guess the world really does not want me linking against libgit :(
---------------------------
PureBasic - Linker error
---------------------------
error: Unresolved external symbol 'close' - referenced from 'git2.lib(mwindow.obj)'.

POLINK: error: Unresolved external symbol '__imp_WinHttpQueryAuthSchemes' - referenced from 'git2.lib(winhttp.obj)'.

POLINK: error: Unresolved external symbol '__imp_CoInitializeEx' - referenced from 'git2.lib(winhttp.obj)'.

POLINK: error: Unresolved external symbol 'IID_IInternetSecurityManager' - referenced from 'git2.lib(winhttp.obj)'.

POLINK: error: Unresolved external symbol 'CLSID_InternetSecurityManager' - referenced from 'git2.lib(winhttp.obj)'.

POLINK: error: Unresolved external symbol '__imp_CoCreateInstance' - referenced from 'git2.lib(winhttp.obj)'.

POLINK: error: Unresolved external symbol '__imp_CoUninitialize' - referenced from 'git2.lib(winhttp.obj)'.

...


---------------------------
OK
---------------------------
So seemingly it's not including some COM component or something. I have no idea, this is not what I do.

Re: unable to load c2.dll when importing a static library

Posted: Tue Apr 09, 2024 10:33 pm
by chi
You have to tell the linker where to find those symbols like this...

Code: Select all

Import "Ole32.lib" : EndImport
Import "Winhttp.lib" : EndImport
...
or include them in the static lib in VS ;)

Re: unable to load c2.dll when importing a static library

Posted: Wed Apr 10, 2024 3:34 am
by chi
I managed to get git_libgit2_init() running with...

Code: Select all

CompilerIf #PB_Compiler_IsMainFile

  Import "ole32.lib" : EndImport
  Import "winhttp.lib" : EndImport
  Import "crypt32.lib" : EndImport
  Import "wbemuuid.lib" : EndImport
  Import "rpcrt4.lib" : EndImport
  Import "zlib.lib" : EndImport
  Import "uuid.lib" : EndImport
  Import "shlwapi.lib" : EndImport
  
  Import ".\pcre.lib" : EndImport
  Import ".\oldnames.lib" : EndImport
  Import ".\git2.lib"
    git_libgit2_init()
  EndImport
  
  Debug git_libgit2_init()
  
CompilerEndIf
You have to compile pcre.lib (Perl Compatible Regular Expressions) yourself and also copy oldnames.lib from VisualStudio\VC\Tools\MSVC\xx.xx.xxxxx\lib\x64\uwp to the directory where the git2.lib is and you saved above .pb file.

Re: unable to load c2.dll when importing a static library

Posted: Wed Apr 10, 2024 4:59 pm
by Quin
Wow, thanks so much, @chi! You're a legend!

Re: unable to load c2.dll when importing a static library

Posted: Fri Apr 12, 2024 7:32 am
by chi
np, thx