Library loading error after trying get a new sensor in the controller file

Requests regarding how to set up experiments in ARGoS.
Swingna
Posts: 6
Joined: Mon Jun 01, 2020 3:42 pm

Library loading error after trying get a new sensor in the controller file

Postby Swingna » Thu Jun 04, 2020 12:58 pm

Hi,

I am currently designing a new sensor and trying to apply it into controller file.
After building the updated files, there was no compilation errors. However, it causes error when I tried to run the file.

The error is below:
[FATAL] Error initializing controllers
[FATAL] Can't load library "build/controllers/footbot_phero/libfootbot_phero" even after trying to add extensions for shared library (so) and module library (so):
/usr/local/lib/argos3/build/controllers/footbot_phero/libfootbot_phero: /usr/local/lib/argos3/build/controllers/footbot_phero/libfootbot_phero: cannot open shared object file: No such file or directory
/usr/local/lib/argos3/build/controllers/footbot_phero/libfootbot_phero.so: /usr/local/lib/argos3/build/controllers/footbot_phero/libfootbot_phero.so: cannot open shared object file: No such file or directory
/usr/local/lib/argos3/build/controllers/footbot_phero/libfootbot_phero.so: OK

To figure out why the problem has occurred, I repeated debugging and I've found that this line of code led this error.

Code: Select all

m_pcWheels = GetActuator<CCI_DifferentialSteeringActuator>("differential_steering"); m_pcProximity = GetSensor <CCI_FootBotProximitySensor >("footbot_proximity" ); m_pcLight = GetSensor <CCI_FootBotLightSensor >("footbot_light" ); m_pcPhero = GetSensor <CCI_FootBotPheroSensor >("footbot_phero" ); // This is my new sensor
After commenting out the last line of code (getting a pheromone sensor), it worked perfectly well. Do you know why this might cause a problem when I load a library even though it is successfully compiled? Where should I take a deep look into? The idea of sensor is that I generate a matrix with the size of arena in the loop function which contains values and the sensor read the value from the loop function. The controller is trying to get the value from the matrix retrieved by the sensor.

Thank you very much :)

pincy
Site Admin
Posts: 447
Joined: Thu Mar 08, 2012 8:04 pm
Location: Boston, MA
Contact:

Re: Library loading error after trying get a new sensor in the controller file

Postby pincy » Thu Jun 04, 2020 8:18 pm

Try using the command "ldd" (LLD in small letters) on the library that contains your new sensor and look for possible errors there. Check that:

1. all the .cpp files are included in the creation of the library
2. all the methods have been implemented

If you share the code with me, I can see what might be the problem.
I made ARGoS.

Swingna
Posts: 6
Joined: Mon Jun 01, 2020 3:42 pm

Re: Library loading error after trying get a new sensor in the controller file

Postby Swingna » Tue Jun 09, 2020 2:38 am

Thank you for your answer. I have checked the cpp files and methods whether they are included or implemented. However, I am not too sure since I don't think I fully understand how the simulator works. There would probably be something I have missed. By the way, what is the problem with the library when I do not use all the methods in the file? I found this error

I attached the zip file of the directory I have used (argos3-examples + my works). In the directory, there is a file called README_SN in which I wrote what I have tried so far to make someone understand about it.

Thank you for the help!
Attachments
argos3-examples.zip
(6.06 MiB) Downloaded 23 times

pincy
Site Admin
Posts: 447
Joined: Thu Mar 08, 2012 8:04 pm
Location: Boston, MA
Contact:

Re: Library loading error after trying get a new sensor in the controller file

Postby pincy » Tue Jun 09, 2020 6:14 am

When I try to compile your code, I get this error (on Mac with Clang):

Code: Select all

Undefined symbols for architecture x86_64: "argos::CCI_FootBotPheroSensor::GetReadings() const", referenced from: CFootBotDiffusion::ControlStep() in footbot_phero.cpp.o "typeinfo for argos::CCI_FootBotPheroSensor", referenced from: argos::CCI_FootBotPheroSensor* argos::CCI_Controller::GetSensor<argos::CCI_FootBotPheroSensor>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in footbot_phero.cpp.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make[2]: *** [controllers/footbot_phero/libfootbot_phero.dylib] Error 1 make[1]: *** [controllers/footbot_phero/CMakeFiles/footbot_phero.dir/all] Error 2 make: *** [all] Error 2
I don't understand why your code is scattered around, but the issue seems to be that you're not linking correctly among the many libraries you're creating. I suggest you to put all your files in the same directory and create a single library, rather than many. This will fix the problem you're encountering.

I am not sure what you're trying to achieve, but to the best of my understanding you're trying to add a new sensor to the foot-bot. In this case, you'll need to also change the CFootbotEntity class to contain the sensor entity you created, or your code won't work.
I made ARGoS.

Swingna
Posts: 6
Joined: Mon Jun 01, 2020 3:42 pm

Re: Library loading error after trying get a new sensor in the controller file

Postby Swingna » Tue Jun 09, 2020 1:28 pm

Thank you very much for the reply!

I did not see such error in my environment (Linux Ubuntu 18.04 / gcc)

Yes I have been trying to add a new sensor to the foot-bot. As I haven't changed CFootbotEntity, it might be a reason for the problem.

I'll try your two suggestion first.

Again, thank you for the help! :D

pincy
Site Admin
Posts: 447
Joined: Thu Mar 08, 2012 8:04 pm
Location: Boston, MA
Contact:

Re: Library loading error after trying get a new sensor in the controller file

Postby pincy » Tue Jun 09, 2020 1:45 pm

The foot-bot entity modification has nothing to do with the problem at hand. You're having a linking problem, which can be solved in many ways. But the simplest is just to put all the files your created in the same library.
I made ARGoS.

Swingna
Posts: 6
Joined: Mon Jun 01, 2020 3:42 pm

Re: Library loading error after trying get a new sensor in the controller file

Postby Swingna » Wed Jun 10, 2020 1:33 pm

Hi,

Thank you very much! As you suggested I moved all the files related to sensors into one directory "phero_sensor" and did all again. However, I still have the same issue.

I found out that the problem occurs when I try linking two particular sources files "footbot_phero_sensor.cpp" and "footbot_phero_sensor.h" in CMakeList.txt file in phero_sensor directory. I experimented other source files but linking these two to the target gave me the library loading error.

As you mentioned before, I checked if all the methods have been implemented and they are all implemented in cpp file. However, it gives the error.

I still do not understand what is the problem with the library even though the compilation was successful and the library was also created.

If you are happy, could you check my code again please?

I attached the updated zip file here and all the sensor related source files are in the phero_sensor directory.

Thank you and have a good day.
Attachments
argos3-examples.zip
(6.67 MiB) Downloaded 25 times

pincy
Site Admin
Posts: 447
Joined: Thu Mar 08, 2012 8:04 pm
Location: Boston, MA
Contact:

Re: Library loading error after trying get a new sensor in the controller file

Postby pincy » Thu Jun 11, 2020 1:04 am

I tried to compile your code and got this error:

Code: Select all

[ 71%] Building CXX object loop_functions/phero_loop_functions/CMakeFiles/phero_loop_functions.dir/phero_loop_functions.cpp.o /Users/cpinciroli/Downloads/argos3-examples/loop_functions/phero_loop_functions/phero_loop_functions.cpp:193:13: error: no member named 'SetRange' in 'argos::CMatrix<500, 500>' pheroMat.SetRange(PosToIdx(-0.1, 100, 2.5), PosToIdx(0.1, 100, 2.5),
I simply commented the line out to be able to keep going. Then I got this error:

Code: Select all

[ 72%] Linking CXX shared module libphero_loop_functions.so Undefined symbols for architecture x86_64: "QFont::QFont()", referenced from: CPheroQTUserFunctions::DrawInWorld() in phero_qt_user_functions.cpp.o "QFont::~QFont()", referenced from: CPheroQTUserFunctions::DrawInWorld() in phero_qt_user_functions.cpp.o ld: symbol(s) not found for architecture x86_64
This says that you haven't linked your code against the Qt libraries. So I added ${ARGOS_QTOPENGL_LIBRARIES} to loop_functions/phero_loop_functions/CMaleLists.txt:

Code: Select all

if(ARGOS_COMPILE_QTOPENGL) target_link_libraries(phero_loop_functions argos3plugin_simulator_qtopengl ${ARGOS_QTOPENGL_LIBRARIES}) endif(ARGOS_COMPILE_QTOPENGL)
Then the compilation continued and I got this error:

Code: Select all

[100%] Linking CXX shared library libfootbot_phero.dylib Undefined symbols for architecture x86_64: "CPheroLoopFunctions::PosToIdx(double, unsigned int, double)", referenced from: argos::CFootBotPheroSensor::Update() in footbot_phero_sensor.cpp.o "argos::CPheroSensorEquippedEntity::ParseType(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const", referenced from: argos::CPheroSensorEquippedEntity::Init(ticpp::Element&) in phero_sensor_equipped_entity.cpp.o "typeinfo for CPheroLoopFunctions", referenced from: argos::CFootBotPheroSensor::CFootBotPheroSensor() in footbot_phero_sensor.cpp.o "_lua_getfield", referenced from: argos::CCI_FootBotPheroSensor::ReadingsToLuaState(lua_State*) in ci_footbot_phero_sensor.cpp.o "_lua_gettable", referenced from: argos::CCI_FootBotPheroSensor::ReadingsToLuaState(lua_State*) in ci_footbot_phero_sensor.cpp.o "_lua_pushnumber", referenced from: argos::CCI_FootBotPheroSensor::ReadingsToLuaState(lua_State*) in ci_footbot_phero_sensor.cpp.o "_lua_setfield", referenced from: argos::CCI_FootBotPheroSensor::ReadingsToLuaState(lua_State*) in ci_footbot_phero_sensor.cpp.o "_lua_settop", referenced from: argos::CCI_FootBotPheroSensor::ReadingsToLuaState(lua_State*) in ci_footbot_phero_sensor.cpp.o
As a rule, you should not use the loop functions inside a sensor. The loop functions are meant for experiment-specific code, but your sensor is written as an experiment-agnostic one. Anyway, let's say we keep going with this. I make the following modifications. First, in phero_loop_functions/CMakeList.txt I changed MODULE to SHARED, so you can link libphero_loop_functions.so to libphero_sensor.so:

Code: Select all

add_library(phero_loop_functions SHARED ${phero_loop_functions_SOURCES})
Then I added phero_loop_functions to the list of libraries to link against in phero_sensor/CMakeLists.txt:

Code: Select all

target_link_libraries(footbot_phero argos3core_simulator argos3plugin_simulator_footbot argos3plugin_simulator_genericrobot phero_loop_functions)
This created a new linking error, namely

Code: Select all

[100%] Linking CXX shared library libfootbot_phero.dylib Undefined symbols for architecture x86_64: "argos::CPheroSensorEquippedEntity::ParseType(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const", referenced from: argos::CPheroSensorEquippedEntity::Init(ticpp::Element&) in phero_sensor_equipped_entity.cpp.o "_lua_getfield", referenced from: argos::CCI_FootBotPheroSensor::ReadingsToLuaState(lua_State*) in ci_footbot_phero_sensor.cpp.o "_lua_gettable", referenced from: argos::CCI_FootBotPheroSensor::ReadingsToLuaState(lua_State*) in ci_footbot_phero_sensor.cpp.o "_lua_pushnumber", referenced from: argos::CCI_FootBotPheroSensor::ReadingsToLuaState(lua_State*) in ci_footbot_phero_sensor.cpp.o "_lua_setfield", referenced from: argos::CCI_FootBotPheroSensor::ReadingsToLuaState(lua_State*) in ci_footbot_phero_sensor.cpp.o "_lua_settop", referenced from: argos::CCI_FootBotPheroSensor::ReadingsToLuaState(lua_State*) in ci_footbot_phero_sensor.cpp.o
Which I fixed by uncommenting lines 156-160 of phero_equipped_entity.cpp. This left me my another linking error:

Code: Select all

Undefined symbols for architecture x86_64: "_lua_getfield", referenced from: argos::CCI_FootBotPheroSensor::ReadingsToLuaState(lua_State*) in ci_footbot_phero_sensor.cpp.o "_lua_gettable", referenced from: argos::CCI_FootBotPheroSensor::ReadingsToLuaState(lua_State*) in ci_footbot_phero_sensor.cpp.o "_lua_pushnumber", referenced from: argos::CCI_FootBotPheroSensor::ReadingsToLuaState(lua_State*) in ci_footbot_phero_sensor.cpp.o "_lua_setfield", referenced from: argos::CCI_FootBotPheroSensor::ReadingsToLuaState(lua_State*) in ci_footbot_phero_sensor.cpp.o "_lua_settop", referenced from: argos::CCI_FootBotPheroSensor::ReadingsToLuaState(lua_State*) in ci_footbot_phero_sensor.cpp.o ld: symbol(s) not found for architecture x86_64
Which I fixed by adding ${LUA_LIBRARIES} to phero_sensor/CMakeLists.txt:

Code: Select all

target_link_libraries(footbot_phero argos3core_simulator argos3plugin_simulator_footbot argos3plugin_simulator_genericrobot phero_loop_functions ${LUA_LIBRARIES})
With all this, compilation finally works. I tried to run

Code: Select all

argos3 -c experiments/phero.argos
and the simulator starts correctly.

I strongly suggest you to read about linking errors and CMake before you keep coding with ARGoS, so you learn how to fix these errors yourself.
I made ARGoS.

Swingna
Posts: 6
Joined: Mon Jun 01, 2020 3:42 pm

Re: Library loading error after trying get a new sensor in the controller file

Postby Swingna » Thu Jun 11, 2020 4:01 pm

Thank you very much for the help!

Your explanation helped me not only the technical issues, but also understanding the simulator much better.

I have implemented all the things you have shared and the simulator works for me too.

I was struggling with this for more than a week and now it is finally solved thanks to your help.

Also, thanks for the suggestion too!

Hope you have a good day!

Swingna
Posts: 6
Joined: Mon Jun 01, 2020 3:42 pm

Re: Library loading error after trying get a new sensor in the controller file

Postby Swingna » Fri Jun 12, 2020 8:18 am

Hi Carlo,

After I solved the library loading error with your help, I tried to run the experiments. But it gave me the new error:

Code: Select all

[FATAL] Failed to initialize the space. [FATAL] Failed to initialize entity "fb_0". [FATAL] Failed to initialize controllable entity "controller_0". [FATAL] Can't set controller for controllable entity "controller_0" [FATAL] While getting a component from a composable entity [FATAL] Component "phero_sensors" does not exist in "fb_0"
I found out that the new sensor equipped entity is not added to footbot_entity, thereby occuring the exception.

Rather than modifying footbot_entity.cpp & h files - I made a new source files - phero_sensor/phero_footbot_entity.cpp & h not to change the original footbot source files. I added the phero sensor in the phero_footbot_entity.cpp & h and tried run the experiments.

After these, I changed experiments/phero.argos as:

Code: Select all

<phero-foot-bot id="fb_0"> <body position="0,0,0" orientation="0,0,0" /> <controller config="fpc"/> </phero-foot-bot>
But this time it gave the error:

Code: Select all

The matching physics engine ("dyn2d"), cannot house movable entity "fb_0"@(0.0.0)
To solve this issue, I created new source files "phero_sensors/dynamics2d_phero_footbot_model.cpp & h modifying "dynamics2d_footbot_model.cpp&h" to include phero_footbot_entity into dyn2d physics engine.

After this, there was no exception occurred, but the footbot did not show up in the simulator and the simulator crashed and gave this error message.

Code: Select all

[FATAL] Entity map for type "foot-bot" not found.
I understand that I have to add phero_footbot_entity into somewhere in the simulator so that it can be considered as entity like original footbot, but I am struggling finding where to go now.

Could you let me know where I should look up to solve this problem please (where I can find entity map to add phero-foot-bot and etc)? and is there the better way to solve above issues that you suggest?

I attached the current files as before.

Thank you very much for the help.

Seongin
Attachments
argos3-examples-20200612.zip
(8.09 MiB) Downloaded 14 times


Return to “How to... ?”



cron