Can I compile my own relay pass in to dynamic link library?

I use the below command to compile into, and which can be success.

g++ -fPIC -shared -o -I /tvm/include/ -I tvm/3rdparty/dmlc-core/include/ -I tvm/3rdparty/dlpack/include -ltvm_runtime -L tvm/build/

but error happened when I load in the python code.

I use ctypes.cdll.LoadLibrary(“”) to load library. how can i fix this , thx.

The error report shows that the __tvm_set_device function has been registered for multiple times.

Check your to see where may introduce an extra function registration.

Below is my code, when I add into the TVM project tvm/src/relay/transform and compile together with TVM source. there is no problem。 Problem happened when I only compile into。 I can’t find problem in my code, please helo to take a look at my code. thx.

`#include <tvm/relay/analysis.h>
 #include <tvm/relay/attrs/transform.h>
 #include <tvm/relay/expr_functor.h>
 #include <tvm/relay/interpreter.h>
 #include <tvm/relay/op.h>
 #include <tvm/relay/op_attr_types.h>
 #include <tvm/relay/transform.h>
 #include <tvm/runtime/container.h>
 #include <tvm/runtime/ndarray.h>
 #include <tvm/runtime/object.h>

namespace tvm {
namespace relay {

 class ToolChain1 : public ExprVisitor {

      std::unordered_map<Expr, bool, ObjectPtrHash, ObjectPtrEqual> memo_;

      void VisitExpr_(const CallNode* call) final {
           //memo_[GetRef<Tuple>(n)] = result;
          std::cout << "call happened " << std::endl;
          std::cout << AsText(GetRef<Expr>(call), false, nullptr) << std::endl;

 Expr ToolChainParse1(const Expr& expr, const IRModule& mod) {
    return expr;

  namespace transform {
  Pass ToolChainParse1() {
          runtime::TypedPackedFunc<Function(Function, IRModule, PassContext)> pass_func =
          [=](Function f, IRModule m, PassContext pc) {
          return Downcast<Function>(ToolChainParse1(f, m));
     return CreateFunctionPass(pass_func, 2, "ToolChainParse1", {});

 TVM_REGISTER_GLOBAL   ("relay._transform.ToolChainParse1").set_body_typed(ToolChainParse1);