Mar 26, 2005 #1 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...
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...
Mar 26, 2005 #2 olded Programmer Oct 27, 1998 1,065 US 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 Upvote 0 Downvote
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