Hi, ich brauch mal Hilfe beim Compilieren....
Wie haben uns mal nen NativeTreiber für Java geschnitzt, für MySQL.
Konnte ich vor einem Jahr noch compilieren, damals noch unter gcc2.9x, nun aber auf meiner Gentoo mit gcc3.2 knallts.
Leider hab ich mit C nicht genug am Hut dass ich sagen könnte was verkehrt läuft
Kann mir einer weiterhelfen?
Hier der Code:
C
// NativeMySQL.cpp : Defines the entry point for the DLL application.
//
#include "de_commedia_mysql_NativeConnection.h"
#include "de_commedia_mysql_NativeResultSet.h"
// #include <windows.h>
#include <mysql.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <jni.h>
#include <time.h>
#include <math.h>
// #include <cruntime.h>
// #include <fltintrn.h>
#include <ctype.h>
__int64 __cdecl _atoi64own(const char *nptr, int maxlength);
int __cdecl atoiown(const char *nptr, int maxlength);
double __cdecl atofown(const char *nptr, int maxlength);
/*
* Class: de_commedia_mysql_NativeConnection
* Method: createConnection
* Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I
*/
JNIEXPORT jint JNICALL Java_de_commedia_mysql_NativeConnection_createConnection(JNIEnv *jEnv, jobject jObject, jstring jHost, jstring jDb, jstring jUser, jstring jPassword) {
const char *host = jEnv->GetStringUTFChars(jHost, NULL);
const char *db = jEnv->GetStringUTFChars(jDb, NULL);
const char *user = jEnv->GetStringUTFChars(jUser, NULL);
const char *password = jEnv->GetStringUTFChars(jPassword, NULL);
// printf("using host %s and db %s and user %s and password %s\n", host, db, user, password);
MYSQL *mysql = mysql_init(NULL);
if (mysql != NULL) {
if (mysql_real_connect(mysql, host, user, password, db, 0, NULL, 0) == NULL) {
mysql_close(mysql);
mysql = NULL;
}
}
jEnv->ReleaseStringUTFChars(jHost, host);
jEnv->ReleaseStringUTFChars(jDb, db);
jEnv->ReleaseStringUTFChars(jUser, user);
jEnv->ReleaseStringUTFChars(jPassword, password);
return (jint) mysql;
}
[ SCHNIPP ]
/*
* Class: de_commedia_mysql_NativeResultSet
* Method: close
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_de_commedia_mysql_NativeResultSet_close(JNIEnv *jEnv, jobject jObject, jint jSet) {
MYSQL_RES *resultSet = (MYSQL_RES *) jSet;
if (resultSet != NULL) {
mysql_free_result(resultSet);
}
}
__int64 __cdecl _atoi64own(const char *nptr, int maxlength) {
int c; /* current char */
__int64 total; /* current total */
int sign; /* if '-', then negative, otherwise positive */
int counter = 0;
// printf("maxlength: %d", maxlength);
// printf(" string: %s", nptr);
/* skip whitespace */
while ( isspace((int)(unsigned char)*nptr) ) {
++counter;
++nptr;
}
c = (int)(unsigned char)*nptr++;
++counter;
sign = c; /* save sign indication */
if (c == '-' || c == '+') {
c = (int)(unsigned char)*nptr++; /* skip sign */
++counter;
}
total = 0;
while (isdigit(c) && (counter <= maxlength)) {
total = 10 * total + (c - '0'); /* accumulate digit */
c = (int)(unsigned char)*nptr++; /* get next char */
++counter;
}
if (sign == '-')
return -total;
else
return total; /* return result, negated if necessary */
}
int __cdecl atoiown(const char *nptr, int maxlength) {
int c; /* current char */
int total; /* current total */
int sign; /* if '-', then negative, otherwise positive */
int counter = 0;
/* skip whitespace */
while ( isspace((int)(unsigned char)*nptr) ) {
++nptr;
++counter;
}
c = (int)(unsigned char)*nptr++;
sign = c; /* save sign indication */
if (c == '-' || c == '+') {
c = (int)(unsigned char)*nptr++; /* skip sign */
++counter;
}
total = 0;
while (isdigit(c) && (counter <= maxlength)) {
total = 10 * total + (c - '0'); /* accumulate digit */
c = (int)(unsigned char)*nptr++; /* get next char */
++counter;
}
if (sign == '-')
return -total;
else
return total; /* return result, negated if necessary */
}
double __cdecl atofown(REG1 const char *nptr, int maxlength) {
#ifdef _MT
struct _flt fltstruct; /* temporary structure */
#endif /* _MT */
/* scan past leading space/tab characters */
while ( isspace((int)(unsigned char)*nptr) )
nptr++;
/* let _fltin routine do the rest of the work */
#ifdef _MT
return( *(double *)&(_fltin2( &fltstruct, nptr, maxlength, 0, 0 )->
dval) );
#else /* _MT */
return( *(double *)&(_fltin( nptr, maxlength, 0, 0 )->dval) );
#endif /* _MT */
}
Alles anzeigen
Sorry ist lang...
Da wo SCHNIPP steht hab ich was rausgeschnitten, das scheint zu gehen.
Und hier der Fehler:
Code
c++ -o NativeMySQL NativeMySQL.cpp -I/opt/sun-jdk-1.4.1.02/include/ -I/opt/sun-jdk-1.4.1.02/include/linux -I/usr/include/mysql
NativeMySQL.cpp:19: parse error before `(' token
NativeMySQL.cpp:20: syntax error before `(' token
NativeMySQL.cpp:21: syntax error before `(' token
NativeMySQL.cpp: In function `jint
Java_de_commedia_mysql_NativeResultSet_getInteger(JNIEnv*, _jobject*, int,
int, int)':
NativeMySQL.cpp:179: `atoiown' undeclared (first use this function)
NativeMySQL.cpp:179: (Each undeclared identifier is reported only once for each
function it appears in.)
NativeMySQL.cpp: In function `jlong
Java_de_commedia_mysql_NativeResultSet_getLong(JNIEnv*, _jobject*, int, int,
int)':
NativeMySQL.cpp:194: `_atoi64own' undeclared (first use this function)
NativeMySQL.cpp: In function `jfloat
Java_de_commedia_mysql_NativeResultSet_getFloat(JNIEnv*, _jobject*, int,
int, int)':
NativeMySQL.cpp:209: `atofown' undeclared (first use this function)
NativeMySQL.cpp: At global scope:
NativeMySQL.cpp:329: parse error before `(' token
NativeMySQL.cpp:331: '__int64' is used as a type, but is not defined as a type.
NativeMySQL.cpp:338: parse error before `while'
NativeMySQL.cpp:343: ISO C++ forbids declaration of `c' with no type
NativeMySQL.cpp:343: `nptr' was not declared in this scope
NativeMySQL.cpp:344: parse error before `++' token
NativeMySQL.cpp:345: ISO C++ forbids declaration of `sign' with no type
NativeMySQL.cpp:345: redefinition of `int sign'
NativeMySQL.cpp:332: `int sign' previously declared here
NativeMySQL.cpp:346: parse error before `if'
NativeMySQL.cpp:351: ISO C++ forbids declaration of `total' with no type
NativeMySQL.cpp:353: parse error before `while'
NativeMySQL.cpp:355: ISO C++ forbids declaration of `c' with no type
NativeMySQL.cpp:355: redefinition of `int c'
NativeMySQL.cpp:343: `int c' previously defined here
NativeMySQL.cpp:355: `nptr' was not declared in this scope
NativeMySQL.cpp:356: parse error before `++' token
NativeMySQL.cpp:365: syntax error before `(' token
NativeMySQL.cpp:367: redefinition of `int total'
NativeMySQL.cpp:351: `int total' previously defined here
NativeMySQL.cpp:368: redefinition of `int sign'
NativeMySQL.cpp:345: `int sign' previously defined here
NativeMySQL.cpp:369: redefinition of `int counter'
NativeMySQL.cpp:333: `int counter' previously defined here
NativeMySQL.cpp:371: parse error before `while'
NativeMySQL.cpp:376: ISO C++ forbids declaration of `c' with no type
NativeMySQL.cpp:376: redefinition of `int c'
NativeMySQL.cpp:355: `int c' previously defined here
NativeMySQL.cpp:376: `nptr' was not declared in this scope
NativeMySQL.cpp:377: ISO C++ forbids declaration of `sign' with no type
NativeMySQL.cpp:377: redefinition of `int sign'
NativeMySQL.cpp:368: `int sign' previously declared here
NativeMySQL.cpp:378: parse error before `if'
NativeMySQL.cpp:383: ISO C++ forbids declaration of `total' with no type
NativeMySQL.cpp:383: redefinition of `int total'
NativeMySQL.cpp:367: `int total' previously declared here
NativeMySQL.cpp:385: parse error before `while'
NativeMySQL.cpp:387: ISO C++ forbids declaration of `c' with no type
NativeMySQL.cpp:387: redefinition of `int c'
NativeMySQL.cpp:376: `int c' previously defined here
NativeMySQL.cpp:387: `nptr' was not declared in this scope
NativeMySQL.cpp:388: parse error before `++' token
NativeMySQL.cpp:397: syntax error before `(' token
make: *** [NativeMySQL.o] Error 1
Alles anzeigen
Irgendwas am __cdecl oder __int64 oder was auch immer passt Ihm nicht, die Fehler kommen jedenfalls in diesen Deklarationen/Methoden
Danke für Eure Hilfe