johnBuffer/AntSimulator

issues building on Linux

ncoder-1 opened this issue · 5 comments

Hi,

I'm having a few issues building on Linux.

[1/4] Building CXX object CMakeFiles/AntSimulator.dir/src/utils.cpp.o
FAILED: CMakeFiles/AntSimulator.dir/src/utils.cpp.o 
/usr/bin/c++  -I../include -I../lib  -MD -MT CMakeFiles/AntSimulator.dir/src/utils.cpp.o -MF CMakeFiles/AntSimulator.dir/src/utils.cpp.o.d -o CMakeFiles/AntSimulator.dir/src/utils.cpp.o -c ../src/utils.cpp
In file included from ../src/utils.cpp:1:
../include/utils.hpp: In instantiation of ‘float getLength(const sf::Vector2<T>&) [with T = float]’:
../src/utils.cpp:22:40:   required from here
../include/utils.hpp:17:13: error: ‘sqrt’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
   17 |  return sqrt(v.x * v.x + v.y * v.y);
      |         ~~~~^~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/features.h:473,
                 from /usr/include/c++/10.2.0/x86_64-pc-linux-gnu/bits/os_defines.h:39,
                 from /usr/include/c++/10.2.0/x86_64-pc-linux-gnu/bits/c++config.h:518,
                 from /usr/include/c++/10.2.0/iosfwd:38,
                 from /usr/include/c++/10.2.0/ios:38,
                 from /usr/include/c++/10.2.0/ostream:38,
                 from /usr/include/SFML/System/Err.hpp:32,
                 from /usr/include/SFML/System.hpp:34,
                 from /usr/include/SFML/Window.hpp:32,
                 from /usr/include/SFML/Graphics.hpp:32,
                 from ../include/utils.hpp:2,
                 from ../src/utils.cpp:1:
/usr/include/bits/mathcalls.h:143:1: note: ‘double sqrt(double)’ declared here, later in the translation unit
  143 | __MATHCALL (sqrt,, (_Mdouble_ __x));
      | ^~~~~~~~~~
[2/4] Building CXX object CMakeFiles/AntSimulator.dir/src/display_manager.cpp.o
FAILED: CMakeFiles/AntSimulator.dir/src/display_manager.cpp.o 
/usr/bin/c++  -I../include -I../lib  -MD -MT CMakeFiles/AntSimulator.dir/src/display_manager.cpp.o -MF CMakeFiles/AntSimulator.dir/src/display_manager.cpp.o.d -o CMakeFiles/AntSimulator.dir/src/display_manager.cpp.o -c ../src/display_manager.cpp
In file included from ../include/marker.hpp:2,
                 from ../include/world.hpp:6,
                 from ../include/display_manager.hpp:4,
                 from ../src/display_manager.cpp:1:
../include/config.hpp:44:17: error: specializing member ‘Conf<>::FOOD_COLOR’ requires ‘template<>’ syntax
   44 | const sf::Color Conf<>::FOOD_COLOR = sf::Color(29, 129, 18);
      |                 ^~~~~~
../include/config.hpp:45:17: error: specializing member ‘Conf<>::TO_FOOD_COLOR’ requires ‘template<>’ syntax
   45 | const sf::Color Conf<>::TO_FOOD_COLOR = sf::Color(119, 211, 109);
      |                 ^~~~~~
../include/config.hpp:46:17: error: specializing member ‘Conf<>::TO_HOME_COLOR’ requires ‘template<>’ syntax
   46 | const sf::Color Conf<>::TO_HOME_COLOR = sf::Color(122, 105, 199);
      |                 ^~~~~~
../include/config.hpp:47:17: error: specializing member ‘Conf<>::COLONY_COLOR’ requires ‘template<>’ syntax
   47 | const sf::Color Conf<>::COLONY_COLOR = sf::Color(67, 46, 163);
      |                 ^~~~~~
../include/config.hpp:49:30: error: specializing member ‘Conf<>::ANT_TEXTURE’ requires ‘template<>’ syntax
   49 | std::shared_ptr<sf::Texture> Conf<>::ANT_TEXTURE;
      |                              ^~~~~~
../include/config.hpp:50:30: error: specializing member ‘Conf<>::MARKER_TEXTURE’ requires ‘template<>’ syntax
   50 | std::shared_ptr<sf::Texture> Conf<>::MARKER_TEXTURE;
      |                              ^~~~~~
In file included from ../include/ant.hpp:9,
                 from ../include/colony.hpp:5,
                 from ../include/display_manager.hpp:5,
                 from ../src/display_manager.cpp:1:
../include/direction.hpp: In member function ‘void Direction::updateVec()’:
../include/direction.hpp:62:13: error: ‘cos’ was not declared in this scope
   62 |   m_vec.x = cos(m_angle);
      |             ^~~
../include/direction.hpp:63:13: error: ‘sin’ was not declared in this scope; did you mean ‘sign’?
   63 |   m_vec.y = sin(m_angle);
      |             ^~~
      |             sign
../include/direction.hpp: In member function ‘void Direction::updateTargetVec()’:
../include/direction.hpp:68:20: error: ‘cos’ was not declared in this scope
   68 |   m_target_vec.x = cos(m_target_angle);
      |                    ^~~
../include/direction.hpp:69:20: error: ‘sin’ was not declared in this scope; did you mean ‘sign’?
   69 |   m_target_vec.y = sin(m_target_angle);
      |                    ^~~
      |                    sign
In file included from ../include/world.hpp:8,
                 from ../include/display_manager.hpp:4,
                 from ../src/display_manager.cpp:1:
../include/utils.hpp: In instantiation of ‘float getLength(const sf::Vector2<T>&) [with T = float]’:
../include/ant.hpp:65:41:   required from here
../include/utils.hpp:17:13: error: ‘sqrt’ was not declared in this scope
   17 |  return sqrt(v.x * v.x + v.y * v.y);
      |         ~~~~^~~~~~~~~~~~~~~~~~~~~~~
[3/4] Building CXX object CMakeFiles/AntSimulator.dir/src/main.cpp.o
FAILED: CMakeFiles/AntSimulator.dir/src/main.cpp.o 
/usr/bin/c++  -I../include -I../lib  -MD -MT CMakeFiles/AntSimulator.dir/src/main.cpp.o -MF CMakeFiles/AntSimulator.dir/src/main.cpp.o.d -o CMakeFiles/AntSimulator.dir/src/main.cpp.o -c ../src/main.cpp
In file included from ../include/marker.hpp:2,
                 from ../include/ant.hpp:4,
                 from ../include/colony.hpp:5,
                 from ../src/main.cpp:4:
../include/config.hpp:44:17: error: specializing member ‘Conf<>::FOOD_COLOR’ requires ‘template<>’ syntax
   44 | const sf::Color Conf<>::FOOD_COLOR = sf::Color(29, 129, 18);
      |                 ^~~~~~
../include/config.hpp:45:17: error: specializing member ‘Conf<>::TO_FOOD_COLOR’ requires ‘template<>’ syntax
   45 | const sf::Color Conf<>::TO_FOOD_COLOR = sf::Color(119, 211, 109);
      |                 ^~~~~~
../include/config.hpp:46:17: error: specializing member ‘Conf<>::TO_HOME_COLOR’ requires ‘template<>’ syntax
   46 | const sf::Color Conf<>::TO_HOME_COLOR = sf::Color(122, 105, 199);
      |                 ^~~~~~
../include/config.hpp:47:17: error: specializing member ‘Conf<>::COLONY_COLOR’ requires ‘template<>’ syntax
   47 | const sf::Color Conf<>::COLONY_COLOR = sf::Color(67, 46, 163);
      |                 ^~~~~~
../include/config.hpp:49:30: error: specializing member ‘Conf<>::ANT_TEXTURE’ requires ‘template<>’ syntax
   49 | std::shared_ptr<sf::Texture> Conf<>::ANT_TEXTURE;
      |                              ^~~~~~
../include/config.hpp:50:30: error: specializing member ‘Conf<>::MARKER_TEXTURE’ requires ‘template<>’ syntax
   50 | std::shared_ptr<sf::Texture> Conf<>::MARKER_TEXTURE;
      |                              ^~~~~~
In file included from ../include/ant.hpp:9,
                 from ../include/colony.hpp:5,
                 from ../src/main.cpp:4:
../include/direction.hpp: In member function ‘void Direction::updateVec()’:
../include/direction.hpp:62:13: error: ‘cos’ was not declared in this scope
   62 |   m_vec.x = cos(m_angle);
      |             ^~~
../include/direction.hpp:63:13: error: ‘sin’ was not declared in this scope; did you mean ‘sign’?
   63 |   m_vec.y = sin(m_angle);
      |             ^~~
      |             sign
../include/direction.hpp: In member function ‘void Direction::updateTargetVec()’:
../include/direction.hpp:68:20: error: ‘cos’ was not declared in this scope
   68 |   m_target_vec.x = cos(m_target_angle);
      |                    ^~~
../include/direction.hpp:69:20: error: ‘sin’ was not declared in this scope; did you mean ‘sign’?
   69 |   m_target_vec.y = sin(m_target_angle);
      |                    ^~~
      |                    sign
In file included from ../include/world.hpp:8,
                 from ../include/ant.hpp:6,
                 from ../include/colony.hpp:5,
                 from ../src/main.cpp:4:
../include/utils.hpp: In instantiation of ‘float getLength(const sf::Vector2<T>&) [with T = float]’:
../include/ant.hpp:65:41:   required from here
../include/utils.hpp:17:13: error: ‘sqrt’ was not declared in this scope
   17 |  return sqrt(v.x * v.x + v.y * v.y);
      |         ~~~~^~~~~~~~~~~~~~~~~~~~~~~

Missing include <cmath> was added to include/utils.hpp which fixed the sqrt/cos/sin errors. I've also added the missing template<> syntax to include/config.hpp but now I get a linker error:

[3/3] Linking CXX executable AntSimulator
FAILED: AntSimulator 
: && /usr/bin/c++   CMakeFiles/AntSimulator.dir/src/display_manager.cpp.o CMakeFiles/AntSimulator.dir/src/main.cpp.o CMakeFiles/AntSimulator.dir/src/utils.cpp.o -o AntSimulator  /usr/lib/libsfml-graphics.so.2.5.1  -lpthread  /usr/lib/libsfml-window.so.2.5.1  /usr/lib/libsfml-system.so.2.5.1 && :
/usr/bin/ld: CMakeFiles/AntSimulator.dir/src/main.cpp.o:(.bss+0x0): multiple definition of `Conf<int>::ANT_COLOR'; CMakeFiles/AntSimulator.dir/src/display_manager.cpp.o:(.bss+0x0): first defined here
/usr/bin/ld: CMakeFiles/AntSimulator.dir/src/main.cpp.o:(.bss+0x4): multiple definition of `Conf<int>::FOOD_COLOR'; CMakeFiles/AntSimulator.dir/src/display_manager.cpp.o:(.bss+0x4): first defined here
/usr/bin/ld: CMakeFiles/AntSimulator.dir/src/main.cpp.o:(.bss+0x8): multiple definition of `Conf<int>::TO_FOOD_COLOR'; CMakeFiles/AntSimulator.dir/src/display_manager.cpp.o:(.bss+0x8): first defined here
/usr/bin/ld: CMakeFiles/AntSimulator.dir/src/main.cpp.o:(.bss+0xc): multiple definition of `Conf<int>::TO_HOME_COLOR'; CMakeFiles/AntSimulator.dir/src/display_manager.cpp.o:(.bss+0xc): first defined here
/usr/bin/ld: CMakeFiles/AntSimulator.dir/src/main.cpp.o:(.bss+0x10): multiple definition of `Conf<int>::COLONY_COLOR'; CMakeFiles/AntSimulator.dir/src/display_manager.cpp.o:(.bss+0x10): first defined here
/usr/bin/ld: CMakeFiles/AntSimulator.dir/src/main.cpp.o: warning: relocation against `_ZN4ConfIiE11ANT_TEXTUREE' in read-only section `.text._ZN4ConfIiE12freeTexturesEv[_ZN4ConfIiE12freeTexturesEv]'
/usr/bin/ld: CMakeFiles/AntSimulator.dir/src/display_manager.cpp.o: in function `World::render(sf::RenderTarget&, sf::RenderStates const&, bool) const':
display_manager.cpp:(.text._ZNK5World6renderERN2sf12RenderTargetERKNS0_12RenderStatesEb[_ZNK5World6renderERN2sf12RenderTargetERKNS0_12RenderStatesEb]+0xfb): undefined reference to `Conf<int>::MARKER_TEXTURE'
/usr/bin/ld: CMakeFiles/AntSimulator.dir/src/display_manager.cpp.o: in function `Colony::render(sf::RenderTarget&, sf::RenderStates const&) const':
display_manager.cpp:(.text._ZNK6Colony6renderERN2sf12RenderTargetERKNS0_12RenderStatesE[_ZNK6Colony6renderERN2sf12RenderTargetERKNS0_12RenderStatesE]+0x229): undefined reference to `Conf<int>::ANT_TEXTURE'
/usr/bin/ld: CMakeFiles/AntSimulator.dir/src/main.cpp.o: in function `Conf<int>::loadTextures()':
main.cpp:(.text._ZN4ConfIiE12loadTexturesEv[_ZN4ConfIiE12loadTexturesEv]+0x2e): undefined reference to `Conf<int>::ANT_TEXTURE'
/usr/bin/ld: main.cpp:(.text._ZN4ConfIiE12loadTexturesEv[_ZN4ConfIiE12loadTexturesEv]+0x46): undefined reference to `Conf<int>::ANT_TEXTURE'
/usr/bin/ld: main.cpp:(.text._ZN4ConfIiE12loadTexturesEv[_ZN4ConfIiE12loadTexturesEv]+0xaf): undefined reference to `Conf<int>::ANT_TEXTURE'
/usr/bin/ld: main.cpp:(.text._ZN4ConfIiE12loadTexturesEv[_ZN4ConfIiE12loadTexturesEv]+0xdb): undefined reference to `Conf<int>::MARKER_TEXTURE'
/usr/bin/ld: main.cpp:(.text._ZN4ConfIiE12loadTexturesEv[_ZN4ConfIiE12loadTexturesEv]+0xf3): undefined reference to `Conf<int>::MARKER_TEXTURE'
/usr/bin/ld: main.cpp:(.text._ZN4ConfIiE12loadTexturesEv[_ZN4ConfIiE12loadTexturesEv]+0x15c): undefined reference to `Conf<int>::MARKER_TEXTURE'
/usr/bin/ld: CMakeFiles/AntSimulator.dir/src/main.cpp.o: in function `Conf<int>::freeTextures()':
main.cpp:(.text._ZN4ConfIiE12freeTexturesEv[_ZN4ConfIiE12freeTexturesEv]+0x32): undefined reference to `Conf<int>::ANT_TEXTURE'
/usr/bin/ld: main.cpp:(.text._ZN4ConfIiE12freeTexturesEv[_ZN4ConfIiE12freeTexturesEv]+0x62): undefined reference to `Conf<int>::MARKER_TEXTURE'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

Any ideas?

Hi,
It is compiling fine with vc15 but I guess there are differences between these compilers.
Can you tell me which compliler you are using ? It will be easier for me to reproduce and fix :)

Just good old g++ but it does the same thing with clang++ as well.

I will look into this :)

It should be better now, tested on Ubuntu 20. Let me know if you have any issues.

Yep that worked perfectly, thanks!