ikhnaton2
asked on
Compile and link Pro*C simple program
I'm new to Pro*C. I had made a simple program (test.pc) to begin
programming with Pro*C. My program is as follows:
#include <stdio.h>
#include <stdlib.h>
#include "/oracle/oracle/app/oracle /product/8 .1.7/preco mp/public/ sqlca.h"
void main()
{
char * uid = "/";
int a;
EXEC SQL CONNECT :uid;
EXEC SQL SELECT count(id) INTO :a
FROM tab
WHERE status=4;
printf("The number of rows is: %d\n", a);
exit(0);
}
I compiled from Pro*C to C without any problem using the following command:
$ proc test.pc
Now, I need to compile from C:
I copied demo_proc.mk from $ORACLE_HOME/precomp/demo/ proc and just change the line with environment variable SAMPLES to put my program name: test. It looks like:
SAMPLE=test
After I execute the make command as follows:
make -f demo_proc.mk
I just got this line with no output:
`/oracle/oracle/app/oracle /product/8 .1.7/lib/l ibclntsh.s l' is up to date.
Could anyone help me to compile my first file?
My environment:
Machine: HP-UX B.11.11 U 9000/800
Pro*C/C++: Release 8.1.7.0.0
C compiler provided by HP-UX: cc
Thanks in Advance
programming with Pro*C. My program is as follows:
#include <stdio.h>
#include <stdlib.h>
#include "/oracle/oracle/app/oracle
void main()
{
char * uid = "/";
int a;
EXEC SQL CONNECT :uid;
EXEC SQL SELECT count(id) INTO :a
FROM tab
WHERE status=4;
printf("The number of rows is: %d\n", a);
exit(0);
}
I compiled from Pro*C to C without any problem using the following command:
$ proc test.pc
Now, I need to compile from C:
I copied demo_proc.mk from $ORACLE_HOME/precomp/demo/
SAMPLE=test
After I execute the make command as follows:
make -f demo_proc.mk
I just got this line with no output:
`/oracle/oracle/app/oracle
Could anyone help me to compile my first file?
My environment:
Machine: HP-UX B.11.11 U 9000/800
Pro*C/C++: Release 8.1.7.0.0
C compiler provided by HP-UX: cc
Thanks in Advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks RCorfman for the answer.
I'm reading the references provided by you, I think I got close to find the answer:
I tried this command
make -f demo_proc.mk build EXE=test OBJS=test.o CODE=ansi_c MODE=ansi
Output was:
cc -o test test.o -L/oracle/oracle/app/oracl e/product/ 8.1.7/lib/ -lclntsh `cat /oracle/oracle/app/oracle/ product/8. 1.7/lib/sy sliblist` -lm -lpthread -lpthread
Then I got, at last, the executable file: test
When I tried to execute:
$ test
No output at all.
I changed the code to contain Error Handling like this:
#include <stdio.h>
#include <stdlib.h>
#include "/oracle/oracle/app/oracle /product/8 .1.7/preco mp/public/ sqlca.h"
/* Error handling function. */
void sql_error(void)
{
EXEC SQL WHENEVER SQLERROR continue;
printf("%.70s\n", sqlca.sqlerrm.sqlerrmc);
exit(1);
}
void main()
{
char * uid = "/";
int a;
EXEC SQL WHENEVER SQLERROR do sql_error();
EXEC SQL CONNECT :uid;
EXEC SQL SELECT count(id) INTO :a
FROM tab
WHERE status=4;
printf("The number of rows is: %d\n", a);
exit(0);
}
Compile from Proc*C to C successfully. Then compile from C using the above make command, the output is:
cc -I. -I/oracle/oracle/app/oracl e/product/ 8.1.7/prec omp/public -I/oracle/oracle/app/oracl e/product/ 8.1.7/rdbm s/public -I/oracle/oracle/app/oracl e/product/ 8.1.7/rdbm s/demo -I/oracle/oracle/app/oracl e/product/ 8.1.7/plsq l/public -I/oracle/oracle/app/oracl e/product/ 8.1.7/netw ork/public -c test.c
cc -o test test.o -L/oracle/oracle/app/oracl e/product/ 8.1.7/lib/ -lclntsh `cat /oracle/oracle/app/oracle/ product/8. 1.7/lib/sy sliblist` -lm -lpthread -lpthread
Again trying to execute:
$ test
No output at all without even an error message.
What's wrong?
I'm reading the references provided by you, I think I got close to find the answer:
I tried this command
make -f demo_proc.mk build EXE=test OBJS=test.o CODE=ansi_c MODE=ansi
Output was:
cc -o test test.o -L/oracle/oracle/app/oracl
Then I got, at last, the executable file: test
When I tried to execute:
$ test
No output at all.
I changed the code to contain Error Handling like this:
#include <stdio.h>
#include <stdlib.h>
#include "/oracle/oracle/app/oracle
/* Error handling function. */
void sql_error(void)
{
EXEC SQL WHENEVER SQLERROR continue;
printf("%.70s\n", sqlca.sqlerrm.sqlerrmc);
exit(1);
}
void main()
{
char * uid = "/";
int a;
EXEC SQL WHENEVER SQLERROR do sql_error();
EXEC SQL CONNECT :uid;
EXEC SQL SELECT count(id) INTO :a
FROM tab
WHERE status=4;
printf("The number of rows is: %d\n", a);
exit(0);
}
Compile from Proc*C to C successfully. Then compile from C using the above make command, the output is:
cc -I. -I/oracle/oracle/app/oracl
cc -o test test.o -L/oracle/oracle/app/oracl
Again trying to execute:
$ test
No output at all without even an error message.
What's wrong?
I would put a printf at the very start of main to ensure it is even running... I agree it seems that you should get some output.
ASKER
Actually the files seems to be built successfully but as I name it "test". When I try to execute it as:
$ test
It run a shell command called "test" which is condition evaluation command.
I should, instead, run the command as follows:
$ ./test
and it works as I wanted.
It was a silly problem, my fault. Your answer has been accepted. Thanks for your help.
P.S.
I would like to mention here that this link: https://www.experts-exchange.com/questions/21067492/How-to-access-Oracle-8-1-database-on-AIX-5-1-from-C-program.html ,
provide by you in the 2nd comment, contains valuable information.
$ test
It run a shell command called "test" which is condition evaluation command.
I should, instead, run the command as follows:
$ ./test
and it works as I wanted.
It was a silly problem, my fault. Your answer has been accepted. Thanks for your help.
P.S.
I would like to mention here that this link: https://www.experts-exchange.com/questions/21067492/How-to-access-Oracle-8-1-database-on-AIX-5-1-from-C-program.html ,
provide by you in the 2nd comment, contains valuable information.
https://www.experts-exchange.com/questions/10716941/PRO-C-Compile-error-Help.html
Here is one that isn't hp-ux specific, it is unix though, and seems to show more instruction on how to compile the demo...
https://www.experts-exchange.com/questions/20318763/Oracle-Pro-C.html
And I think this one looks like it may have lot's of clear instruction on compiling a program. Also discusses pro*c vs. OCI arguments.
https://www.experts-exchange.com/questions/21067492/How-to-access-Oracle-8-1-database-on-AIX-5-1-from-C-program.html
This one seems more remote, but also has some refernce info
https://www.experts-exchange.com/questions/20150898/Pro-c-can't-open-include-files.html