Jump to page: 1 2
Thread overview
Linker can't link functions from advapi
Apr 01, 2019
Deen O'Connor
Apr 01, 2019
Kagamin
Apr 01, 2019
Mike Parker
Apr 01, 2019
Deen O'Connor
Apr 01, 2019
kinke
Apr 02, 2019
Deen O'Connor
Apr 01, 2019
Mike Parker
Apr 01, 2019
kinke
Apr 02, 2019
destructionator
Apr 02, 2019
Mike Parker
Apr 02, 2019
Deen O'Connor
Apr 01, 2019
Bastiaan Veelo
Apr 01, 2019
Deen O'Connor
Apr 01, 2019
Deen O'Connor
Apr 01, 2019
Mike Parker
April 01, 2019
So i got this problem when i tried to compile my project in VS 17 with VisualD plugin.

It compiled just fine, i got no errors from DMD, but both optlink and vs linker tell me that i have 3 unknown functions - OpenProcessToken, LookupPrivilegeValue and AdjustTokenPrivileges.

I tried converting advapi32.dll to .lib, this did not solve the problem, because with the necessary .lib file set in project settings i get a message telling me that my advapi32.lib is corrupt.

Idk what to do, and i don't want to re-write everything with another language.
April 01, 2019
Maybe you didn't setup the project to link with advapi32.lib
April 01, 2019
On Monday, 1 April 2019 at 10:07:58 UTC, Deen O'Connor wrote:
> So i got this problem when i tried to compile my project in VS 17 with VisualD plugin.
>
> It compiled just fine, i got no errors from DMD, but both optlink and vs linker tell me that i have 3 unknown functions - OpenProcessToken, LookupPrivilegeValue and AdjustTokenPrivileges.
>
> I tried converting advapi32.dll to .lib, this did not solve the problem, because with the necessary .lib file set in project settings i get a message telling me that my advapi32.lib is corrupt.
>
> Idk what to do, and i don't want to re-write everything with another language.

You shouldn't need to convert it for the MS linker. The proper 32- and 64-bit COFF format libs should have been installed with VS 17.
April 01, 2019
On Monday, 1 April 2019 at 14:04:35 UTC, Mike Parker wrote:
> You shouldn't need to convert it for the MS linker. The proper 32- and 64-bit COFF format libs should have been installed with VS 17.

 I know, but if i don't set the .lib file for the linker, it tells me it doesn't know those functions.
April 01, 2019
On Monday, 1 April 2019 at 10:07:58 UTC, Deen O'Connor wrote:
> So i got this problem when i tried to compile my project in VS 17 with VisualD plugin.
>
> It compiled just fine, i got no errors from DMD, but both optlink and vs linker tell me that i have 3 unknown functions - OpenProcessToken, LookupPrivilegeValue and AdjustTokenPrivileges.
>
> I tried converting advapi32.dll to .lib, this did not solve the problem, because with the necessary .lib file set in project settings i get a message telling me that my advapi32.lib is corrupt.
>
> Idk what to do, and i don't want to re-write everything with another language.

I would advise against using optlink, make sure your object file format is COFF. I can recommend setting up your project for dub[1]. All I had to do is add this to dub.json:

 	"libs": [
		"Gdi32",
		"Comdlg32",
		"Winspool",
		"Ws2_32",
		"wntab32x",
		"User32"
		],

and compile with `dub build -a=x86_mscoff` for 32bit or `dub build -a=x86_64` for 64bit. It just works. Granted I also have this in dub.json

  	"lflags-x86_mscoff": ["/NODEFAULTLIB:LIBC.lib"]

but I believe that is necessary because of some other libs that we link with.


[1] https://dub.pm/getting_started

Bastiaan.
April 01, 2019
On Monday, 1 April 2019 at 15:10:20 UTC, Deen O'Connor wrote:
>  I know, but if i don't set the .lib file for the linker, it tells me it doesn't know those functions.

So the only issue is that the lib isn't referenced automatically and that you have to specify it explicitly? Then all that's missing is a `pragma(lib, "advapi32")` in the module referencing these functions; is that druntime?
April 01, 2019
On Monday, 1 April 2019 at 15:33:46 UTC, Bastiaan Veelo wrote:
> I would advise against using optlink, make sure your object file format is COFF. I can recommend setting up your project for dub[1]. All I had to do is add this to dub.json:
>
>  	"libs": [
> 		"Gdi32",
> 		"Comdlg32",
> 		"Winspool",
> 		"Ws2_32",
> 		"wntab32x",
> 		"User32"
> 		],
>
> and compile with `dub build -a=x86_mscoff` for 32bit or `dub build -a=x86_64` for 64bit. It just works. Granted I also have this in dub.json
>
>   	"lflags-x86_mscoff": ["/NODEFAULTLIB:LIBC.lib"]
>
> but I believe that is necessary because of some other libs that we link with.

That didn't work. Linking failed with code 1120 with the same errors as before.


April 01, 2019
On Monday, 1 April 2019 at 15:33:46 UTC, Bastiaan Veelo wrote:
> I would advise against using optlink, make sure your object file format is COFF. I can recommend setting up your project for dub[1]. All I had to do is add this to dub.json:
>
>  	"libs": [
> 		"Gdi32",
> 		"Comdlg32",
> 		"Winspool",
> 		"Ws2_32",
> 		"wntab32x",
> 		"User32"
> 		],
>
> and compile with `dub build -a=x86_mscoff` for 32bit or `dub build -a=x86_64` for 64bit. It just works. Granted I also have this in dub.json
>
>   	"lflags-x86_mscoff": ["/NODEFAULTLIB:LIBC.lib"]
>
> but I believe that is necessary because of some other libs that we link with.

Linker failed with exit code 1120, same errors as before.
April 01, 2019
On Monday, 1 April 2019 at 15:10:20 UTC, Deen O'Connor wrote:
> On Monday, 1 April 2019 at 14:04:35 UTC, Mike Parker wrote:
>> You shouldn't need to convert it for the MS linker. The proper 32- and 64-bit COFF format libs should have been installed with VS 17.
>
>  I know, but if i don't set the .lib file for the linker, it tells me it doesn't know those functions.

Right. That’s how the compile-link model works. While it would be possible to add a lib pragma to every system module in DRuntime so that the appropriate library is automatically linked when the module is imported, that’s not currently the case. So you do have to provide them to the linker.

When using Optlink, some commonly system libs are automatically linked, like kernel32 for example, but not when using the MS linker.
April 01, 2019
On Monday, 1 April 2019 at 19:09:50 UTC, Deen O'Connor wrote:
> On Monday, 1 April 2019 at 15:33:46 UTC, Bastiaan Veelo wrote:
>> I would advise against using optlink, make sure your object file format is COFF. I can recommend setting up your project for dub[1]. All I had to do is add this to dub.json:
>>
>>  	"libs": [
>> 		"Gdi32",
>> 		"Comdlg32",
>> 		"Winspool",
>> 		"Ws2_32",
>> 		"wntab32x",
>> 		"User32"
>> 		],
>>
>
> Linker failed with exit code 1120, same errors as before.

You don't need all of those if you aren't using them, but did you add advapi32 to the list?

« First   ‹ Prev
1 2