Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compile to library

Status
Not open for further replies.

greggory

IS-IT--Management
Mar 26, 2005
11
FR
Does anyone knows if it's possible to compile a 4GL file into a (static or dynamic) shared library (.so or .a).

I tried some time ago but couldn't figure out how it works...
 
Hi:

I haven't tried dynamically linking a library, but since 4GL compiles to "C" object, statically linking a library is possible. Consider this example:

Given two source modules:

# get_server.4gl:
# Get the current date from the database engine.
# placed in get_st.4gl
FUNCTION get_server_today()
DEFINE sv_current DATE

SELECT today INTO sv_current
FROM systables WHERE tabname = "systables"

RETURN sv_current
END FUNCTION

# ret_day.4gl:
# This function returns SUNDAY=1, MONDAY=2, ....SATURDAY=7
# placed in ret_day_no.
FUNCTION ret_day_no(ddate)
DEFINE ddate DATE

IF ddate IS NULL
THEN # no nulls, an error
RETURN 0
END If
RETURN (weekday(ddate) + 1)
END FUNCTION

Compile the source and create a library called testlib.a using the ar command:

c4gl -c ret_day.4gl
ar -r testlib.a ret_day.o

c4gl -c get_server.4gl
ar -r testlib.a get_server.o

Now, create a source file to test the library:

# main.4gl: test the stub functions
DATABASE testdb

MAIN
DEFINE
tdate DATE,
day_no SMALLINT

LET tdate = get_server_today()
LET day_no = ret_day_no(tdate)

DISPLAY tdate
DISPLAY day_no
SLEEP 1
END MAIN

Finally, create program, myprog, using the testlib.a:

c4gl main.4gl testlib.a -o myprog

You should be able to execute myprog.

Regards,


Ed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top