digitalmars.D - Linker can't link functions from advapi
- Deen O'Connor (11/11) Apr 01 2019 So i got this problem when i tried to compile my project in VS 17
- Kagamin (1/1) Apr 01 2019 Maybe you didn't setup the project to link with advapi32.lib
- Mike Parker (4/16) Apr 01 2019 You shouldn't need to convert it for the MS linker. The proper
- Deen O'Connor (3/6) Apr 01 2019 I know, but if i don't set the .lib file for the linker, it
- kinke (5/7) Apr 01 2019 So the only issue is that the lib isn't referenced automatically
- Deen O'Connor (2/4) Apr 02 2019 It worked, thanks a lot.
- Mike Parker (9/15) Apr 01 2019 Right. That’s how the compile-link model works. While it would be
- kinke (6/10) Apr 01 2019 I count 62 `pragma(lib, ...)` in druntime, incl. advapi32 [1].
- destructionator gmail.com (4/6) Apr 01 2019 So yes and no. I agree they should be there, but they are unlikely to
- Mike Parker (4/12) Apr 01 2019 Yeah, I was surprised to learn that they are there. I've had to
- Deen O'Connor (2/10) Apr 02 2019 I see, thank you for explaining that.
- Bastiaan Veelo (20/32) Apr 01 2019 I would advise against using optlink, make sure your object file
- Deen O'Connor (3/20) Apr 01 2019 That didn't work. Linking failed with code 1120 with the same
- Deen O'Connor (2/19) Apr 01 2019 Linker failed with exit code 1120, same errors as before.
- Mike Parker (3/18) Apr 01 2019 You don't need all of those if you aren't using them, but did you
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.
Apr 01 2019
Maybe you didn't setup the project to link with advapi32.lib
Apr 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.
Apr 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.
Apr 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?
Apr 01 2019
On Monday, 1 April 2019 at 19:08:01 UTC, kinke wrote:Then all that's missing is a `pragma(lib, "advapi32")` in the module referencing these functions; is that druntime?It worked, thanks a lot.
Apr 02 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: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.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.
Apr 01 2019
On Monday, 1 April 2019 at 21:10:20 UTC, Mike Parker wrote: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.I count 62 `pragma(lib, ...)` in druntime, incl. advapi32 [1]. Missing ones can be seen as a bug, or at the very least an unnecessary inconvenience. [1] https://github.com/dlang/druntime/blob/aa39818f2805d7406d06c9fc74b7903789ca13ac/src/core/sys/windows/aclapi.d#L14
Apr 01 2019
On Mon, Apr 01, 2019 at 09:46:51PM +0000, kinke via Digitalmars-d wrote:I count 62 `pragma(lib, ...)` in druntime, incl. advapi32 [1]. Missing ones can be seen as a bug, or at the very least an unnecessary inconvenience.So yes and no. I agree they should be there, but they are unlikely to actually work because the druntime modules are not in the active build and thus their pragmas don't apply.
Apr 01 2019
On Tuesday, 2 April 2019 at 01:18:54 UTC, destructionator wrote:On Mon, Apr 01, 2019 at 09:46:51PM +0000, kinke via Digitalmars-d wrote:Yeah, I was surprised to learn that they are there. I've had to link with certain system libs on Windows as recently as a few months ago and had simply assumed the pragmas weren't there.I count 62 `pragma(lib, ...)` in druntime, incl. advapi32 [1]. Missing ones can be seen as a bug, or at the very least an unnecessary inconvenience.So yes and no. I agree they should be there, but they are unlikely to actually work because the druntime modules are not in the active build and thus their pragmas don't apply.
Apr 01 2019
On Monday, 1 April 2019 at 21:10:20 UTC, Mike Parker wrote: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.I see, thank you for explaining that.
Apr 02 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.
Apr 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.
Apr 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.
Apr 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:You don't need all of those if you aren't using them, but did you add advapi32 to the list?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.
Apr 01 2019