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

Building on Windows fails, missing xlocale.h #33

Closed
eldar opened this issue Aug 23, 2013 · 5 comments
Closed

Building on Windows fails, missing xlocale.h #33

eldar opened this issue Aug 23, 2013 · 5 comments

Comments

@eldar
Copy link

eldar commented Aug 23, 2013

I am building QJson with MSVC 2010 and I get the following error:

c:\projects\qjson\src\json_scanner.h:37: error: C1083: Cannot open include file: 'xlocale.h': No such file or directory

However there is a header called xlocale, so I changed the include. But then it complains that there are no symbols "locale_t" and "newlocale". Is it supposed to build with Microsoft compilers at all?

@JFF-Bohdan
Copy link

The same problem with mingw (with Qt 5.1.1). I fixed it by using QLocale instead of locale_t. If you interested in this - I can make little patch.

@flavio
Copy link
Owner

flavio commented Oct 2, 2013

I would rather prefer to find the right header which provides localte_t under windows :)

BTW, it would be nice to see your patch. Maybe you can attach it here.

@JFF-Bohdan
Copy link

Hi.

It's not a problem to find xlocale, there is other problem with linking. So I noted all my steps in both way (one for xlocale and other for QLocale).
(I works under Win 7 (x64) with Qt 5.1.1 (x32) and mingw 4.8 and compiles using qmake and own .pro file which I can send to you if you want).

=== Way 1. Looking for < xlocale >. ===

json_scanner.h:
#ifdef Q_OS_WIN
#include < xlocale >
#define locale_t _locale_t
#define freelocale _free_locale
#else
#include < xlocale.h >
#endif

line number 39 #include < xlocale > can be disabled, because all needful functions can be found in < locale.h > (included at line 36). When you will disable it, you will got messages
json_scanner.yy: -1 : In member function 'virtual int JSonScanner::yylex()':
json_scanner.yy: 106 : error: 'strtod_l' was not declared in this scope

So, let's go deeper.
We have no strtod_l(), but we have _strtod_l(). As I see, you tuning defines at line 3158:
#if defined(_WIN32) && !defined(MINGW32)
#define strtoll _strtoi64
#define strtoull _strtoui64
#define strtod_l _strtod_l
#endif

And strtod_l() disabled for MINGW32, but at my machine we have no predefined strtod_l() so we need to define it.

After all these steps you will got problems with linking:

json_scanner.o: -1 : In function ZN11JSonScannerC2EP9QIODevice': json_scanner.cpp: 41 : error: undefined reference to_create_locale'
In function ZN11JSonScannerD2Ev': json_scanner.cpp: 49 : error: undefined reference to_free_locale'
collect2.exe: -1 : error: error: ld returned 1 exit status

I tried to solve this problem by reading MSDN and found .dll file to link, but I was failed. So I you find what library we need to link with QJson it can work and fix problem.

=== Way 2. Fixing with QLocale===
After this I tried to understand why do we need to use xlocale and fixed problem with these steps:

  1. Adding QLocale to json_scanner.h:

#include < QLocale >
class JSonScanner : public yyFlexLexer
...

  1. Changing locale_t to QLocale
    locale_t m_C_locale; -> QLocale m_C_locale;
  2. Refactoring in JSonScanner::JSonScanner() and JSonScanner::~JSonScanner():

JSonScanner::JSonScanner(QIODevice* io)
: m_allowSpecialNumbers(false),
m_io (io),
m_criticalError(false),
m_C_locale(QLocale::C)
{
//stub
}

JSonScanner::~JSonScanner()
{
//stub
}

  1. Looking of all usages of m_C_locale I found just one.
    In json_scanner.cc:3425:
    Changing
    *m_yylval = QVariant(_strtod_l(yytext, NULL, m_C_locale));
    to
    *m_yylval = QVariant(m_C_locale.toDouble(QLatin1String(yytext)));

After these steps I got successful compilation and linking.

But I have one question. As I see, you uses m_C_locale for deserializing double but do we also need to use it for serialization?

Hope it will be useful for you.

Also, please help me with issue "Problem when trying to parse simple Json" (#39).

When I uses successfully compiled library and tries to parse simple JSON I have problem "json syntax error, unexpected invalid 4". As I told in issue, my JSON is very simple and looks like this:

{
"fields" : [
{
"index" : 2,
"name" : "category_weight",
"type" : 2
},
{
"index" : 1,
"name" : "category_name",
"type" : 10
},
{
"index" : 0,
"name" : "category_id",
"type" : 2
}
]
}

If you want, I can make little code which generates this JSON and then falls when tries to deserialize it.

Sorry for my English.

Best regards, Bohdan.

@drizt
Copy link
Contributor

drizt commented Nov 11, 2013

I can't compile my project with Qt-4.8.5-mingw

$ make
Scanning dependencies of target qjson
[ 9%] Building CXX object src/CMakeFiles/qjson.dir/parser.cpp.obj
In file included from json_parser.yy:28:0,
from c:/MinGW/msys/1.0/home/User/qjson/src/parser.cpp:23:
c:/MinGW/msys/1.0/home/User/qjson/src/json_scanner.h:39:19: fatal error: xlocale: No such file or directory
compilation terminated.
make[2]: *** [src/CMakeFiles/qjson.dir/parser.cpp.obj] Error 1
make[1]: *** [src/CMakeFiles/qjson.dir/all] Error 2
make: *** [all] Error 2

@flavio
Copy link
Owner

flavio commented Jan 25, 2014

This has been fixed by PR#44

@flavio flavio closed this as completed Jan 25, 2014
syncmage pushed a commit to sourcemage/grimoire that referenced this issue Aug 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants