1

Just got stuck in compiling a simple C++ program with Eigen C++ when using intel oneAPI DPC++/C++ compiler: The example contains two .cpp files (main.cpp and Preprocessing.cpp) and one include file (struct_INFO.h).

I don't know why the compiler gives errors as the image shows. Error messages from Intel compiler:

duplicate symbol: bool const std::_Is_integral<bool>
duplicate symbol: bool const std::_Is_integral<char>
duplicate symbol: bool const std::_Is_integral<signed char> 
duplicate symbol: bool const std::_Is_integral<unsigned char>
duplicate symbol: bool const std::_Is_integral<wchar_t>
duplicate symbol: bool const std::_Is_integral<char16_t>
duplicate symbol: bool const std::_Is_integral<char32_t>

... All the errors are similar, so I just show some of them.

It seems that I can include neither the Eigen head file (<Eigen/Core>) nor the head file struct_INFO.h, which containing Eigen head file, in my subroutine Preprocessing.cpp.

The only way that I know to fix the problem is to merge the two .cpp files into one.

However, this approach is kind of cumbersome that I need to put all the subroutines in one file as long as I need to use the Eigen variables.

Does anyone know how to solve this problem? Thank you.

  1. main.cpp:

    #include "struct_INFO.h"
    #include <Eigen/Core>
    
    int Preprocessing(struct_INFO& struct_INFO_obj);
    
    int main(int* argc, char** argv)
    {
        struct_INFO struct_INFO_obj;
        Preprocessing(struct_INFO_obj);
        return 0;
    }
    
  2. Preprocessing.cpp

    #include "struct_INFO.h"
    
    int Preprocessing(struct_INFO& struct_INFO_obj)
    {
           return 1;
    }
    
  3. struct_INFO.h

    #include <Eigen/Core>
    
    class struct_INFO
    {
           public:
           Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic> Matrix;
    };
    
phuclv
  • 37,963
  • 15
  • 156
  • 475
Jason
  • 11
  • 2
  • 1
    You should use three ticks \`\`\`cpp code here \`\`\` to format code blocks and please use newlines in there. Also if you provide console output, please do so as text, as one cannot easily copy from a picture. – Eike Feb 07 '22 at 20:59
  • Thank you for reminding me about the format. This is my first time to post a question here. I tried to follow the format, but somehow didn't make it right. Thank you again! – Jason Feb 07 '22 at 21:49
  • Compiles+links fine with ICX on https://godbolt.org/z/5ThMvr163, with Eigen 3.4. The resulting asm doesn't define any of those symbols in the first place. But Godbolt can't test with multiple compilation units linking together. – Peter Cordes Feb 08 '22 at 01:57
  • @Jason Thanks for editing your question. Someone was faster than me and edited your question again because your edit still bungled some code formatting. You should have a look at the used syntax as it makes it easier to understand your question. – Eike Feb 08 '22 at 07:52
  • 1
    Are you just missing an include guard or a #pragma once in `struct_INFO.h`? – Eike Feb 08 '22 at 07:54
  • @Peter Cordes, thank you for help. I am still trying to figure out how to do. – Jason Feb 08 '22 at 20:27
  • @Eike, you are right. Thanks for the one who helped edit my post. I tried some ways such as using #ifndef and #define, but the compiler still shows the same errors. I just tried your suggestion using #pragma once. There are still the same errors shown up. – Jason Feb 08 '22 at 20:30

0 Answers0