Discussion:
[Mingw-users] Can't find GetProcessMemoryInfo when linking
Michael Garcia
2011-02-22 16:36:11 UTC
Permalink
Hi,

I'm trying to use GetProcessMemoryInfo() to get memory usage for my app. I
include psapi.h and -lpsapi when I link but I get the error message:

undefined reference to '***@12'

I use other Win API methods like GetCurrentProcessId() and OpenProcess() and
those don't generate link errors. Any idea what I might be doing wrong?

Thanks,
-Mike
Luis Lavena
2011-02-22 17:08:00 UTC
Permalink
On Tue, Feb 22, 2011 at 1:36 PM, Michael Garcia
Hi,
I'm trying to use GetProcessMemoryInfo() to get memory usage for my app.  I
I use other Win API methods like GetCurrentProcessId() and OpenProcess() and
those don't generate link errors.  Any idea what I might be doing wrong?
Can you provide the linking options? I found that gcc or g++ is quite
particular when linking files, and -l options needs to be added to the
end instead of the beginning of the command line.

Does that makes sense?
--
Luis Lavena
AREA 17
-
Perfection in design is achieved not when there is nothing more to add,
but rather when there is nothing more to take away.
Antoine de Saint-Exupéry
Michael Garcia
2011-02-22 22:44:15 UTC
Permalink
Here's my link command:
g++ -pipe -g
/cygdrive/p/magarcia_oo_unix/FDA/obj/release/win2k/common/testdrivers/testReports.o
-o /cygdrive/p/magarcia_oo_unix/FDA/exe/release/win2k/testReportGenerator.exe
/cygdrive/p/magarcia_oo_unix/FDA/cots/lib/win2k/XalanTransformer_1_4_0.dll
/cygdrive/p/magarcia_oo_unix/FDA/cots/lib/win2k/xerces-c_2_1_0.dll
-L/cygdrive/p/magarcia_oo_unix/FDA/lib/release/win2k
-L/cygdrive/p/magarcia_oo_unix/FDA/cots/lib/win2k -L/usr/local/lib -ltestdrivers
-lwinverify -lpsapi -lgcc -lstdc++ -lxerces-c2_1_0 -ldtime -ldattr -lnotif
-lthread -ldmisc -lnotify -ltimr -lmisc -lipc -lrpclib -ljvm
/cygdrive/p/magarcia_oo_unix/FDA/lib/release/win2k/libwinverify.a(WinUtils.o.b)(.text+0xde):WinUtils.cc:
undefined reference to `***@12'
collect2: ld returned 1 exit status
Post by Luis Lavena
Can you provide the linking options? I found that gcc or g++ is quite
particular when linking files, and -l options needs to be added to the
end instead of the beginning of the command line.
Does that makes sense?
--
Luis Lavena
AREA 17
-
Perfection in design is achieved not when there is nothing more to add,
but rather when there is nothing more to take away.
Antoine de Saint-Exupéry
Greg Chicares
2011-02-23 02:40:29 UTC
Permalink
Post by Michael Garcia
g++ -pipe -g
/cygdrive/p/magarcia_oo_unix/FDA/obj/release/win2k/common/testdrivers/testReports.o
-o /cygdrive/p/magarcia_oo_unix/FDA/exe/release/win2k/testReportGenerator.exe
Is this Cygwin gcc? I wouldn't expect MinGW gcc to understand '/cygdrive/'.
Post by Michael Garcia
/cygdrive/p/magarcia_oo_unix/FDA/cots/lib/win2k/XalanTransformer_1_4_0.dll
/cygdrive/p/magarcia_oo_unix/FDA/cots/lib/win2k/xerces-c_2_1_0.dll
-L/cygdrive/p/magarcia_oo_unix/FDA/lib/release/win2k
-L/cygdrive/p/magarcia_oo_unix/FDA/cots/lib/win2k -L/usr/local/lib -ltestdrivers
-lwinverify -lpsapi -lgcc -lstdc++ -lxerces-c2_1_0 -ldtime -ldattr -lnotif
Here, '-lpsapi' follows '-lwinverify', which seems correct. It wouldn't
hurt to add '-lpsapi' at the very end of the link command, just to be sure.
Post by Michael Garcia
-lthread -ldmisc -lnotify -ltimr -lmisc -lipc -lrpclib -ljvm
collect2: ld returned 1 exit status
In a minimal test case, with MinGW gcc-3.4.5, I omitted '-lpsapi' and got:
undefined reference to `***@12'
with no underscore before the capital 'G'. Was 'libwinverify.a' built with
the same version of the same compiler as the rest of the code? Does
'WinUtils.cc' provide its own local declaration of GetProcessMemoryInfo(),
instead of including 'psapi.h'?

Earnie
2011-02-22 18:10:36 UTC
Permalink
Post by Michael Garcia
Hi,
I'm trying to use GetProcessMemoryInfo() to get memory usage for my app. I
I use other Win API methods like GetCurrentProcessId() and OpenProcess() and
those don't generate link errors. Any idea what I might be doing wrong?
http://www.mingw.org/wiki/The_linker_consistently_giving_undefined_references
--
Earnie
-- http://www.for-my-kids.com
Loading...