0
template <class Scalar>
struct Pattern24 {
  //          00  01
  //
  //      02  03  04  05
  //
  //  06  07  08  09  10  11
  //
  //  12  13  14  15  16  17
  //
  //      18  19  20  21
  //
  //          22  23
  //
  // -----> x
  // |
  // |
  // y

  static constexpr Scalar pattern_raw[][2] = {
      {-1, 5},  {1, 5},

      {-3, 3},  {-1, 3},  {1, 3},   {3, 3},

      {-5, 1},  {-3, 1},  {-1, 1},  {1, 1},  {3, 1},  {5, 1},

      {-5, -1}, {-3, -1}, {-1, -1}, {1, -1}, {3, -1}, {5, -1},

      {-3, -3}, {-1, -3}, {1, -3},  {3, -3},

      {-1, -5}, {1, -5}

  };

  static constexpr int PATTERN_SIZE =
      sizeof(pattern_raw) / (2 * sizeof(Scalar));

  typedef Eigen::Matrix<Scalar, 2, PATTERN_SIZE> Matrix2P;
  static const Matrix2P pattern2;
};

template <class Scalar>
const typename Pattern24<Scalar>::Matrix2P Pattern24<Scalar>::pattern2 =
    Eigen::Map<Pattern24<Scalar>::Matrix2P>((Scalar*)
                                                Pattern24<Scalar>::pattern_raw);

Above is the code I am trying to use in a project. But unfortunately while trying to link the files I get the following error:

[build] : && /opt/cuda/bin/g++
[build] /usr/bin/ld: CMakeFiles/odometry.dir/src/odometry.cpp.o: warning: relocation against `_ZN6visnav9Pattern24IfE11pattern_rawE' in read-only section `.text'
[build] /usr/bin/ld: CMakeFiles/odometry.dir/src/odometry.cpp.o: in function `__static_initialization_and_destruction_0(int, int)':
[build] undefined reference to `visnav::Pattern24<float>::pattern_raw'
[build] /usr/bin/ld: warning: creating DT_TEXTREL in a PIE
[build] collect2: error: ld returned 1 exit status

After adding the above code as a header file to the project, it stopped compiling. I suspect the problem could because of my G++ version, which appears to be GCC 10.2.

  • What C++ settings do you use? – 273K Jun 27 '21 at 15:44
  • For the CMake I use the following set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_POSITION_INDEPENDENT_CODE ON) and as for flags "-fPIC -lstdc++ -ftemplate-backtrace-limit=0 -Wall -Wextra". Also I have already check the link you have provided but it doesn't seem to help... – Yiğit Aras Tunalı Jun 27 '21 at 15:50
  • @drescherjm That seems to be a possible problem yes, but I would rather not go up to c++17 because of dependency issues. Is there any way I can change my code to make it work with c++14? – Yiğit Aras Tunalı Jun 27 '21 at 15:54
  • Sorry I removed my comment about enabling c++17. – drescherjm Jun 27 '21 at 16:33
  • @drescherjm ended up solving the problem as the code I wrote uses c++17. I had to fix other parts of the project but overall it worked! Thanks. – Yiğit Aras Tunalı Jun 28 '21 at 19:44

0 Answers0