| Bug #34341 | Error compiling source when HAVE_CHARSET_cp932 not defined | ||
|---|---|---|---|
| Submitted: | 6 Feb 2008 6:31 | Modified: | 21 Mar 2011 20:17 |
| Reporter: | Alexander Pravdin | Email Updates: | |
| Status: | Closed | Impact on me: | |
| Category: | MySQL Server: Compiling | Severity: | S3 (Non-critical) |
| Version: | 5.0.45 and higher | OS: | Any |
| Assigned to: | Hery Ramilison | CPU Architecture: | Any |
| Tags: | HAVE_CHARSET_cp932;compiling | ||
[12 Feb 2008 15:25]
MySQL Verification Team
Thank you for the bug report. Could you please describe the exact steps you did to compile the source and which VS version are you using. Thanks in advance.
[13 Feb 2008 1:26]
Alexander Pravdin
I'm using VS 2005. I cleared the solution from intermadiate files, replaced libmysql\charset.c and mysys\charset.c by original ones and started reproducing my build steps.
First I commented unneeded charsets in config-win.h and leave only cp1251, latin1 and utf8 charsets. Then started build process and gave many errors such as these:
Error 154 error LNK2001: unresolved external symbol _my_charset_cp932_japanese_ci mysys.lib
Error 155 fatal error LNK1120: 1 unresolved externals c:\work\mysql\client\debug\mysqlshow.exe 1
Error 156 error LNK2001: unresolved external symbol _my_charset_cp932_japanese_ci mysys.lib
Error 157 fatal error LNK1120: 1 unresolved externals c:\work\mysql\client\debug\mysql_upgrade.exe 1
Error 159 error LNK2001: unresolved external symbol _my_charset_cp932_japanese_ci mysys.lib
Error 160 fatal error LNK1120: 1 unresolved externals c:\work\mysql\client\debug\mysqlimport.exe 1
Error 161 error LNK2001: unresolved external symbol _my_charset_cp932_japanese_ci mysys.lib
Error 162 fatal error LNK1120: 1 unresolved externals c:\work\mysql\extra\debug\perror.exe 1
Using text search in the sources I found symbol my_charset_cp932_japanese_ci is used in following c-files:
libmysql\charset-def.c
libmysql\charset.c
libmysql\ctype-cp932.c
mysys\charset-def.c
mysys\charset.c
strings\ctype-cp932.c
Files with same names are identical so I view each pair as one file and modify (if needed) both files concurrently.
In the file charset-def.c using of the my_charset_cp932_japanese_ci is escaped:
#ifdef HAVE_CHARSET_cp932
add_compiled_collation(&my_charset_cp932_japanese_ci);
add_compiled_collation(&my_charset_cp932_bin);
#endif
So, we have no error here because HAVE_CHARSET_cp932 not defined in config-win.h. In the file ctype-cp932.c definition of the my_charset_cp932_japanese_ci is escaped too by condition #ifdef HAVE_CHARSET_cp932 in line 23. But in the file charset.c we have no escaping in lines 709, 710, so compiler compile reference to the symbol but linker did not find the definition.
Because we did not use the cp932 charset in my case and other places where we use it are escaped, I add the preprocessor condition to escape using my_charset_cp932_japanese_ci when HAVE_CHARSET_cp932 is not defined:
Lines 709, 710 in the charset.c I replaced by these lines:
fs_cset_cache=
#ifdef HAVE_CHARSET_cp932
!strcmp(buf, "cp932") ? &my_charset_cp932_japanese_ci :
#endif
&my_charset_bin;
After all these steps the solution was compiled successfully.
PS: I found the charset.c file which present in projects libmysql and mysys in the solution is located at one place mysys\charset.c, so duplicate file libmysql\charset.c is never used in any project. I think something should be fixed to decrease file duplicating.
[13 Feb 2008 10:04]
Susanne Ebrecht
Sorry, but I can't see the bug here. Maybe I missunderstood you. I understood: 1) You changed our source code 2) The linker got confused and chooses the wrong files, because the linker didn't know exactly, where to find dependencies. 3) At least, you found a solution, how to fix the changes, that you made at the original code. 4) The original code compiled and works fine. Where is the bug? Please, correct me, if I understood something wrong.
[13 Feb 2008 10:44]
Susanne Ebrecht
Sorry, the description wasn't clear to me. I just talked to our developer and he can see the bug. Verified by checking the source code for 5.0.45 and latest bk tree for 5.0.
[21 Mar 2011 20:17]
Hery Ramilison
Committed revision 3305.

Description: I tried to compile the sources with commented definition "#define HAVE_CHARSET_cp932 1" (no need this charset) in config-win.h and got error in "charset.c" in the function "fs_character_set" with referencing to variable "my_charset_cp932_japanese_ci". Think it will be under any OS. How to repeat: Comment the line #define HAVE_CHARSET_cp932 in include\config-win.h Suggested fix: CHARSET_INFO *fs_character_set() { if (!fs_cset_cache) { char buf[10]= "cp"; GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_IDEFAULTANSICODEPAGE, buf+2, sizeof(buf)-3); /* We cannot call get_charset_by_name here because fs_character_set() is executed before LOCK_THD_charset mutex initialization, which is used inside get_charset_by_name. As we're now interested in cp932 only, let's just detect it using strcmp(). */ fs_cset_cache= #ifdef HAVE_CHARSET_cp932 !strcmp(buf, "cp932") ? &my_charset_cp932_japanese_ci : #endif &my_charset_bin; } return fs_cset_cache; }