LINUX.ORG.RU

C&C++


0

0

Всем привет !!!

Проблема следующая : как слинковать два файла один из которых написан на C, а другой на C++

anonymous

А в чем собственно проблема-то?

abbr
()

А проблема такая - пишу программу на C++ которая должна взаимодействовать с ORACLE через интерфейс OCI. Но библиотека OCI написана для C и поэтому при компиляции g++ выдаётся куча ошибок.

anonymous
()

функции С должны быть описаны как exterm "C"

anonymous
()

Вот тестовая программа :

#include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h>

#include <oratypes.h> /* LDA and CDA struct declarations */ #include <ocidfn.h> #ifdef __STDC__ #include <ociapr.h> #else #include <ocikpr.h> #endif /* demo constants and structs */ #include <ocidem.h>

#define MAX_NAME_LENGTH 30 /* Maximum length of a column name */

/* oparse flags */ #define DEFER_PARSE 1 #define NATIVE 1 #define VERSION_7 2

/* exit flags */ #define OCI_EXIT_FAILURE 1 #define OCI_EXIT_SUCCESS 0

Lda_Def lda; /* login area */ ub4 hda[HDA_SIZE/(sizeof(ub4))]; /* host area */ Cda_Def cda; /* cursor area */

/* Globals needed */ text tabname [MAX_NAME_LENGTH+1]; /* table name - generated on the fly */ uword tabnum = 0; /* table number */ uword row_count = 0; /* number of rows returned so far */

/* SQL statement used in this program */

//text *sqlstmt = (text *)"select * from test"; text *sqlstmt = (text *)"insert into test values( '123', '456')";

/* return values from query - kept as globals for simplicity */ text col1 [MAX_NAME_LENGTH+1]; text col2 [MAX_NAME_LENGTH+1];

/* Function prototypes */ void logon (); void logoff (); void setup(); void err_report(); void get_data(); void do_exit();

void logon() {

if (olog(&lda, (ub1 *)hda, (text *)"lexa", -1, (text *)"111", -1, (text *)0, -1, (ub4)OCI_LM_DEF)) { err_report((Cda_Def *)&lda); exit(OCI_EXIT_FAILURE); }

printf("\n Connected to ORACLE as ocitest\n"); }

void logoff() { if (oclose(&cda)) /* close cursor */ { fprintf(stderr, "Error closing cursor 1.\n"); do_exit(OCI_EXIT_FAILURE); }

if (ologof(&lda)) /* log off the database */ { fprintf(stderr, "Error on disconnect.\n"); do_exit(OCI_EXIT_FAILURE); } }

void setup() { if (oopen(&cda, &lda, (text *) 0, -1, -1, (text *) 0, -1)) /* open */ { err_report(&cda); do_exit(OCI_EXIT_FAILURE); }

if (oparse(&cda, sqlstmt, (sb4) -1, DEFER_PARSE, /* parse */ (ub4) VERSION_7)) { err_report(&cda); do_exit(OCI_EXIT_FAILURE); }

}

void get_data() { if (oexec(&cda)) { err_report(&cda); do_exit(OCI_EXIT_FAILURE); }

}

void err_report(cursor) Cda_Def *cursor; { sword n; text msg[512];

if (cursor->fc > 0) printf("\n-- ORACLE error when processing OCI function %s \n\n", oci_func_tab[cursor->fc]); else printf("\n-- ORACLE error\n");

n = (sword)oerhms(&lda, cursor->rc, msg, (sword) sizeof msg); fprintf(stderr, "%s\n", msg); }

void do_exit(status) eword status; { if (status == OCI_EXIT_FAILURE) printf("\n Exiting with FAILURE status %d\n", status); else printf("\n Exiting with SUCCESS status %d\n", status);

exit(status); }

main( void) { logon(); setup(); get_data(); logoff();

do_exit(OCI_EXIT_SUCCESS); }

Ошибки :

g++ -c -I/oracle/app/oracle/product/9.2/rdbms/demo -I/oracle/app/oracle/product/9.2/rdbms/public -I/oracle/app/oracle/product/9.2/plsql/public -I/oracle/app/oracle/product/9.2/network/public -I/oracle/app/oracle/product/9.2/precomp/public test.cpp test.cpp: In function `void logon()': test.cpp:54: too many arguments to function `void err_report()' test.cpp:65: at this point in file test.cpp: In function `void logoff()': test.cpp:56: too many arguments to function `void do_exit()' test.cpp:77: at this point in file test.cpp:56: too many arguments to function `void do_exit()' test.cpp:83: at this point in file test.cpp: In function `void setup()': test.cpp:54: too many arguments to function `void err_report()' test.cpp:91: at this point in file test.cpp:56: too many arguments to function `void do_exit()' test.cpp:92: at this point in file test.cpp:54: too many arguments to function `void err_report()' test.cpp:98: at this point in file test.cpp:56: too many arguments to function `void do_exit()' test.cpp:99: at this point in file test.cpp: In function `void get_data()': test.cpp:54: too many arguments to function `void err_report()' test.cpp:108: at this point in file test.cpp:56: too many arguments to function `void do_exit()' test.cpp:109: at this point in file test.cpp: At global scope: test.cpp:114: `cursor' was not declared in this scope test.cpp:115: variable or field `err_report' declared void test.cpp:115: `int err_report' redeclared as different kind of symbol test.cpp:54: previous declaration of `void err_report()' test.cpp:115: syntax error before `*' token test.cpp:120: parse error before `if' test.cpp:126: ISO C++ forbids declaration of `n' with no type test.cpp:126: `cursor' was not declared in this scope test.cpp:127: ISO C++ forbids declaration of `fprintf' with no type test.cpp:127: `int fprintf' redeclared as different kind of symbol /usr/include/stdio.h:298: previous declaration of `int fprintf(FILE*, const char*, ...)' test.cpp:127: initializer list being treated as compound expression test.cpp:127: invalid conversion from `text*' to `int' test.cpp:128: parse error before `}' token test.cpp:130: `status' was not declared in this scope test.cpp:131: variable or field `do_exit' declared void test.cpp:131: `int do_exit' redeclared as different kind of symbol test.cpp:56: previous declaration of `void do_exit()' test.cpp:131: syntax error before `status' test.cpp:138: `status' was not declared in this scope test.cpp:138: ISO C++ forbids declaration of `exit' with no type test.cpp:138: `int exit' redeclared as different kind of symbol /usr/include/stdlib.h:610: previous declaration of `void exit(int)' test.cpp:139: parse error before `}' token test.cpp: In function `int main()': test.cpp:149: `do_exit' cannot be used as a function make: *** [all] Error 1

При использовании 'cc' всё без проблем

anonymous
()

Спасибо огромное !!!!!!!!

anonymous
()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.