Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined symbol: RegisterCustomOps #23035

Open
MyraYu2022 opened this issue Dec 6, 2024 · 1 comment
Open

undefined symbol: RegisterCustomOps #23035

MyraYu2022 opened this issue Dec 6, 2024 · 1 comment
Labels
build build issues; typically submitted using template stale issues that have not been addressed in a while; categorized by a bot

Comments

@MyraYu2022
Copy link

Describe the issue

I wrote a custom op library referring to https://github.com/microsoft/onnxruntime/tree/rel-1.16.0/onnxruntime/test/testdata/custom_op_library,
my custom_op_library.h file is like this:

#pragma once
#include <onnxruntime_c_api.h>

#ifdef _cplusplus
extern "C" {
#endif

ORT_EXPORT OrtStatus* ORT_API_CALL RegisterCustomOps(OrtSessionOptions* options, const OrtApiBase* api);

#ifdef _cplusplus
}
#endif

my custom_op_library.cc file is like this:

static const char* cust_lib = "riscv_test";
OrtStatus* ORT_API_CALL RegisterCustomOps(OrtSessionOptions* options, const OrtApiBase* api) {
   Ort::Global<void>::api_ = api->GetApi(ORT_API_VERSION);
   Ort::CustomOpDomain domain{cust_lib};

   std::unique_ptr<Ort::Custom::OrtLiteCustomOp> custom{Ort::Custom::CreateLiteCustomOp("Custom", "CPUExecutionProvider", 
        CustomKernel)};
   domain.Add(custom.get());

   Ort::UnownedSessionOptions session_options(options);
   session_options.Add(domain);
   AddOrtCustomOpDomainToContainer(std::move(domain));
   return nullptr;
}

my custom_op_library.lds file is like this:

VERS_1.0.0 {
  global:
    RegisterCustomOps;
  local:
       *;
};

my CMakeLists.txt is like this:

cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
project(custom_op CXX)

set(CMAKE_CXX_STANDARD 17)
set(ONNXRUNTIME_CUSTOM_OP_LIB_LINK_FLAG "-Xlinker --version-script=${TEST_SRC_DIR}/testdata/custom_op_library/custom_op_library.lds -Xlinker --no-undefined -Xlinker --gc-sections -z noexecstack")
set_property(TARGET custom_op_library APPEND_STRING PROPERTY LINK_FLAGS ${ONNXRUNTIME_CUSTOM_OP_LIB_LINK_FLAG})

set(custom_op_src_patterns
    "${TEST_SRC_DIR}/testdata/custom_op_library.h"
    "${TEST_SRC_DIR}/testdata/custom_op_library.cc"
  )
file(GLOB custom_op_src ${custom_op_src_patterns})

option(ONNXRUNTIME_ROOTDIR "onnxruntime root dir")

add_library(custom_op SHARED ${custom_op_src})
target_include_directories(custom_op PRIVATE "${ONNXRUNTIME_ROOTDIR}/include"
                                    "${ONNXRUNTIME_ROOTDIR}/include/onnxruntime"
                                    "${ONNXRUNTIME_ROOTDIR}/include/onnxruntime/core/session")

And I build the .so and use the python APIhttps://onnxruntime.ai/docs/api/python/api_summary.html#onnxruntime.SessionOptions.register_custom_ops_library

My code is like this:

options = ort.SessionOptions()
options.register_custom_ops_library("myLib.so")
session = ort.InferenceSession(
       "myModel.onnx",
       sess_options=options,
       providers=['CPUExecutionProvider']
)

And I got error:
onnxruntime.capi.onnxruntime_pybind11_state.Fail: [ONNXRuntimeError] : 1 : FAIL : Failed to get symbol RegisterCustomOps with error: /myLib.so: undefined symbol: RegisterCustomOps

I am wondering to know how can I resolve this problem.
Thanks.

Urgency

No response

Target platform

pytorch

Build script

Wrote above.

Error / output

onnxruntime.capi.onnxruntime_pybind11_state.Fail: [ONNXRuntimeError] : 1 : FAIL : Failed to get symbol RegisterCustomOps with error: /myLib.so: undefined symbol: RegisterCustomOps

Visual Studio Version

No response

GCC / Compiler Version

No response

@MyraYu2022 MyraYu2022 added the build build issues; typically submitted using template label Dec 6, 2024
Copy link
Contributor

github-actions bot commented Jan 5, 2025

This issue has been automatically marked as stale due to inactivity and will be closed in 30 days if no further activity occurs. If further support is needed, please provide an update and/or more details.

@github-actions github-actions bot added the stale issues that have not been addressed in a while; categorized by a bot label Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build build issues; typically submitted using template stale issues that have not been addressed in a while; categorized by a bot
Projects
None yet
Development

No branches or pull requests

1 participant