Author Topic: LIB files HowTo  (Read 10009 times)

Offline russellman

  • Single posting newcomer
  • *
  • Posts: 3
LIB files HowTo
« on: March 28, 2006, 11:53:08 pm »
  I have code block ver 1 rc 2, windows xp, GNU gcc compileer, and MinGw.

I wount to use PlaySound() it's header is #include <mmsystem.h> The lib is winmm.lib .

In visual c++ 6 to add a lib to code you.

#include <mmsystem.h>                  //include the HEADER file for PlaySound().
#pragma comment(lib,"Winmm.lib")   //include the LIB file for PlaySound().

Then you can use PlaySound().

How do you do it in code::block ver 1 rc 2?

Gary Russell
[email protected]

Offline TDragon

  • Lives here!
  • ****
  • Posts: 943
    • TDM-GCC
Re: LIB files HowTo
« Reply #1 on: March 29, 2006, 12:21:20 am »
Most standard Platform SDK libraries (including winmm) are included in MinGW with the .a extension. So you would use either #pragma comment(lib,"libwinmm.a"), or the more portable method of adding "winmm" to the list of libraries to link (found in your project's Build Options).
https://jmeubank.github.io/tdm-gcc/ - TDM-GCC compiler suite for Windows (GCC 9.2.0 2020-03-08, 32/64-bit, no extra DLLs)

Offline russellman

  • Single posting newcomer
  • *
  • Posts: 3
Re: LIB files HowTo
« Reply #2 on: March 29, 2006, 01:07:48 am »
When I add #pragma comment(lib,"libwinmm.a") I get

error
mingw32-g++.exe: .objs\lib\libwinmm.o: No such file or directory

(found in your project's Build Options). I tried it too.

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: LIB files HowTo
« Reply #3 on: March 29, 2006, 01:11:03 am »
#pragma comment(lib,"Winmm.lib") is a non-standard Microsoft feature (felony).
No IDE supports this, and this is a common stumbling block when using any other IDE.

You have to add the link libraries in the project's linker options (on the left side of that dialog). It is normally not necessary to worry about the extension, in most cases the base name will do (the IDE takes care of the rest).

An alternative for gcc is to specify the libraries by giving the -l flag in "additional options" (but forget about that, it is a lot more comfortable to let the IDE do the dirty work).
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline TDragon

  • Lives here!
  • ****
  • Posts: 943
    • TDM-GCC
Re: LIB files HowTo
« Reply #4 on: March 29, 2006, 01:17:45 am »
No IDE supports this, and this is a common stumbling block when using any other IDE.
Not sure exactly what you mean by this, but DMC supports #pragma comment(lib, "..."). I'm too lazy to check whether GCC does, so I'll assume it doesn't. Whatever the case, it is indeed an inappropriate and error-prone way of specifying link libraries.
https://jmeubank.github.io/tdm-gcc/ - TDM-GCC compiler suite for Windows (GCC 9.2.0 2020-03-08, 32/64-bit, no extra DLLs)

Offline russellman

  • Single posting newcomer
  • *
  • Posts: 3
Re: LIB files HowTo
« Reply #5 on: March 29, 2006, 01:24:37 am »
Russellman hear.

Hears how it worked. I added #pragma comment(lib,"libwinmm.a")

and removed the link libraries in the project's linker options (on the left side of that dialog).

and it works.

In Borland you only link libraries in the project's linker options. If thay did not come with the compiler. One you made or 3ed party.

Gary thinks.

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: LIB files HowTo
« Reply #6 on: March 29, 2006, 09:17:06 am »
Quote
Not sure exactly what you mean by this
What I mean is that this is a non-standard functionality which is a regular source of problems for MS users trying to move to anything else that is not MS. Users are being taught to do something which is not only obscure and error prone, but which effectively prevents them from using another system. I remember at least a dozen people complaining about this very problem in the past.
The point is not whether it accidentially works with one compiler or the other, the point is that it is wrong and evil.

Quote
Hears how it worked. I added #pragma comment(lib,"libwinmm.a")
and removed the link libraries in the project's linker options (on the left side of that dialog).
You should do the opposite, even if it appears to work that way. You should specify link libraries in the project options and not in a #pragma.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline TDragon

  • Lives here!
  • ****
  • Posts: 943
    • TDM-GCC
Re: LIB files HowTo
« Reply #7 on: March 29, 2006, 04:28:19 pm »
The point is not whether it accidentially works with one compiler or the other, the point is that it is wrong and evil.
True dat. I apologize for nitpicking. :)
https://jmeubank.github.io/tdm-gcc/ - TDM-GCC compiler suite for Windows (GCC 9.2.0 2020-03-08, 32/64-bit, no extra DLLs)