Is it possible to compile RTI DDS code into a shared library, like a .so, and call it from another application? It would be nice if someone already done it with Eclipse, and post the instruction here on the forum. Or is there a makefile that RTI have that can compile DDS example code into the shared library? Please help. Thanks
Hi Joseph,
I assume that you want to create a shared library with the code generated by rtiddsgen so that you can link it against other applications. If that is the case, you can do the following:
First, generate an example makefile. In this case we are using C++ and the architecture is x64Linux3gcc4.8.2, but this applies to any other platform.
This should have generated a makefile called makefile_hello_x64Linux3gcc4.8.2. We are going to make a copy of the original makefile and call it makefile_hello_x64Linux3gcc4.8.2.original, that way you can compare the changes to the original file.
From now on we will editing makefile_hello_x64Linux3gcc4.8.2. In that makefile will find that we are actually building two executables: hello_publisher and hello_subscriber. We are now going to make some changes to link those executables against a shared library that we are going to create and that will contain all the type plugins generated by rtiddsgen. To do so modify the makefile as follows:
-fPIC
to your compiler flags.SHARED_LIB
where you will name your shared library (e.g., libhello.so).objs/$(TARGET_ARCH)/$(SHARED_LIB)
:$(TARGET_ARCH)
:objs/$(TARGET_ARCH)/%
target to use the new shared library instead of the orignial common object files:Once you have done those changes, you can run the makefile as follows. You will find the library and executables you have created under objs/$(TARGET_ARCH):
Please, let me know if this is what you were looking for or you have doubts on how to make the appropriate changes in your makefile. I think it is probably better to do these changes at the makefile level, so that you can compile both from Eclipse and from the command line.
Thanks,
Fernando.
Thanks Fernando. I didn't expect to get a quick answer, but you did. Thanks again, and it works perfect.
Just little mispell on line 64 "LIKER" should be "LINKER"
That is great! I have just fixed line 64, thanks for pointing that out.
Best,
Fernando.
And I am trying to model your makefile to do a static library, but no luck. Would you be kind and show me how to compile and build a static library also? Thanks Fernando.
Hi Joseph,
If you want to create a static library as well you will need to use the
ar
archiver. Plese, modify your makefile as follows:$(TARGET_ARCH)
:Please, let me know if this solves your issue.
Thanks,
Fernando
Yes sir. That solves it. Thank you, thank you.
Fernando,
If I use this static library (libhello.a) to link into another application, do I need to set any RTI DDS compiler/linker flags in that application at all? Just link the library, and specify the path, and add the include file? I am not sure why I can't call the function inside the lib. Do you have any suggestion? Thanks
Hello Mr Fernando
I have incorporated the changes as given by you. But i am getting errors like publisher.o file not found etc. while i am running my makefile.
Kindly help.
Hi Shikha,
Are you modifying the makefile generated by rtiddsgen? Could you post makefile so that we can help you figure out the problem?
Thanks,
Fernando.
Hello Fernando,
I am trying to create shared library( static and dynamic) . I am getting the below error. Also attached the makefile
/usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/crt1.o: In function `_start':
(.text+0x24): undefined reference to `main'
collect2: error: ld returned 1 exit status
make: *** [makefile_SimulatorIDL_x64Linux4gcc7.3.0:105: objs/x64Linux4gcc7.3.0/libRTISimulator.so] Error 1
[paras@localhost RTI_SIM]$ vi makefile_SimulatorIDL_x64Linux4gcc7.3.0
Regards
Chand