-1

I try to use the symbolicc++ toolbox with catkin. With a bigger project I have the structure:

//main2.cpp
#include "someheader.h"
int main(){
   Symbol a;
   Symbolicclass b(a);
   b.func();
}

//someheader.h
#ifndef SOMEHEADER_H
#define SOMEHEADER_H
    #include "symbolicclass.h"
#endif

//symbolicclass.h
#ifndef SYMBOLICCLASSHEADER_H
#define SYMBOLICCLASSHEADER_H
    #include "symbolicc++.h"
    using namespace std;

    class Symbolicclass{
       Symbolic value;
       public:
          void func();
          Symbolicclass(Symbolic _value){value=_value;};
    };
#endif

//symbolicclass.cpp
#include "symbolicclass.h"
void Symbolicclass::func(){ printf("whatever"); };

The whole catkin package can be found here: https://www.dropbox.com/s/4khoagm3uhsbs31/symbolic.zip?dl=0 Its 34Mb, as it includes the symbolicc++ library.

Than I get multiple definition errors of the SymbolicC++ library? e.g.

/home/Projects/SymbolicPlatform/Catkin/src/symbolic/thirdparty/SymbolicC++3-3.35/headers/symbolic/functions.h:1105: multiple definition of `Kronecker::Kronecker(Kronecker const&)'
CMakeFiles/symbolic_node.dir/src/main.cpp.o:/home/Projects/SymbolicPlatform/Catkin/src/symbolic/thirdparty/SymbolicC++3-3.35/headers/symbolic/functions.h:1105: first defined here

CMakeFiles/symbolic_node.dir/src/symbolic_agent.cpp.o: In function `Kronecker::Kronecker(Symbolic const&, Symbolic const&)':
/home/Projects/SymbolicPlatform/Catkin/src/symbolic/thirdparty/SymbolicC++3-3.35/headers/symbolic/functions.h:1107: multiple definition of `Kronecker::Kronecker(Symbolic const&, Symbolic const&)'
CMakeFiles/symbolic_node.dir/src/main.cpp.o:/home/Projects/SymbolicPlatform/Catkin/src/symbolic/thirdparty/SymbolicC++3-3.35/headers/symbolic/functions.h:1107: first defined here

etc. The only difference in CMakeLists is:

add_executable(symbolic_node src/main1.cpp) //WORKING FOR SIMPLE EXAMPLE

add_executable(symbolic_node src/main2.cpp src/symbolicclass.cpp)//CRAZY ERRORS

Do you have any idea what could be the problem?! For me it doesn't make sense that I get the multiple definition errors but I just use the #include "symbolicc++.h" once?! I think the error might be in the CMakeLists, there I build the symbolicc++ library and add it to the project. Thanks a lot for your help!

DentOpt
  • 77
  • 1
  • 6
  • did you apply the answer ? It looks like you did not !! It won't work with the two cpp along side each other ! – Vtik May 28 '16 at 01:23

1 Answers1

1

Ok, I think I will elaborate more about symbolicc++ use with catkin in ROS, so let's get to it step-by-step:

1 - download the only headers library (not the prebuilt, it looks like some bugs are in there) fro here and extract it somewhere.

2 - in CMakeLists.txt add the following line :

set(CMAKE_CXX_FLAGS "-fno-elide-constructors")

and add the headers folder to the includes :

include_directories( include ${catkin_INCLUDE_DIRS}  /path_to/SymbolicC++3-3.35/headers/)

-3 - if you need the library, just add it to the includes in your headers/sources as:

#include "symbolicc++.h"

and that should be all to be done !

Now, considering your problem, just change the add_executable to this :

add_executable(symbolic_node src/main2.cpp) //remove src/symbolicclass.cpp

It will work just fine.

Vtik
  • 3,073
  • 2
  • 23
  • 38
  • Thank you very much for your fast answer. As you requested I provided the whole catkin package in https://www.dropbox.com/s/dc1s6ypdzh56o7i/symbolic.zip?dl=0 I tried your suggestion, but the symbolicc++ is not only headers, which means he is not finding some function definitions. My previous attempt was to build a symbolicc++ library in the CMakeLists. You can find the code in the provided sample. There I unfortunately get the multiple definitions error?! It would be very kind of you, if you could have a look at the package. Thank you very much already for your help. – DentOpt May 25 '16 at 07:33
  • Sorry, I had to update the question. Also the code example is updated on dropbox. Actually it is not working, as I do not get the reference to the function in the source than: undefined reference to `Symbolicclass::func()' – DentOpt May 26 '16 at 09:50
  • lol, but you said that it worked yesterday, and it was so when I tried. you sure changed something since... – Vtik May 26 '16 at 09:52
  • It worked, because the function SymbolicClass::func() was private and never called. If I call it, like in the adjusted example from above, it can't find the function declaration, because the source isn't linked. I updated the example in the dropbox accordingly. – DentOpt May 26 '16 at 16:30
  • 1
    well, either create a shared library like [this](http://stackoverflow.com/questions/37423561/how-to-create-a-shared-library-in-ros/37423676#37423676) or define your function inside the header file. Anyway, It looks like a coding problem, **not related to Symbolic anymore**, so think of opening another question for that. Also, think of posting an [mcve](http://stackoverflow.com/help/mcve), not posting code on dropbox. Cheers, – Vtik May 26 '16 at 17:13
  • Hey, thanks for your help. The problem was actually in the symbolicc++ library. I was using the version "headers only" which defines the functions in the headers outside the classes. That leads to multiple definitions when you include it in more than one file. To solve these issues, I am now using the gnu library version which comes with source files. Thanks for your help again – DentOpt May 29 '16 at 09:44