Bug #44931 Missing includes
Submitted: 18 May 2009 12:04 Modified: 3 Aug 2009 11:56
Reporter: Michal Hrusecky Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / C++ Severity:S3 (Non-critical)
Version:1.0.5 OS:Linux
Assigned to: Ulf Wendel CPU Architecture:Any
Tags: Contribution

[18 May 2009 12:04] Michal Hrusecky
Description:
I tried to compile MySQL Connector/C++ using gcc 4.4 and I found that some files were missing stdio.h include files. For details see attached patch.

How to repeat:
Try to compile MySQL Connector/C++ using gcc 4.4

Suggested fix:
Index: driver/mysql_art_resultset.cpp
===================================================================
--- driver/mysql_art_resultset.cpp.orig
+++ driver/mysql_art_resultset.cpp
@@ -16,6 +16,7 @@
 
 #include <cppconn/exception.h>
 #include <sstream>
+#include <stdio.h>
 #include <math.h>
 
 
Index: driver/mysql_prepared_statement.cpp
===================================================================
--- driver/mysql_prepared_statement.cpp.orig
+++ driver/mysql_prepared_statement.cpp
@@ -10,6 +10,7 @@
 */
 #include <string.h>
 #include <stdlib.h>
+#include <stdio.h>
 #include <memory>
 #include <iostream>
 #include <sstream>
Index: test/unit/classes/resultsetmetadata.cpp
===================================================================
--- test/unit/classes/resultsetmetadata.cpp.orig
+++ test/unit/classes/resultsetmetadata.cpp
@@ -15,6 +15,7 @@
 #include "resultsetmetadata.h"
 #include <sstream>
 #include <stdlib.h>
+#include <stdio.h>
 #include <cppconn/resultset.h>
 #include <cppconn/datatype.h>
 #include <cppconn/prepared_statement.h>
[18 May 2009 12:54] Sveta Smirnova
Thank you for the report.

Yes, references to stdio.h are not exist. But everything compiles fine in my environment.

Additionally version 1.0.4 is a bit old. Please try current version 1.0.5 and if problem still exists provide your compile log.
[21 May 2009 15:22] Michal Hrusecky
Compilation log (version 1.0.5 - interesting parts only)

Attachment: compile.log (application/octet-stream, text), 3.20 KiB.

[21 May 2009 15:23] Michal Hrusecky
Patch against 1.0.5

Attachment: mysql-connector-cpp-1.0.5-gcc44.patch (application/octet-stream, text), 1003 bytes.

[21 May 2009 15:26] Michal Hrusecky
I updated patch against version 1.0.5. I guess that problem depends on gcc version (I'm using version 4.4.0).
[22 May 2009 6:30] Sveta Smirnova
Thank you for the feedback.

I use same gcc of same version:

$gcc --version
gcc (GCC) 4.4.0 20081128 (experimental)
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[22 May 2009 7:08] Sveta Smirnova
Same results on another box - build succeeds. Could you please provide cmake output also?
[22 May 2009 14:02] Michal Hrusecky
Full log from two different machines

Attachment: log.txt (text/plain), 9.90 KiB.

[22 May 2009 14:09] Michal Hrusecky
I also tried it on other machine with same result - it doesn't compile with gcc 4.4.0, with 4.3.x everything is ok. I guess I've got newer gcc :-) Output from both machines included. I'm not very familiar with cmake, but I can provide you with any addition files.

But my builds fails because of pritnf/snprintf or similar functions which are defined in stdio.h and stdio.h isn't included in any of these files that fails to compile... So I wouldn't suspect cmake for that...
[29 May 2009 8:56] Sveta Smirnova
Thank you for the feedback.

Verified as described. Problem is repeatable only if use latest gcc 4.4.0 on Linux.
[13 Jul 2009 17:17] Ulf Wendel
I have pushed a change to the development version. Will need to check it using GCC 4.4.0.

The development version gets mirrored at https://code.launchpad.net/~mysql/mysql-connector-cpp/trunk .
[15 Jul 2009 8:29] Ulf Wendel
Fixed in trunk, someone needs to review and close the issue. Andrey, Lawrin, - can one of you bite the bullet and review?
[15 Jul 2009 17:16] Lawrenty Novitsky
I would move those stdio inclusions from .h to .cpp. I think there is no need to do that in .h

Besides that, I could find references to snprintf also in mysql_metadata.cpp mysql_ps_resultset.cpp. I think it wouldn't hurt to include stdio everywhere, and not to rely on the fact it included in some other included header.

Otherwise I'm fine with the patch
[3 Aug 2009 11:56] Ulf Wendel
Lawrin, I followed your suggestions. I moved the include into .cpp and checked the other files for including stdio.h. I have pushed my changes into trunk and verified that it compiles. 

The fixes will make it into the next release, which is 1.0.6. It is scheduled for September 2009.