Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build on Windows Machine #4

Open
AmRo045 opened this issue Jan 3, 2021 · 3 comments
Open

Build on Windows Machine #4

AmRo045 opened this issue Jan 3, 2021 · 3 comments

Comments

@AmRo045
Copy link

AmRo045 commented Jan 3, 2021

How can I build this library on the Windows machine?

make command output on Windows 10:

g++ -std=c++11 -Wall -pedantic -c utils/utilities.cpp -o build/utilities.o
utils/utilities.cpp: In function 'int readMapFromFile(std::__cxx11::string, std::map<std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >*)':
utils/utilities.cpp:221:35: error: no matching function for call to 'getline(char**, size_t*, FILE*&)'
   while (getline(&buf, &buflen, fp) > 0) {
                                   ^
In file included from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\string:53:0,
                 from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\stdexcept:39,
                 from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\array:39,
                 from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\tuple:39,
                 from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_map.h:63,
                 from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\map:61,
                 from utils/utilities.hpp:4,
                 from utils/utilities.cpp:1:
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\basic_string.tcc:1509:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::basic_istream<_CharT, _Traits>& std::getline(std::basic_istream<_CharT, _Traits>&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, _CharT)
     getline(basic_istream<_CharT, _Traits>& __in,
     ^~~~~~~
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\basic_string.tcc:1509:5: note:   template argument deduction/substitution failed:
utils/utilities.cpp:221:35: note:   mismatched types 'std::basic_istream<_CharT, _Traits>' and 'char**'
   while (getline(&buf, &buflen, fp) > 0) {
                                   ^
In file included from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\string:52:0,
                 from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\stdexcept:39,
                 from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\array:39,
                 from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\tuple:39,
                 from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_map.h:63,
                 from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\map:61,
                 from utils/utilities.hpp:4,
                 from utils/utilities.cpp:1:
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\basic_string.h:5365:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::basic_istream<_CharT, _Traits>& std::getline(std::basic_istream<_CharT, _Traits>&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)
     getline(basic_istream<_CharT, _Traits>& __is,
     ^~~~~~~
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\basic_string.h:5365:5: note:   template argument deduction/substitution failed:
utils/utilities.cpp:221:35: note:   mismatched types 'std::basic_istream<_CharT, _Traits>' and 'char**'
   while (getline(&buf, &buflen, fp) > 0) {
                                   ^
In file included from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\string:52:0,
                 from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\stdexcept:39,
                 from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\array:39,
                 from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\tuple:39,
                 from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_map.h:63,
                 from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\map:61,
                 from utils/utilities.hpp:4,
                 from utils/utilities.cpp:1:
aits, class _Alloc> std::basic_istream<_CharT, _Traits>& std::getline(std::basic_istream<_CharT, _Traits>&&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, _CharT)
     getline(basic_istream<_CharT, _Traits>&& __is,
     ^~~~~~~
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\basic_string.h:5373:5: note:   template argument deduction/substitution failed:
utils/utilities.cpp:221:35: note:   mismatched types 'std::basic_istream<_CharT, _Traits>' and 'char**'
   while (getline(&buf, &buflen, fp) > 0) {
                                   ^
In file included from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\string:52:0,
                 from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\stdexcept:39,
                 from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\array:39,
                 from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\tuple:39,
                 from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_map.h:63,
                 from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\map:61,
                 from utils/utilities.hpp:4,
                 from utils/utilities.cpp:1:
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\basic_string.h:5380:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::basic_istream<_CharT, _Traits>& std::getline(std::basic_istream<_CharT, _Traits>&&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)
     getline(basic_istream<_CharT, _Traits>&& __is,
     ^~~~~~~
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\basic_string.h:5380:5: note:   template argument deduction/substitution failed:
utils/utilities.cpp:221:35: note:   mismatched types 'std::basic_istream<_CharT, _Traits>' and 'char**'
   while (getline(&buf, &buflen, fp) > 0) {
                                   ^
make: *** [makefile:22: build/utilities.o] Error 1
@hadisfr
Copy link
Member

hadisfr commented Jan 4, 2021

Hi!
Unfortunately, we do not support Windows and MinGW officially.
It seems that we have used non-POSIX gcc-specific old-C-style getline there, which is not available in MinGW (See https://stackoverflow.com/q/27381903).
If you have found any workaround, merge-requests are appreciated. :D

Do you have any solution? 🤔 @gsoosk @sadmanbrad

@AmRo045
Copy link
Author

AmRo045 commented Jan 4, 2021

I think we can change the implementation of readMapFromFile method from this:

APHTTP/utils/utilities.cpp

Lines 209 to 246 in 03a8239

int readMapFromFile(std::string fname, std::map<std::string, std::string> *m) {
int count = 0;
FILE *fp = fopen(fname.c_str(), "r");
if (!fp)
return -errno;
m->clear();
char *buf = 0;
size_t buflen = 0;
while (getline(&buf, &buflen, fp) > 0) {
char *nl = strchr(buf, '\n');
if (nl == NULL)
continue;
*nl = 0;
char *sep = strchr(buf, '=');
if (sep == NULL)
continue;
*sep = 0;
sep++;
std::string s1 = buf;
std::string s2 = sep;
(*m)[s1] = s2;
count++;
}
if (buf)
free(buf);
fclose(fp);
return count;
}

to this:

int readMapFromFile(std::string fname, std::map<std::string, std::string> *m) {
  ifstream inputStream(fname);
  std::string line;

  if (inputStream.fail())
    return -errno;

  while (getline(inputStream, line)) {
    auto tokens = tokenize(line, '=');
    //     KEY         VALUE
    (*m)[tokens[0]] = tokens[1];
  }

  return (*m).size();
}

@hadisfr
Copy link
Member

hadisfr commented Jan 5, 2021

Thank you. Your code seems much cleaner than the old one. :D I did not remember internals of library, so I'll ask someone else to review it and apply the patch if everything is OK. A MR will be appreciated, too. :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants