undefined reference to `GetComputerNameExA'

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

undefined reference to `GetComputerNameExA'

Carl Sturtivant
New to in-depth use of MinGW. But it's clearly the right thing!

According to MSDN GetComputerNameExA is in kernel32.dll ,
yet the following program compiles but does not link with my MinGW
installation. Adding -lkernel32 doesn't help. Details below. Any
suggestions how I can get linkage?

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

int main() {
  char buf[1024];
  DWORD sz = 1024;
  //GetComputerNameA( buf, &sz);
  GetComputerNameExA( 1, buf, &sz);
  printf( "\"%s\"\n", buf);
}
========

msys $ gcc -o gethostname gethostname.c
C:\temp\ccmcT7xy.o:gethostname.c:(.text+0x31):
  undefined reference to `GetComputerNameExA'
collect2.exe: error: ld returned 1 exit status

msys $ gcc --version
gcc.exe (GCC) 4.8.1
Copyright (C) 2013 Free Software Foundation, Inc.

msys $ uname -a
MINGW32_NT-6.1 CARL 1.0.17(0.48/3/2) 2011-04-24 23:39 i686 Msys

========

------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: undefined reference to `GetComputerNameExA'

Greg Jung
The headers are there, in winbase.h; here is a collection of how I compile:

        -lshlwapi  -lws2_32 \
        -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32

some of that won't be needed, of course.

On Sat, Feb 7, 2015 at 10:29 AM, Carl Sturtivant <[hidden email]> wrote:
New to in-depth use of MinGW. But it's clearly the right thing!

According to MSDN GetComputerNameExA is in kernel32.dll ,
yet the following program compiles but does not link with my MinGW
installation. Adding -lkernel32 doesn't help. Details below. Any
suggestions how I can get linkage?

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

int main() {
  char buf[1024];
  DWORD sz = 1024;
  //GetComputerNameA( buf, &sz);
  GetComputerNameExA( 1, buf, &sz);
  printf( "\"%s\"\n", buf);
}
========

msys $ gcc -o gethostname gethostname.c
C:\temp\ccmcT7xy.o:gethostname.c:(.text+0x31):
  undefined reference to `GetComputerNameExA'
collect2.exe: error: ld returned 1 exit status

msys $ gcc --version
gcc.exe (GCC) 4.8.1
Copyright (C) 2013 Free Software Foundation, Inc.

msys $ uname -a
MINGW32_NT-6.1 CARL 1.0.17(0.48/3/2) 2011-04-24 23:39 i686 Msys

========

------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe


------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: undefined reference to `GetComputerNameExA'

Carl Sturtivant
On 2/7/2015 1:10 PM, Greg Jung wrote:
> The headers are there, in winbase.h; here is a collection of how I compile:
>
>         -lshlwapi  -lws2_32 \
>         -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32
> -loleaut32 -luuid -lcomdlg32 -ladvapi32
>
> some of that won't be needed, of course.

It's linkage I need. I put all these on the command line and it still
doesn't link.




------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: undefined reference to `GetComputerNameExA'

Eli Zaretskii
In reply to this post by Carl Sturtivant
> Date: Sat, 07 Feb 2015 12:29:32 -0600
> From: Carl Sturtivant <[hidden email]>
>
> #include <windows.h>
> #include <stdio.h>
>
> int main() {
>   char buf[1024];
>   DWORD sz = 1024;
>   //GetComputerNameA( buf, &sz);
>   GetComputerNameExA( 1, buf, &sz);
>   printf( "\"%s\"\n", buf);
> }
> ========
>
> msys $ gcc -o gethostname gethostname.c
> C:\temp\ccmcT7xy.o:gethostname.c:(.text+0x31):
>   undefined reference to `GetComputerNameExA'
> collect2.exe: error: ld returned 1 exit status

The prototype of GetComputerNameExA is guarded by

  #if (_WIN32_WINNT >= 0x0500)

So you need to

  #define _WIN32_WINNT 0x0500

before including <window.h>.

------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: undefined reference to `GetComputerNameExA'

Carl Sturtivant
>
> The prototype of GetComputerNameExA is guarded by
>
>   #if (_WIN32_WINNT >= 0x0500)
>
> So you need to
>
>   #define _WIN32_WINNT 0x0500
>
> before including <window.h>.

This worked, thank you!





------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe