AGAIN database

THis is my program

#include <stdio.h>
#include "sqlext.h"
#include "sql.h"
#include <string.h>
#include<errno.h>

// #include "sqlunix.h"
#define STR_LEN 30
#define SQL_NTS (-3)
#define MYSQLSUCCESS(rc) ((rc==SQL_SUCCESS)||(rc==SQL_SUCCESS_WITH_INFO))

void main\(\)
\{
	HENV     henv;                            /* environment handle */
	HDBC     hdbc;                            /* connection handle */
	HSTMT    hstmt;                           /* statement handle */
	SDWORD   retcode;                         /* return code */
	UCHAR    info[STR_LEN];                   /* info string for SQLGetInfo */
	int rc=0;
	unsigned char chr\_ds\_name[SQL\_MAX\_DSN_LENGTH];   // Data source name

// char chr_ds_name[]={"SQL"}; // Data source name
//strcpy(chr_ds_name,"SQL");

	retcode = SQLAllocEnv\(&henv\);
	retcode = SQLAllocConnect\(henv,&hdbc\);
	retcode = SQLConnect\(hdbc,chr\_ds\_name,SQL_NTS, NULL,0,NULL,0\);

if (!MYSQLSUCCESS(rc))
{
SQLFreeEnv(henv);
SQLFreeConnect(hdbc);
// error_out();
exit(-1);
}
}

the error on compilation is :

Undefined first referenced
symbol in file
SQLConnect /var/tmp/ccnGf8ud.o
SQLAllocEnv /var/tmp/ccnGf8ud.o
SQLFreeEnv /var/tmp/ccnGf8ud.o
SQLAllocStmt /var/tmp/ccnGf8ud.o
SQLAllocConnect /var/tmp/ccnGf8ud.o
SQLFreeConnect /var/tmp/ccnGf8ud.o
ld: fatal: Symbol referencing errors. No output written to d
collect2: ld returned 1 exit status

i am compiling it as: g++ <filename.cpp>

what is this error
please do help me

You have to link against the mysql client library, you probably should also point to the mysql include path, too:

g++ <filename.cpp> -L/usr/local/lib/mysql  -I/usr/  -I/usr/local/include/mysql 

Exactly where the -L and -I point depend on where (and if) the library and include files ive on your system.

Which distibution of Linux?

i have been working on solaris 5.8

i just want to know that what libraries u need to compile the database program

because i think i am working on older version of solaris so i dont have sql.h and sqlext.h header files also, but i downloaded those files form the net

somebody told me that i should use -lsql while compiling
like

g++ <filename.cpp> -lsql

i serached it in all the possible directories of my system but i couldnt get it

1)so i am unable to understand which files u need to include and what libraries u need when u want a database to be connected to c++.

2) if the libraries of database r not in the system then from where we can download it

I'm assuming mysql.

If you want me to help you HAVE to tell me the name of the DATABASE ENGINE.

i have been trying to connect Microsoftsql serevr to solaris 5.8 using c++

These function calls look like ODBC calls so I'm assuming you're trying to use unixODBC. If not, you're gonna need it because Microsoft ODBC hasn't been ported to unix yet, and isn't likely to be anytime this millenium :wink:

They have a faq entry relating to this very problem. In short you need to link with -lodbc .

hi corona

i tried to compile my above program with -lodbc and -lsql (both seperatley and togther) but it is giving error as

ld: fatal: library -lsql: not found
ld: fatal: File processing errors. No output written to a.out
collect2: ld returned 1 exit status

ld: fatal: library -lodbc: not found
ld: fatal: File processing errors. No output written to a.out
collect2: ld returned 1 exit status

I dont Know what to do now

Are you trying to compile Windows C code on a unix box?

Right, this isn't windows. You won't get those functions without some sort of third-party library, which I assumed you had but apparently not. See that library I linked you to? unixODBC? Get it.