Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Titan » How to use a TTCN3-based library in other TTCN3 projects (Simple solution)(C, TTCN3, TitanSim, External Functions, Library)
How to use a TTCN3-based library in other TTCN3 projects (Simple solution) [message #1768337] Mon, 17 July 2017 15:50
Akos Pernek is currently offline Akos PernekFriend
Messages: 1
Registered: July 2017
Junior Member
The purpose of this guide is to describe how to create a library from a TTCN-3 project, and how to use this library as an external library in other projects. In this way it is not necessary to distribute the source code of the original project as long as it is compiled for the target environment.

Let's assume the original project consists of three files: -> sensitive code
TSTM_LIB_Definitions.ttcn -> public definitions
TSTM_LIB_Functions.ttcn -> external functions, and public functions

These source files and optional dependencies must be grouped in a project files, see an example project file (TSTM_LIB.prj):

<!DOCTYPE TITAN_GUI_project_file>
<Project TITAN_version="4.2.pl0" >
<Execute_Command>rsh %host &quot;cd %project_working_dir ; &quot;%executable&quot; %localhost %mctr_port&quot;</Execute_Command>
<Execute_Hosts>alfa, beta, gamma</Execute_Hosts>
<File_Group name="MainFileGroup" >
<File_Group name="TSTM_LIB" >
<File path="../../../vobs/ttcn/TSTM_LIB//src/" />
<File path="../../../vobs/ttcn/TSTM_LIB//src/TSTM_LIB_Definitions.ttcn" />
<File path="../../../vobs/ttcn/TSTM_LIB//src/TSTM_LIB_Functions.ttcn" />

As written in Section 6.1.2 of the Programmer's Technical Reference for TITAN TTCN-3 Test Executor, a makefile can be generated for this project.

The following script can be used to generate the makefile for the above project, issuing the command TSTM_LIB.prj


comm_base_dir=`dirname $0`
base_dir=`dirname $1`
unused_list=`grep "<UnUsed_List>" $1| sed -n 's!.*<UnUsed_List>\(.*\)</UnUsed_List>.*!\1!p'| sed 's!,! !g'`
script_name=`grep "<ScriptFile_AfterMake>" $1| sed -n 's!.*<ScriptFile_AfterMake>\(.*\)</ScriptFile_AfterMake>.*!\1!p'`
file_list=`$comm_base_dir/ $1`
ex_name=`grep "<Executable_Path>" $1| sed -n 's!.*<Executable_Path>\(.*\)</Executable_Path>.*!\1!p'`
ex_name=`basename $ex_name`

#echo "\"$file_list\""
for file in $unused_list
fn=`basename $file`
# echo "\"$fn\""
file_list=`echo "$file_list" | grep -v "$fn"`
#echo "\"$file_list\""

# echo "$file_list"
source_list=`echo "$file_list" | egrep '(.*\.ttcn)|(.*\.asn)|(.*\.c[c]*$)|(.*\.h[h]*$)'`

pp=`echo $source_list | grep ttcnpp`

if [ "$pp" != "" ]
args="-f -p"

if [ "$script_name" != "" ]
rm -f Makefile.tmp Makefile Makefile_"$ex_name"
ttcn3_makefilegen $args -e "$ex_name" $source_list
$base_dir/$script_name Makefile Makefile.tmp
mv -f Makefile.tmp Makefile_"$ex_name"
rm -f Makefile
ttcn3_makefilegen $args -e "$ex_name" $source_list
mv -f Makefile Makefile_"$ex_name"

The generated makefile has the 'make library' option and the library can be created issuing the command:

make library -f Makefile_tstm_lib

and as a result libtstm_lib.a file will be created.

The created library can now be used by other projects. The easiest way is to include the ttcn source code (TSTM_Definitions.ttcn and TSTM_Functions.ttcn) in the project file of the other project. Note: these are the files which only contain public functions and definitions and external functions, which are implemented and hidden in libtstm_lib.a. Furthermore the makefile has to be modified as well. It is suggested to introduce a macro with the library location: TSTM_LIB_DIR, and $(TSTM_LIB_DIR)/libtstm_lib.a has to be added to section $(EXECUTABLE): $(OBJECTS):

if $(CXX) $(LDFLAGS) -o $@ $(OBJECTS) \
-L$(TTCN3_DIR)/lib -l$(TTCN3_LIB) $(TSTM_LIB_DIR)/libtstm_lib.a \
-L$(OPENSSL_DIR)/lib -lcrypto \
-L$(XMLDIR)/lib $($(PLATFORM)_LIBS); \
then : ; else $(TTCN3_DIR)/bin/titanver $(OBJECTS); exit 1; fi

In this way the library will be linked during compilation, its features can be used.

Previous Topic:Support for WebSocket in Eclipse Titan
Next Topic:Regular expression escaping in configuration file
Goto Forum:

Current Time: Wed Nov 14 08:31:45 GMT 2018

Powered by FUDForum. Page generated in 0.02330 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top