patrykcieslak / stonefish

Stonefish - an advanced C++ simulation library designed for (but not limited to) marine robotics.
https://stonefish.readthedocs.io/
GNU General Public License v3.0
126 stars 32 forks source link

Problem running tests ? #15

Closed felipecode closed 3 years ago

felipecode commented 3 years ago

Hello Patryk ! Thanks a lot for this simulator. Seems really cool but I am having a bit of problems getting it to work. Might be something really dumb I am doing since I am bit rusty on C++ ( Getting back to it now) Describe the bug

I was able to compile and install the library without any problems. But for some reason I cant compile the test examples, and when I make my own example following your tutorial I have some linking problems. It might be my compiler version or something like that but i feel i don't have the info to fix it.

The test examples.

First, compiling then directly with the provided cmake does not work. doing

     cd Tests
     mkdir build && cd build && cmake .. && make 

gives me include error, since the include does contains the folder Stonefish in the path.

/home/felipe/stonefish/Tests/FloatingTest/main.cpp:26:10: fatal error: core/GraphicalSimulationApp.h: No such file or directory
 #include <core/GraphicalSimulationApp.h>

fixing that gives me an error on the data folder macro

/home/felipe/stonefish/Tests/FallingTest/main.cpp:49:35: error: expected primary-expression before ‘(’ token
     FallingTestApp app(std::string(DATA_DIR_PATH), s, h, simulationManager);

My own example

When I create the first example described here : https://stonefish.readthedocs.io/en/stable/building.html, compiling as :

g++ -o test main.cpp MySimulationManager.cpp -DDATA_DIR_PATH=\"${CMAKE_CURRENT_SOURCE_DIR}/Data/\" -lStonefish -I /usr/local/include/Stonefish/

gives me a weird linking error.

/tmp/ccIGdiDK.o: In function `MySimulationManager::MySimulationManager(float)':
MySimulationManager.cpp:(.text+0x28): undefined reference to `sf::SimulationManager::SimulationManager(float, sf::SolverType, sf::CollisionFilteringType)'
/tmp/ccIGdiDK.o: In function `MySimulationManager::BuildScenario()':
MySimulationManager.cpp:(.text+0xbb): undefined reference to `sf::SimulationManager::CreateMaterial(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, float, float)'
MySimulationManager.cpp:(.text+0x13e): undefined reference to `sf::SimulationManager::CreateMaterial(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, float, float)'
MySimulationManager.cpp:(.text+0x1ea): undefined reference to `sf::SimulationManager::SetMaterialsInteraction(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, float, float)'
MySimulationManager.cpp:(.text+0x2a5): undefined reference to `sf::SimulationManager::SetMaterialsInteraction(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, float, float)'
MySimulationManager.cpp:(.text+0x360): undefined reference to `sf::SimulationManager::SetMaterialsInteraction(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, float, float)'
MySimulationManager.cpp:(.text+0x73a): undefined reference to `sf::Plane::Plane(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, float, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, float)'
/tmp/ccIGdiDK.o:(.data.rel.ro._ZTV19MySimulationManager[_ZTV19MySimulationManager]+0x28): undefined reference to `sf::SimulationManager::SimulationStepCompleted(float)'
collect2: error: ld returned 1 exit status

I think it might be some flag on the CMAKE for the library compilation ? Maybe some library version that I have ?

THanks again for this amazing project

Environment

OS: ubuntu 18.04 Compiler: g++ 8.4

patrykcieslak commented 3 years ago

Hola Felipe! Nice to hear from you and see you interested in my project.

The examples that are in the Stonefish library are prepared just to make it easy for me to test things during development. If you want to play with them you need to run cmake -DBUILD_TESTS=ON .. (assuming you created the build directory under the main directory). This will compile and link the library and the examples locally, without installing the lib in the system.Then you can launch any of the examples in the Tests directory.

If you want to create your own example, using the shared library installed system-wide, you need to link a few libs. The easiest way is to use pkg-config. You can also look into the /usr/local/lib/pkgconfig/stonefish.pc file. You will see the flags needed for the compiler and linker.

I will add some compilation instructions. Good that you noticed it.

Patryk

felipecode commented 3 years ago

Thanks ! It works. I am a bit rusty in c++ indeed ! The compilation instructions would be great.