c++mxnet

The mxnet's cpp package reports error when #include regarding dmlc/base.h


I would like to use the cpp package of mxnet. So what I did was initially to download the mxnet files from the related github repository. Then I did the following:

cd mxnet

mkdir build

cd build

cmake -DUSE_CPP_PACKAGE=1 ..

cmake --build . --target install

Everything ran smoothly without errors etc. I had already installed the related prerequisities. My issue is that when trying to use the cpp package:

#include "mxnet-cpp/MxNetCpp.h"

I receiving three errors and three warnings all related to the dmlc package:

error 1: /usr/local/include/dmlc/base.h:247:1: error: template with C linkage template

error 2: /usr/local/include/dmlc/base.h:260:1: error: template with C linkage template

error 3:/usr/local/include/dmlc/base.h:282:20: error: conflicting declaration of C function ‘const char* dmlc::BeginPtr(const string&)’

Since I am new to c++ I would appreciate and related feedback for resolving the issue.

 The exact log is:
In file included from /usr/local/include/dmlc/endian.h:9,
                 from /usr/include/x86_64-linux-gnu/sys/types.h:176,
                 from /usr/include/stdlib.h:395,
                 from /usr/include/c++/11/cstdlib:75,
                 from /usr/include/c++/11/ext/string_conversions.h:41,
                 from /usr/include/c++/11/bits/basic_string.h:6608,
                 from /usr/include/c++/11/string:55,
                 from /usr/local/include/mxnet-cpp/executor.hpp:31,
                 from /usr/local/include/mxnet-cpp/MxNetCpp.h:29,
                 from /home/stathis/Documents/Documents/Documents/Untitled.cpp:1:
/usr/local/include/dmlc/base.h:247:1: error: template with C linkage
  247 | template<typename T>
      | ^~~~~~~~
In file included from /usr/include/features.h:486,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/c++config.h:586,
                 from /usr/include/c++/11/bits/stl_algobase.h:59,
                 from /usr/include/c++/11/vector:60,
                 from /usr/local/include/mxnet-cpp/executor.hpp:29,
                 from /usr/local/include/mxnet-cpp/MxNetCpp.h:29,
                 from /home/stathis/Documents/Documents/Documents/Untitled.cpp:1:
/usr/include/x86_64-linux-gnu/sys/types.h:27:1: note: 'extern "C"' linkage started here
   27 | __BEGIN_DECLS
      | ^~~~~~~~~~~~~
In file included from /usr/local/include/dmlc/endian.h:9,
                 from /usr/include/x86_64-linux-gnu/sys/types.h:176,
                 from /usr/include/stdlib.h:395,
                 from /usr/include/c++/11/cstdlib:75,
                 from /usr/include/c++/11/ext/string_conversions.h:41,
                 from /usr/include/c++/11/bits/basic_string.h:6608,
                 from /usr/include/c++/11/string:55,
                 from /usr/local/include/mxnet-cpp/executor.hpp:31,
                 from /usr/local/include/mxnet-cpp/MxNetCpp.h:29,
                 from /home/stathis/Documents/Documents/Documents/Untitled.cpp:1:
/usr/local/include/dmlc/base.h:260:1: error: template with C linkage
  260 | template<typename T>
      | ^~~~~~~~
In file included from /usr/include/features.h:486,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/c++config.h:586,
                 from /usr/include/c++/11/bits/stl_algobase.h:59,
                 from /usr/include/c++/11/vector:60,
                 from /usr/local/include/mxnet-cpp/executor.hpp:29,
                 from /usr/local/include/mxnet-cpp/MxNetCpp.h:29,
                 from /home/stathis/Documents/Documents/Documents/Untitled.cpp:1:
/usr/include/x86_64-linux-gnu/sys/types.h:27:1: note: 'extern "C"' linkage started here
   27 | __BEGIN_DECLS
      | ^~~~~~~~~~~~~
In file included from /usr/local/include/dmlc/endian.h:9,
                 from /usr/include/x86_64-linux-gnu/sys/types.h:176,
                 from /usr/include/stdlib.h:395,
                 from /usr/include/c++/11/cstdlib:75,
                 from /usr/include/c++/11/ext/string_conversions.h:41,
                 from /usr/include/c++/11/bits/basic_string.h:6608,
                 from /usr/include/c++/11/string:55,
                 from /usr/local/include/mxnet-cpp/executor.hpp:31,
                 from /usr/local/include/mxnet-cpp/MxNetCpp.h:29,
                 from /home/stathis/Documents/Documents/Documents/Untitled.cpp:1:
/usr/local/include/dmlc/base.h:282:20: error: conflicting declaration of C function 'const char* dmlc::BeginPtr(const string&)'
  282 | inline const char* BeginPtr(const std::string &str) {
      |                    ^~~~~~~~
/usr/local/include/dmlc/base.h:273:14: note: previous declaration 'char* dmlc::BeginPtr(std::string&)'
  273 | inline char* BeginPtr(std::string &str) {  // NOLINT(*)
      |              ^~~~~~~~
make[1]: *** [Documents.mk:97: ../build-Debug/Documents/Untitled.cpp.o] Error 1
make[1]: Leaving directory '/home/stathis/Documents/Documents/Documents'
make: *** [Makefile:5: All] Error 2
==== build ended with errors (3 errors, 3 warnings) ===

Solution

  • mxnet-cpp does not depend on dmlc. It has the file base.h, dmlc has its own base.h at the same time. So you mix several base.h between independent projects. You have many errors in your include directories.

    -I/usr/include/
    -I/usr/local/include/
    -I/usr/local/include/mxnet-cpp/
    -I/usr/local/include/mshadow/
    -I/usr/local/include/dmlc/
    -I/usr/local/include/mkl/
    

    Remove all these directories. The first two are default and should not be added explicitly. Other are reachable in the default locations.