1

I am receiving the following errors in my win32 api code in devc++:

[Linker error] undefined reference to `EnumProcessModules@16' 

[Linker error] undefined reference to `GetModuleFileNameExA@16'

ld returned 1 exit status 

How can I solve this problem? I tried using

#pragma comment(lib, "psapi.lib")

since it was a linker issue but it did not help whatsoever.

Mysticial
  • 464,885
  • 45
  • 335
  • 332
Bhubhu Hbuhdbus
  • 1,489
  • 6
  • 24
  • 31

2 Answers2

0

For future reference I got it to work in CMake as follows, credit goes to Chibueze Opata:

find_library (PSAPI Psapi)

...

add_executable(...)

...

target_link_libraries(Basic -lpsapi)

Halcyon
  • 1,376
  • 1
  • 15
  • 22
-2

Link with the library that provides the missing functions.

As mentioned in the question comments, g++ (which most likely is the compiler that you’re using with DevC++) does unfortunately not support #pragma comment.

Also, as mentioned in the question comments, DevC++ is a rather outdated and ungood IDE. Since you are using Windows, try out e.g. Code::Blocks IDE for the g++ compiler, or Microsoft’s Visual C++ Express IDE for Visual C++. And with the latter you can use the #pragma, if you want…

Cheers and hth. - Alf
  • 142,714
  • 15
  • 209
  • 331
  • 8
    The right answer is to add `-lpsapi` to the linker options. – Chibueze Opata Aug 09 '14 at 19:34
  • @ChibuezeOpata: no, that's not the "right" answer at all; it is of negative utility. you might benefit from exploring ["Give a man a fish"](http://bit.ly/19IxXJA). or perhaps not, i don't know. – Cheers and hth. - Alf Aug 09 '14 at 20:00
  • Yes, [we can agree to disagree](http://orwelldevcpp.blogspot.com/) when you put any of your suggestions on a USB. – Chibueze Opata Aug 09 '14 at 20:35
  • @ChibuezeOpata: I guess you're the [ignorant](http://bit.ly/1omw6o1) downvoter. Jeez. Could you not think of anything better to do than to vandalize a perfectly good answer and then downvote it. – Cheers and hth. - Alf Aug 10 '14 at 04:20
  • 1
    Your answer is not perfectly good. Kindly include the actual answer with your personal suggestion and I will revise my downvote. Nothing of what you mentioned in your answer solves the problem neither is DevCPP so bad or 'ungood'. – Chibueze Opata Aug 11 '14 at 00:27