I want to compile a C++ program that includes & uses the mutex library, with G++ via the Command Prompt on a Windows system. I'm attempting to compile with C++ 17.
My version of G++ is g++
(MinGW.org GCC-6.3.0-1) 6.3.0
.
I'm normally able to compile simple programs via the
g++
command on any Command Prompt. However, attempting to compile the following example file
test.cpp
:
1 2 3 4 5 6 7 8 9 10 11
|
#include <iostream>
#include <mutex>
std::mutex mut;
int main()
{
std::cout << "test\n";
return 0;
}
| |
With the following command:
|
g++ -std=c++17 test.cpp -o test
| |
Results in:
1 2 3
|
test.cpp:4:6: error: 'mutex' in namespace 'std' does not name a type
std::mutex mut;
^~~~~
| |
My understanding of this is what I need to supply a flag for the linker to link the library when issuing a build command with G++, however I'm not quite sure what that flag is for
mutex
and where to place it in the build command.
What is the linker flag required to supply to G++ to compile a C++ file that includes
mutex
?
Thanks for reading my post, any guidance is appreciated.