ConvertSidToStringSidA linker error

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

ConvertSidToStringSidA linker error

mingw
Hello.

Can't seem to link this simple program:

#include <windows.h>
#include <sddl.h>
#include <stdio.h>

#define MAX_SIZE 256

int
main (int argc, char *argv[])
{
  char *name;
  char domain [MAX_SIZE];
  char *sid_str;
  DWORD domain_size = MAX_SIZE;
  DWORD sid_size = MAX_SIZE;
  SID *sid;
  SID_NAME_USE account_type;

  if (argc < 2) {
    fprintf (stderr, "usage: name\n");
    return 111;
  }

  name = argv[1];
  sid = malloc (MAX_SIZE);

  if (!LookupAccountName (NULL, name, sid, &sid_size,
    domain, &domain_size, &account_type)) {
    fprintf (stderr, "error: lookup: %d\n", GetLastError());
    return 112;
  }

  fprintf (stderr, "info: lookup ok\n");

  if (!ConvertSidToStringSid (sid, &sid_str)) {
    fprintf (stderr, "error: convert: %d\n", GetLastError());
    return 112;
  }

  printf ("%s\n", sid_str);
  return 0;
}

---

$ gcc -v -o getsid getsid.c
Reading specs from c:/MinGW/bin/../lib/gcc/mingw32/3.4.5/specs
Configured with: ../gcc-3.4.5-20060117-3/configure --with-gcc --with-gnu-ld --with-gnu-as --host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls --enable-languages=c,c++,f77,ada,objc,java --disable-win32-registry --disable-shared --enable-sjlj-exceptions --enable-libgcj --disable-java-awt --without-x --enable-java-gc=boehm --disable-libgcj-debug --enable-interpreter --enable-hash-synchronization --enable-libstdcxx-debug
Thread model: win32
gcc version 3.4.5 (mingw-vista special r3)
 c:/MinGW/bin/../libexec/gcc/mingw32/3.4.5/cc1.exe -quiet -v -iprefix c:\MinGW\bin\../lib/gcc/mingw32/3.4.5/ getsid.c -quiet -dumpbase getsid.c -auxbase getsid -version -o c:\WINDOWS\TEMP/cchaXtZi.s
ignoring nonexistent directory "c:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../mingw32/include"
ignoring nonexistent directory "/mingw/lib/gcc/mingw32/3.4.5/../../../../mingw32/include"
#include "..." search starts here:
#include <...> search starts here:
 c:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include
 c:/MinGW/bin/../lib/gcc/mingw32/3.4.5/include
 /mingw/lib/gcc/mingw32/3.4.5/../../../../include
 /mingw/include
 /mingw/lib/gcc/mingw32/3.4.5/include
 /mingw/include
End of search list.
GNU C version 3.4.5 (mingw-vista special r3) (mingw32)
        compiled by GNU C version 3.4.5 (mingw-vista special r3).
GGC heuristics: --param ggc-min-expand=36 --param ggc-min-heapsize=12222
 c:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../mingw32/bin/as.exe -o c:\WINDOWS\TEMP/cccGHcfi.o c:\WINDOWS\TEMP/cchaXtZi.s
 c:/MinGW/bin/../libexec/gcc/mingw32/3.4.5/collect2.exe -Bdynamic -o getsid.exe /mingw/lib/crt2.o c:/MinGW/bin/../lib/gcc/mingw32/3.4.5/crtbegin.o -Lc:/MinGW/bin/../lib/gcc/mingw32/3.4.5 -Lc:/MinGW/bin/../lib/gcc -L/mingw/lib/gcc/mingw32/3.4.5 -Lc:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../mingw32/lib -L/mingw/lib/gcc/mingw32/3.4.5/../../../../mingw32/lib -L/mingw/lib -Lc:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../.. -L/mingw/lib/gcc/mingw32/3.4.5/../../.. c:\WINDOWS\TEMP/cccGHcfi.o -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt -luser32 -lkernel32 -ladvapi32 -lshell32 -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt c:/MinGW/bin/../lib/gcc/mingw32/3.4.5/crtend.o
c:\WINDOWS\TEMP/cccGHcfi.o:getsid.c:(.text+0x139): undefined reference to `ConvertSidToStringSidA'
collect2: ld returned 1 exit status

The MSDN documentation says that the function is provided by advapi32.dll, which
does appear in the compiler's default list of linked DLLs.

Any idea why there's still an undefined reference?


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users

_______________________________________________
This list observes the Etiquette found at http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.
Reply | Threaded
Open this post in threaded view
|

Re: ConvertSidToStringSidA linker error

Brian Dessent
[hidden email] wrote:

> The MSDN documentation says that the function is provided by advapi32.dll, which
> does appear in the compiler's default list of linked DLLs.
>
> Any idea why there's still an undefined reference?

The failure is because you didn't specify the version of Windows you
want to target.  If you look at that MSDN page you'll also see that the
function is only available on Windows 2k and later, which means you need
to define WINVER to 0x0500 or higher before including any of the Windows
headers if you want to use that interface, and accept that the resulting
executable produced won't run on 9x/ME/NT4 systems.

What actually happened was because WINVER wasn't defined sddl.h didn't
declare a prototype for the function.  If you enable warnings (always a
good idea) you will see one about calling a function without a
prototype, which is a big clue that something is wrong.  But because the
Win32 API uses a different calling convention than the C default this
also means that linking fails without a proper prototype in scope, even
though -ladvapi32 was present.

Brian

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users

_______________________________________________
This list observes the Etiquette found at http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.
Reply | Threaded
Open this post in threaded view
|

Re: ConvertSidToStringSidA linker error

mingw
On 20081201 22:11:38, Brian Dessent wrote:

> [hidden email] wrote:
>
> > The MSDN documentation says that the function is provided by advapi32.dll, which
> > does appear in the compiler's default list of linked DLLs.
> >
> > Any idea why there's still an undefined reference?
>
> What actually happened was because WINVER wasn't defined sddl.h didn't
> declare a prototype for the function.  If you enable warnings (always a
> good idea) you will see one about calling a function without a
> prototype, which is a big clue that something is wrong.  But because the
> Win32 API uses a different calling convention than the C default this
> also means that linking fails without a proper prototype in scope, even
> though -ladvapi32 was present.

Thanks.

Yeah, it was the fact that it was a linker error that threw me. I'll
know in future...


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users

_______________________________________________
This list observes the Etiquette found at http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.