We help IT Professionals succeed at work.

Compile and link Pro*C simple program

ikhnaton2
ikhnaton2 asked
on
Medium Priority
3,578 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
Comment
Watch Question

Commented:
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Commented:
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

Author

Commented:
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?

Commented:
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.

Author

Commented:
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.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.