ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
3

How to correctly compile a C# package?

asked 2012-05-27 22:48:28 -0500

updated 2012-11-09 06:40:19 -0500

Hello!

I have trouble building a C# package due to the error:

  /home/berln/projects/ros/roscsharp/hello_world/src/hello.cs(3,7): error CS0246: The type or namespace name `RosCS' could not be found. Are you missing a using directive or an assembly reference?

I created a simple C# package by

  berln@berln-Signor:~/projects/ros/roscsharp$ roscreate-pkg hello_world

Then I edited manifest.xml and added this line.

  <depend package="roscs"/>

And the last thing I changed is CMakeLists.txt, and I added these three lines:

  rosbuild_include(roscs cncs)
  CSHARP_ADD_TARGET_DEPENDENCY(hello Mono.C5) 
  CSHARP_ADD_EXE(hello src/hello.cs)

Here's the src/hello.cs:

  using System;
  using System.Threading;
  using RosCS;

  public class RosCsHello
  {
      Node node;
      public RosCsHello()
      {
          this.node = Node.MainNode;
      }
      public void Run() 
      {
          while(RosSharp.Ok()) 
          {
              Console.WriteLine("Hello");
          }
      }

      static public void Main ()
      {   
          RosSharp.Init("ROSCS_hello",args);
          RosCsHello hello = new RosCsHello();
          hello.Run();
      }   
  }

But when I compile, the compiler would complain that it cannot find RosCS, I don't know why this happens?

EDIT:

I followed what Alireza suggested, I first modify my CMakeLists.txt, and then remove Makefile autogenerated by roscreate-pkg.After that, I cmake CMakeLists.txt, then make.

But I got this error message:

[ 14%] Creating Csharp Wrapper Code
Querying Ros for messages...
Message: Name: Logger NameSpace: roscpp/
Start generating...
Path for generating files : /home/rosfuerte/project/ros/my_package/roscs_try/msg_cs_gen!
Total msges: 1
Cleaning before...
Template: /home/rosfuerte/project/ros/important_packages/cn-roscs-ros-pkg/roscs/templates/messages/Message.cs
Template: /home/rosfuerte/project/ros/important_packages/cn-roscs-ros-pkg/roscs/templates/messages/Node.cs
Template: /home/rosfuerte/project/ros/important_packages/cn-roscs-ros-pkg/roscs/templates/messages/Publisher.cs
Template: /home/rosfuerte/project/ros/important_packages/cn-roscs-ros-pkg/roscs/templates/messages/RosSharp.cs
Template: /home/rosfuerte/project/ros/important_packages/cn-roscs-ros-pkg/roscs/templates/messages/Timer.cs
Template: /home/rosfuerte/project/ros/important_packages/cn-roscs-ros-pkg/roscs/templates/messages/roscs.cpp
Template: /home/rosfuerte/project/ros/important_packages/cn-roscs-ros-pkg/roscs/templates/messages/Subscriber.cs.pm
make[2]: *** No rule to make target `lib/std_msgs.Messages.dll', needed by `lib/roscs_try.Communication.dll'.  Stop.
make[1]: *** [CMakeFiles/CSharp_myExe_exe.dir/all] Error 2
make: *** [all] Error 2

This is my CMakeLists.txt

cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)

rosbuild_init()
rosbuild_include(roscs cncs) 
rosbuild_gen_cs_msg()

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

CSHARP_ADD_TARGET_DEPENDENCY(myExe Mono.C5)
CSHARP_ADD_EXE(myExe src/tmp.cs)

Does anyone have ideas about how this problem can be solved? Any thought or advice would be appreciated!

edit retag flag offensive close merge delete

6 Answers

Sort by ยป oldest newest most voted
1

answered 2012-11-09 05:36:32 -0500

Alireza gravatar image

updated 2012-11-09 05:40:54 -0500

Just edit your CMakeList.txt to something like this:


    cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)

rosbuild_init()
rosbuild_include(roscs cncs)

rosbuild_gen_cs_msg()


set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)

set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

CSHARP_ADD_TARGET_DEPENDENCY(test_cs Mono.C5 )

CSHARP_ADD_EXE(test_cs src/test_cs.cs)
 
edit flag offensive delete link more

Comments

Thanks! By following you CMakelists.txt, I can now successfully rosmake. But the binary appeared in /bin is test_cs.exe.mdb(I assumed it should be an executable test_cs.exe). Do you have this situation?

Po-Jen Lai gravatar image Po-Jen Lai  ( 2012-11-09 05:52:03 -0500 )edit

no, i have both of them! just try to remove every auto generated files in the package directory and use cmake CMakeList.txt and then "make" command in order to compile the package.

Alireza gravatar image Alireza  ( 2012-11-09 06:08:39 -0500 )edit

Weird...I removed Makefile generated automatically and cmake CMakeLists.txt, but my make fails.Thanks a lot, I'll update my question. I'll try tomorrow, it's late here.

Po-Jen Lai gravatar image Po-Jen Lai  ( 2012-11-09 06:29:43 -0500 )edit
1

answered 2012-06-24 23:51:04 -0500

Olivier R. gravatar image

Hi, I had the same problem and adding rosbuild_gen_cs_msg() to CMakeList.txt just below rosbuild_include(roscs cncs) solved it.

Hope it helps.

edit flag offensive delete link more

Comments

1

I tried that solution before but it didn't work. Can you share your succeeded package to me? I want to compare mine and yours to find the difference. Thanks~

Po-Jen Lai gravatar image Po-Jen Lai  ( 2012-06-30 22:39:11 -0500 )edit
1

answered 2013-09-27 08:36:25 -0500

mklingen gravatar image

I fixed the problem!!

Surprising nobody has gotten around to compiling a C# package in almost a year. The answer is this:

Add <depend package="std_msgs"/>

To your manifest.xml. Those messages will magically get compiled and put into your lib directory.

edit flag offensive delete link more
0

answered 2012-06-25 04:18:17 -0500

thebyohazard gravatar image

updated 2012-06-25 04:22:25 -0500

I haven't used RosCS yet, so I can't say I've tested this solution. However, when I saw this question, I got excited that there was ROS C# support, and I looked at the code. If this is the repository you're using, the namespace looks to be 'RosCs' not 'RosCS'.

EDIT: looking at it further, there are instances of both namespaces. Maybe you're looking for the other one, though?

edit flag offensive delete link more

Comments

I just want to test if a simple C# package works, and I referenced the example on roscs page(http://www.ros.org/wiki/roscs). In that example, it used RosCS. BTW, RosCs is quite interesting, maybe I should look at roscs further.

Po-Jen Lai gravatar image Po-Jen Lai  ( 2012-06-30 22:45:09 -0500 )edit

Sorry for unselecting this answer, since the problem is still unsolved right now. I thought it was solved that time.

Po-Jen Lai gravatar image Po-Jen Lai  ( 2012-11-07 20:17:26 -0500 )edit
0

answered 2012-06-13 09:01:17 -0500

allenh1 gravatar image

You might want to try launching your IDE from a terminal. If it's like ros-qt4, the IDE must be launched that way. Also, you could try to build it in the directory with rosmake (not sure how that works with C#).

Hope it helps!

-Hunter A.

edit flag offensive delete link more

Comments

Sorry, I don't get it. What do you mean "You might want to try launching your IDE from a terminal"?

Po-Jen Lai gravatar image Po-Jen Lai  ( 2012-06-15 16:55:56 -0500 )edit

If you're using mono, launch it in a terminal (look it up, but the command is probably just "mono").

allenh1 gravatar image allenh1  ( 2012-06-16 05:25:39 -0500 )edit

I didn't use IDE, I created a package and put hello.cs to PACKAGE_ROOT/src, then rosmake the package. I've tried that if I wrote "pure" C# code(not using RosCS or anything about ROS) and rosmake, it works well and the execution file in PACKAGE_ROOT/bin run correctly.

Po-Jen Lai gravatar image Po-Jen Lai  ( 2012-06-16 17:54:07 -0500 )edit
0

answered 2012-05-28 07:59:21 -0500

Mac gravatar image

If you're having trouble finding ROSCS (aside: C# bindings? Cool!), here are a couple of things to try:

  • Is ROSCS in your ROS_PACKAGE_PATH? (Does roscd roscs work?)
  • Have you built ROSCS? (rosmake roscs)?
edit flag offensive delete link more

Comments

Thanks! But I already built ROSCS and "roscd roscs" works.

Po-Jen Lai gravatar image Po-Jen Lai  ( 2012-05-28 17:22:56 -0500 )edit

Question Tools

Stats

Asked: 2012-05-27 22:48:28 -0500

Seen: 2,128 times

Last updated: Sep 27 '13