OneLoneCoder / synth

The latest code to make your own virtual sound synthesizer in Windows. Please see the videos associated with this code. Links in the source files.
http://www.onelonecoder.com
365 stars 130 forks source link

Synth not compiling with MinGW-W64 #14

Closed CamelCaseCam closed 3 years ago

CamelCaseCam commented 3 years ago

When I try to compile olcNoiseMaker.h, g++ gives the following errors: D:\Development\Cpp\BuildTools\Compiler\mingw64\bin\g++.exe -g D:\Development\Cpp\Synth\main.cpp -o D:\Development\Cpp\Synth\main.exe In file included from D:\Development\Cpp\Synth\main.cpp:6: D:\Development\Cpp\Synth\olcNoiseMaker.h: In member function 'bool olcNoiseMaker::Create(std::cxx11::wstring, unsigned int, unsigned int, unsigned int, unsigned int)': D:\Development\Cpp\Synth\olcNoiseMaker.h:95:67: error: no matching function for call to 'find(std::vector<std::cxx11::basic_string >::iterator, std::vector<std::cxx11::basic_string >::iterator, std::cxx11::wstring&)'

I'm able to solve these errors by adding #include \, but then these errors appear: D:\Development\Cpp\BuildTools\Compiler\mingw64\bin\g++.exe -g D:\Development\Cpp\Synth\main.cpp -o D:\Development\Cpp\Synth\main.exe In file included from D:\Development\Cpp\Synth\main.cpp:4: D:\Development\Cpp\Synth\olcNoiseMaker.h: In static member function 'static std::vector<std::cxx11::basic_string > olcNoiseMaker::Enumerate()': D:\Development\Cpp\Synth\olcNoiseMaker.h:176:35: error: no matching function for call to 'std::vector<std::cxx11::basic_string >::push_back(CHAR [32])' sDevices.push_back(woc.szPname); ^ In file included from D:/Development/Cpp/BuildTools/Compiler/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/vector:64, from D:\Development\Cpp\Synth\olcNoiseMaker.h:50, from D:\Development\Cpp\Synth\main.cpp:4: D:/Development/Cpp/BuildTools/Compiler/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/stl_vector.h:1074:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::cxx11::basic_string; _Alloc = std::allocator<std::__cxx11::basic_string >; std::vector<_Tp, _Alloc>::value_type = std::cxx11::basic_string]' push_back(const value_type& x) ^~~~~ D:/Development/Cpp/BuildTools/Compiler/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/stl_vector.h:1074:7: note: no known conversion for argument 1 from 'CHAR [32]' {aka 'char [32]'} to 'const value_type&' {aka 'const std::__cxx11::basic_string&'} D:/Development/Cpp/BuildTools/Compiler/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/stl_vector.h:1090:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::cxx11::basic_string; _Alloc = std::allocator<std::cxx11::basic_string >; std::vector<_Tp, _Alloc>::value_type = std::cxx11::basic_string]' push_back(value_type&& x) ^~~~~ D:/Development/Cpp/BuildTools/Compiler/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/stl_vector.h:1090:7: note: no known conversion for argument 1 from 'CHAR [32]' {aka 'char [32]'} to 'std::vector<std::__cxx11::basic_string >::value_type&&' {aka 'std::cxx11::basic_string&&'} auto d = std::find(devices.begin(), devices.end(), sOutputDevice); ^ In file included from D:/Development/Cpp/BuildTools/Compiler/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/locale_facets.h:48, from D:/Development/Cpp/BuildTools/Compiler/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/basic_ios.h:37, from D:/Development/Cpp/BuildTools/Compiler/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/ios:44, from D:/Development/Cpp/BuildTools/Compiler/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/ostream:38, from D:/Development/Cpp/BuildTools/Compiler/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/iostream:39, from D:\Development\Cpp\Synth\main.cpp:1: D:/Development/Cpp/BuildTools/Compiler/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/streambuf_iterator.h:368:5: note: candidate: 'template typename gnu_cxx::__enable_if<std::is_char<_CharT2>::value, std::istreambuf_iterator<_CharT> >::type std::find(std::istreambuf_iterator<_CharT>, std::istreambuf_iterator<_CharT>, const _CharT2&)' find(istreambuf_iterator<_CharT> first, ^~~~ D:/Development/Cpp/BuildTools/Compiler/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/streambuf_iterator.h:368:5: note: template argument deduction/substitution failed: In file included from D:\Development\Cpp\Synth\main.cpp:6: D:\Development\Cpp\Synth\olcNoiseMaker.h:95:67: note: 'gnu_cxx::__normal_iterator<std::cxx11::basic_string*, std::vector<std::cxx11::basic_string > >' is not derived from 'std::istreambuf_iterator<_CharT>' auto d = std::find(devices.begin(), devices.end(), sOutputDevice);

My experience is with C#, so what does all this mean?

CamelCaseCam commented 3 years ago

I was able to fix the above errors by adding "-lwinmm" to the tasks.json file, but now it's trying to convert a char array to a wstring

CamelCaseCam commented 3 years ago

Ok, here is my working solution for compiling this with vscode and MinGW-w64:

  1. add "-lwinmm" to args in tasks.json
  2. add #include \ to olcNoiseMaker.h
  3. add this function to the olcNoiseMaker class: static std::wstring s2ws(const std::string& str) { int size_needed = MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), NULL, 0); std::wstring wstrTo( size_needed, 0 ); MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), &wstrTo[0], size_needed); return wstrTo; } (not my code, just something I found on stackoverflow)
  4. inside Enumerate() change "sDevices.push_back(woc.szPname);" to "sDevices.push_back(s2ws(std::string(woc.szPname)));"

I hope this helps someone