Answer the question
In order to leave comments, you need to log in
Linking with a C++ library?
Hello everyone, here's an example:
#include <iostream>
#include <windows.h>
int main() {
mciSendString("play C:\\WINDOWS\\Media\\onestop.mid", NULL, 0, NULL);
std::cout << "played...\npress enter for stop";
std::cin.get();
mciSendString("stop C:\\WINDOWS\\Media\\onestop.mid", NULL, 0, NULL);
std::cout << "stopped...\npress enter for exit";
std::cin.get();
return 0;
}
#include <iostream>
#include <Windows.h>
#include "MMSystem.h"
using namespace std;
int main()
{
PlaySound(TEXT("LHSRLD11.wav"), NULL, SND_SYNC);
system("pause");
return 0;
}
Answer the question
In order to leave comments, you need to log in
mmsystem.h and winmm.lib are a standard Windows header file and library provided with the Windows SDK, which is included with Visual Studio. mmsystem.h is available from the start in the studio, just use it in #include, you don't need to copy it to your project. winmm.lib is also available, but it must be included in the project - the -lwinmm.lib option of the compiler or set in the project properties as an additional library used if you are using an IDE. It is not enabled by default.
In general, to connect third-party libraries to any C / C ++ project, you need to:
1. add the path where the library header files are located as an option -I<path header files>
to the compiler launch command.
2. add the path where the lib files (lib for msvc) of the library are located to the option-L<path to lib files>
. If there is only one library file, then this step can be skipped and the full path can be specified in step 3. If there are several files, then it is easier to specify the path to the directory in the -L option, and in step 3, specify only the name of a specific library file.
3. add the name of the library file (lib file) to the option -l<lib name>
or the full path to the lib file.
If you are building from the IDE, then the same steps must be done in the project settings. Compiler options are almost universal - the same options (and similar approach) are used in msvc, gcc, clang and other compilers.
For building libraries with a Qt project:
In the pro file:
LIBS variable - compiler options -L and -l are set (p.2 and p.3)
INCLUDEPATH variable - compiler options -I are set (p.1)
For example:
INCLUDEPATH += -Ipath/to/header/files
LIBS += -Lpath/to/lib/files -lmylibfile
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question