eProsima / Micro-XRCE-DDS

An XRCE DDS implementation. Looking for commercial support? Contact info@eprosima.com
Apache License 2.0
156 stars 17 forks source link

How to compile after creating a uClient source file? #79

Closed vibnwis closed 3 years ago

vibnwis commented 3 years ago

Hi there, I have created a myPublishHelloWorldClient.c of which a modified version of PublishHelloWorldClient.c. However, I could not find any descriptions on how to compile the source. I am running the client on Ubuntu 20.04. Appreciate any suggestions or comments.

Thank you so much. V

pablogs9 commented 3 years ago

Try to add your folder here.

vibnwis commented 3 years ago

I found a command, gcc myPublishHelloWorldClient.c -lmicrocdr -lmicroxrcedds_client. However, I encountered the following errors - my apologies for being a newbie. Basically, I presumed it would be free from errors since it is a replica of publishHelloWorld.

myPublishHelloWorldClient.c: In function ‘main’:
myPublishHelloWorldClient.c:40:59: error: incompatible type for argument 3 of ‘uxr_init_udp_transport’
   40 |     if(!uxr_init_udp_transport(&transport, &udp_platform, "127.0.0.1", 2018))
      |                                                           ^~~~~~~~~~~
      |                                                           |
      |                                                           char *
In file included from /usr/local/include/uxr/client/transport.h:21,
                 from /usr/local/include/uxr/client/client.h:30,
                 from myPublishHelloWorldClient.c:17:
/usr/local/include/uxr/client/profile/transport/ip/udp/udp_transport.h:51:23: note: expected ‘uxrIpProtocol’ {aka ‘enum uxrIpProtocol’} but argument is of type ‘char *’
   51 |         uxrIpProtocol ip_protocol,
      |         ~~~~~~~~~~~~~~^~~~~~~~~~~
myPublishHelloWorldClient.c:40:72: warning: passing argument 4 of ‘uxr_init_udp_transport’ makes pointer from integer without a cast [-Wint-conversion]
   40 |     if(!uxr_init_udp_transport(&transport, &udp_platform, "127.0.0.1", 2018))
      |                                                                        ^~~~
      |                                                                        |
      |                                                                        int
In file included from /usr/local/include/uxr/client/transport.h:21,
                 from /usr/local/include/uxr/client/client.h:30,
                 from myPublishHelloWorldClient.c:17:
/usr/local/include/uxr/client/profile/transport/ip/udp/udp_transport.h:52:21: note: expected ‘const char *’ but argument is of type ‘int’
   52 |         const char* ip,
      |         ~~~~~~~~~~~~^~
myPublishHelloWorldClient.c:40:9: error: too few arguments to function ‘uxr_init_udp_transport’
   40 |     if(!uxr_init_udp_transport(&transport, &udp_platform, "127.0.0.1", 2018))
      |         ^~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/local/include/uxr/client/transport.h:21,
                 from /usr/local/include/uxr/client/client.h:30,
                 from myPublishHelloWorldClient.c:17:
/usr/local/include/uxr/client/profile/transport/ip/udp/udp_transport.h:48:16: note: declared here
   48 | UXRDLLAPI bool uxr_init_udp_transport(
      |                ^~~~~~~~~~~~~~~~~~~~~~

Try to add your folder here.

vibnwis commented 3 years ago

Sorry for my ignorance. "Try to add your folder here.", I have looked into the "here" and did you mean to try to create a folder in the example folder or file structure?

pablogs9 commented 3 years ago

Well... in the code that you have shared the problem is that you have installed an old version of the Client library and the uxr_init_udp_transport have changed:

vibnwis commented 3 years ago

Hi Pablo, For the cMakelist.txt, just to clarify. I am no longer working on Olimex board. My supervisors and I decided to work on Ubuntu system for both the client and the agent. Hence, if I am not wrong, the cMakelist.txt is no longer valid. Can I say that?

Many thanks for the update on the new version. I will get the newer one immediately.

pablogs9 commented 3 years ago

You can build and install the Micro XRCE-DDS Client library and then link your code against it using gcc main.c -lmicrocdr -lmicroxrcedds_client

vibnwis commented 3 years ago

Good to know that. I was wondering if it needs to remove the old version before installing a new one? If yes, how and what is the best method?

vibnwis commented 3 years ago

Okie, I managed to move on a bit further. I encountered similar issues when compiling myPublishHelloWorld.c. Not believing it I use the examples, HelloWorld, yet I encountered the same issues. See below.

iki-ros@wikiros-NUC8i5BEH:~/micro-xrce-dds-v2/PublishHelloWorld$ gcc main.c -lmicrocdr -lmicroxrcedds_client /usr/bin/ld: /tmp/ccQHFtIC.o: in function main': main.c:(.text+0x45a): undefined reference toHelloWorld_size_of_topic' /usr/bin/ld: main.c:(.text+0x4a4): undefined reference to `HelloWorld_serialize_topic' collect2: error: ld returned 1 exit status

Appreciate your comments or suggestion, please?

vibnwis commented 3 years ago

Okie, the correct command should gcc main.c HelloWorld.c -o HelloWorld -lmicrocdr -lmicroxrcedds_client