Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Compile and link Pro*C simple program

Posted on 2006-03-22
5
Medium Priority
?
3,528 Views
Last Modified: 2008-01-16
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/precomp/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/libclntsh.sl' 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
0
Comment
Question by:ikhnaton2
  • 3
  • 2
5 Comments
 
LVL 16

Accepted Solution

by:
RCorfman earned 1000 total points
ID: 16261210
The line that you got is saying that it didn't hink it needed to compile the library. I think the .mk file needs input on top of what was provided... but I don't know for sure because the development environment I used generated the .mk files on the fly and ran them.

I haven't used pro*c on hp-ux, I have on Windows.  I don't know if these will help or not (I don't usually spam links, but in this case...).
http://www.experts-exchange.com/Programming/Q_21121227.html

This makes reference to using this line with that .mk file..
I use this command to compile:
/usr/bin/make -f /apps/oracle/ora817/precomp/demo/proc/demo_proc.mk build EXE=pgsqlldr OBJS=pgsqlldr.o CODE=ansi_c MODE=ansi
0
 
LVL 16

Expert Comment

by:RCorfman
ID: 16261283
Here are a couple of other links that may help (again, I'm sorry I don't have more direct input):
http://www.experts-exchange.com/Databases/Oracle/Q_10716941.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...
http://www.experts-exchange.com/Databases/Oracle/Q_20318763.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.
http://www.experts-exchange.com/Databases/Oracle/Q_21067492.html

This one seems more remote, but also has some refernce info
http://www.experts-exchange.com/Databases/Oracle/Q_20150898.html
0
 
LVL 1

Author Comment

by:ikhnaton2
ID: 16261544
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/oracle/product/8.1.7/lib/ -lclntsh   `cat /oracle/oracle/app/oracle/product/8.1.7/lib/sysliblist`  -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/precomp/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/oracle/product/8.1.7/precomp/public -I/oracle/oracle/app/oracle/product/8.1.7/rdbms/public -I/oracle/oracle/app/oracle/product/8.1.7/rdbms/demo -I/oracle/oracle/app/oracle/product/8.1.7/plsql/public -I/oracle/oracle/app/oracle/product/8.1.7/network/public       -c test.c

cc   -o test  test.o -L/oracle/oracle/app/oracle/product/8.1.7/lib/ -lclntsh   `cat /oracle/oracle/app/oracle/product/8.1.7/lib/sysliblist`  -lm  -lpthread -lpthread

Again trying to execute:
$ test

No output at all without even an error message.

What's wrong?
0
 
LVL 16

Expert Comment

by:RCorfman
ID: 16262045
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.
0
 
LVL 1

Author Comment

by:ikhnaton2
ID: 16262264
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: http://www.experts-exchange.com/Databases/Oracle/Q_21067492.html ,
provide by you in the 2nd comment, contains valuable information.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question