Skip to content

Link errors when copy execuTorch libs to the application folders #7465

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

Closed
jpeng2012 opened this issue Jan 1, 2025 · 11 comments
Closed

Link errors when copy execuTorch libs to the application folders #7465

jpeng2012 opened this issue Jan 1, 2025 · 11 comments

Comments

@jpeng2012
Copy link

jpeng2012 commented Jan 1, 2025

🐛 Describe the bug

Currently I am using release 0.4, I copied the header files under extension/tensor, extension/module/, runtime/core, runtime/platform, runtime/executor, libexecutorch.a, libportable_kernels.a, libportable_ops_lib.a to my application folders

My cmake file framework is like this,
set(EXECUTORCH_LIBRARY ${EXECUTORCH_LIB_PATH}/libexecutorch.a
${EXECUTORCH_LIB_PATH}/libportable_kernels.a
${EXECUTORCH_LIB_PATH}/libportable_ops_lib.a)

dd_library(mysharedLib SHARED ${SRC_LIST})

target_link_libraries(mysharedLib PRIVATE
-Wl,--no-allow-shlib-undefined
-Wl,-z,defs
-Wl,--whole-archive ${EXECUTORCH_LIBRARY} -Wl,--no-whole-archive
${OTHERLIBS}

The compilation works just fine but linker keep complaining executorch::runtime:: ....

What's wrong?

Also is it possible to build a shared library version?
It would be great if you can provide a simple exmaple cmakefile to link the only minimal libraries to external c++ project.

Versions

OS: Ubuntu 22.04.5 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version: Could not collect
CMake version: version 3.22.1
Libc version: glibc-2.35

Python version: 3.12.6

@dinusha94
Copy link

I used executorch in a simple external C++ project with the CMakeList.txt file mentioned in the following issue #7459 (comment)

@kimishpatel
Copy link
Contributor

The compilation works just fine but linker keep complaining executorch::runtime:: ....

Can you expand on the error?

@jpeng2012
Copy link
Author

@kimishpatel partial of link errors. Will try @dinusha94 's method.

2024-12-31 16:49:20 -0800 -- INFO: [docker] CMakeFiles/executorch_app.dir/src/executorch_wrapper.cpp.o: In function `EngineExecuTorch::EngineExecute()':

/optexe/workspace/simpleApp/src/executorch_wrapper.cpp:164: undefined reference to `executorch::extension::Module::execute(std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator > const&, std::__ndk1::vector<executorch::runtime::EValue, std::__ndk1::allocatorexecutorch::runtime::EValue > const&)'

2024-12-31 16:49:20 -0800 -- INFO: [docker] CMakeFiles/executorch_app.dir/src/executorch_wrapper.cpp.o: In function `std::__ndk1::__unique_ifexecutorch::extension::Module::__unique_single std::__ndk1::make_unique<executorch::extension::Module, char const*>(char const*&&)':

/opt/build-tools/AndroidNDKStandaloneToolchain/android-ndk/android-ndk-r21b/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/c++/v1/memory:3003: undefined reference to `executorch::extension::Module::Module(std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator > const&, executorch::extension::Module::LoadMode, std::__ndk1::unique_ptr<executorch::runtime::EventTracer, std::__ndk1::default_deleteexecutorch::runtime::EventTracer >)'

2024-12-31 16:49:20 -0800 -- INFO: [docker] CMakeFiles/executorch_app.dir/src/executorch_wrapper.cpp.o: In function `executorch::runtime::EValue::toTensor() const &':

/optexe/android_ndk/include/executorch/runtime/core/evalue.h:278: undefined reference to `executorch::runtime::internal::get_log_timestamp()'

2024-12-31 16:49:20 -0800 -- INFO: [docker] /optexe/android_ndk/include/executorch/runtime/core/evalue.h:278: undefined reference to `executorch::runtime::runtime_abort()'

2024-12-31 16:49:20 -0800 -- INFO: [docker] CMakeFiles/executorch_app.dir/src/executorch_wrapper.cpp.o: In function `executorch::extension::make_tensor_ptr(std::__ndk1::vector<int, std::__ndk1::allocator >, void*, std::__ndk1::vector<unsigned char, std::__ndk1::allocator >, std::__ndk1::vector<int, std::__ndk1::allocator >, executorch::runtime::etensor::ScalarType, executorch::runtime::TensorShapeDynamism, std::__ndk1::function<void (void*)>)':

/optexe/android_ndk/include/executorch/extension/tensor/tensor_ptr.h:158: undefined reference to `executorch::extension::make_tensor_impl_ptr(std::__ndk1::vector<int, std::__ndk1::allocator >, void*, std::__ndk1::vector<unsigned char, std::__ndk1::allocator >, std::__ndk1::vector<int, std::__ndk1::allocator >, executorch::runtime::etensor::ScalarType, executorch::runtime::TensorShapeDynamism, std::__ndk1::function<void (void*)>)'

2024-12-31 16:49:20 -0800 -- INFO: [docker] CMakeFiles/executorch_app.dir/src/executorch_wrapper.cpp.o: In function `executorch::runtime::internal::logf(executorch::runtime::LogLevel, unsigned long, char const*, char const*, unsigned long, char const*, ...)':

/optexe/android_ndk/include/executorch/runtime/platform/log.h:131: undefined reference to `executorch::runtime::internal::vlogf(executorch::runtime::LogLevel, unsigned long, char const*, char const*, unsigned long, char const*, std::__va_list)'

2024-12-31 16:49:20 -0800 -- INFO: [docker] CMakeFiles/executorch_app.dir/src/executorch_wrapper.cpp.o: In function `executorch::runtime::EValue::toTensorList() const':

/optexe/android_ndk/include/executorch/runtime/core/evalue.h:353: undefined reference to `executorch::runtime::internal::get_log_timestamp()'

2024-12-31 16:49:20 -0800 -- INFO: [docker] /optexe/android_ndk/include/executorch/runtime/core/evalue.h:353: undefined reference to `executorch::runtime::runtime_abort()'

2024-12-31 16:49:20 -0800 -- INFO: [docker] CMakeFiles/executorch_app.dir/src/executorch_wrapper.cpp.o: In function `executorch::runtime::EValue::toListOptionalTensor() const':

/optexe/android_ndk/include/executorch/runtime/core/evalue.h:371: undefined reference to `
2024-12-31 16:49:20 -0800 -- INFO: [docker] executorch::runtime::BoxedEvalueList<executorch::runtime::etensor::optionalexecutorch::runtime::etensor::Tensor >::get() const'

@jpeng2012
Copy link
Author

@dinusha94
I am not able to find
/usr/local/lib/libextension_module_static.a
/usr/local/lib/libextension_data_loader.a
/usr/local/lib/libextension_tensor.a
following the setup build method from the tutorial.

@dinusha94
Copy link

@jpeng2012 ,

I copied those folders from the executorch's build directory, /executorch/cmake-out/lib, also need to copy includes to /usr/local/include/ from /executorch/cmake-out/include.

to get all necessary includes I added the following code to the top level CMakeList.txt before building executorch

include new codes after

install(
  TARGETS executorch executorch_no_prim_ops
  DESTINATION lib
  INCLUDES
  DESTINATION ${_common_include_directories}
)

Code to include in CMakeList.txt

install(
  DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/runtime
  DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch
  FILES_MATCHING PATTERN "*.h"
)
install(
  DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/extension
  DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch
  FILES_MATCHING PATTERN "*.h"
)
install(
  DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/devtools
  DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch
  FILES_MATCHING PATTERN "*.h"
)


@jpeng2012
Copy link
Author

@dinusha94 thank you for your help. I realized I need to turn on some compile options in CMakeFile.txt. After that I can build successfully. I haven't tested a model yet.

@kimishpatel
Copy link
Contributor

@jpeng2012 I am gonna close this issue as original one seems to be resolved. Thanks @dinusha94 for the pointers. I dont know if gh has "thanks" badges but if there is one, i will send it your way

@copparihollmann
Copy link

copparihollmann commented Mar 6, 2025

Hi everyone!

I would like to re-open this issue because I'm experiencing a problem that I think might be related.

I’m encountering undefined reference errors when using the Module API in executorch. I built executorch with the following flags:

-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON
-DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON
-DEXECUTORCH_BUILD_XNNPACK=ON
-DEXECUTORCH_ENABLE_LOGGING=ON
-DPYTHON_EXECUTABLE=python

After building and installing, I copied the entire contents of cmake-out/lib and cmake-out/include into my repository (as local copies).

I’m using the following minimal example for testing a forward pass on a model:

#include <executorch/extension/module/module.h>
#include <executorch/extension/tensor/tensor.h>
#include <cassert>
#include <iostream>

using namespace executorch::extension;

int main() {
    // Create a Module using an exported model file
    Module module("/home/agustin_nahuel/projects/XNNPack/executorch-evaluation/models/executorch/convnext_tiny.pte");

    // Create input tensor (dummy data)
    float dummy[1 * 3 * 244 * 244] = {0};
    auto tensor = from_blob(dummy, {1, 3, 244, 244});

    // Perform inference
    const auto result = module.forward(tensor);

    // Print the result
    const auto output = result->at(0).toTensor().const_data_ptr<float>();
    for (int i = 0; i < result->at(0).toTensor().numel(); ++i) {
        std::cout << output[i] << " ";
    }
    std::cout << std::endl;

    return 0;
}

CMakeLists.txt for my downstream project:

cmake_minimum_required(VERSION 3.13)
project(Benchmarking)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Use the locally copied executorch headers and libraries
set(EXECUTORCH_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
set(EXECUTORCH_LIBS "${CMAKE_CURRENT_SOURCE_DIR}/lib")

# Find LibTorch with your specific path
message(STATUS "Looking for libtorch at: /home/agustin_nahuel/projects/XNNPack/libtorch")
find_package(Torch REQUIRED PATHS "/home/agustin_nahuel/projects/XNNPack/libtorch")
message(STATUS "Found Torch libraries at: ${TORCH_LIBRARIES}")

# Main executable
set(SOURCES main.cpp)
add_executable(Benchmark ${SOURCES})

# Include directories for main executable
target_include_directories(Benchmark PRIVATE
    ${TORCH_INCLUDE_DIRS}
    ${EXECUTORCH_INCLUDE_DIR}
    ${EXECUTORCH_INCLUDE_DIR}/executorch  # To pick up executorch/extension/module/module.h, etc.
)

# Link libraries (using the shared version of the Module API)
target_link_libraries(Benchmark PRIVATE
    ${TORCH_LIBRARIES}
    ${EXECUTORCH_LIBS}/libexecutorch.a
    ${EXECUTORCH_LIBS}/libexecutorch_core.a
    ${EXECUTORCH_LIBS}/libextension_module_static.a  
    ${EXECUTORCH_LIBS}/libextension_tensor.a
    ${EXECUTORCH_LIBS}/libportable_ops_lib.a
    ${EXECUTORCH_LIBS}/libextension_data_loader.a
)

The Issue:
When building my downstream project, I get the following linker errors:

/usr/bin/ld: CMakeFiles/Benchmark.dir/main.cpp.o: in function `main':
main.cpp:(.text+0xa0): undefined reference to `executorch::extension::Module::Module(std::string const&, executorch::extension::Module::LoadMode, std::unique_ptr<executorch::runtime::EventTracer, std::default_delete<executorch::runtime::EventTracer> >)'
/usr/bin/ld: CMakeFiles/Benchmark.dir/main.cpp.o: in function `executorch::extension::Module::forward(std::vector<executorch::runtime::EValue, std::allocator<executorch::runtime::EValue> > const&)':
main.cpp:(.text._ZN10executorch9extension6Module7forwardERKSt6vectorINS_7runtime6EValueESaIS4_EE[_ZN10executorch9extension6Module7forwardERKSt6vectorINS_7runtime6EValueESaIS4_EE]+0x62): undefined reference to `executorch::extension::Module::execute(std::string const&, std::vector<executorch::runtime::EValue, std::allocator<executorch::runtime::EValue> > const&)'

I have verified using nm -gDC that the installed libextension_module.so (and even the one I’m referencing) contains the required symbols. For example, running:

nm -gDC /home/agustin_nahuel/projects/XNNPack/executorch/cmake-out/lib/libextension_module_static.a

I did find that the symbols are present:

000000000000c7f0 T executorch::extension::Module::Module(std::unique_ptr<executorch::runtime::DataLoader, std::default_delete<executorch::runtime::DataLoader> >, std::unique_ptr<executorch::runtime::MemoryAllocator, std::default_delete<executorch::runtime::MemoryAllocator> >, std::unique_ptr<executorch::runtime::MemoryAllocator, std::default_delete<executorch::runtime::MemoryAllocator> >, std::unique_ptr<executorch::runtime::EventTracer, std::default_delete<executorch::runtime::EventTracer> >)
000000000000c6a0 T executorch::extension::Module::Module(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, executorch::extension::Module::LoadMode, std::unique_ptr<executorch::runtime::EventTracer, std::default_delete<executorch::runtime::EventTracer> >)
000000000000c990 T executorch::extension::Module::Module(std::shared_ptr<executorch::runtime::Program>, std::unique_ptr<executorch::runtime::MemoryAllocator, std::default_delete<executorch::runtime::MemoryAllocator> >, std::unique_ptr<executorch::runtime::MemoryAllocator, std::default_delete<executorch::runtime::MemoryAllocator> >, std::unique_ptr<executorch::runtime::EventTracer, std::default_delete<executorch::runtime::EventTracer> >)
000000000000c7f0 T executorch::extension::Module::Module(std::unique_ptr<executorch::runtime::DataLoader, std::default_delete<executorch::runtime::DataLoader> >, std::unique_ptr<executorch::runtime::MemoryAllocator, std::default_delete<executorch::runtime::MemoryAllocator> >, std::unique_ptr<executorch::runtime::MemoryAllocator, std::default_delete<executorch::runtime::MemoryAllocator> >, std::unique_ptr<executorch::runtime::EventTracer, std::default_delete<executorch::runtime::EventTracer> >)
000000000000d980 T executorch::extension::Module::load_method(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, executorch::runtime::EventTracer*)
000000000000e980 T executorch::extension::Module::method_meta(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
000000000000cb60 T executorch::extension::Module::method_names[abi:cxx11]()
000000000000cb40 T executorch::extension::Module::load(executorch::runtime::Program::Verification)
000000000000e9e0 T executorch::extension::Module::execute(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<executorch::runtime::EValue, std::allocator<executorch::runtime::EValue> > const&)

I have also tried linking against the shared and static versions separately. However, the error persists.

Other similar issues have been reported (e.g., #7465 (here), #8196, and discussions on the PyTorch forum).

Steps I have taken (summarized):

  1. Built executorch with the Module extension enabled (EXECUTORCH_BUILD_EXTENSION_MODULE=ON) and installed headers using these commands in executorch’s CMakeLists.txt:
    install(
      DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/runtime
      DESTINATION include/executorch
      FILES_MATCHING PATTERN "*.h"
    )
    install(
      DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/extension
      DESTINATION include/executorch
      FILES_MATCHING PATTERN "*.h"
    )
    install(
      DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/devtools
      DESTINATION include/executorch
      FILES_MATCHING PATTERN "*.h"
    )
    
  2. Since I don’t have permission to install to system directories, I set -DCMAKE_INSTALL_PREFIX=cmake-out and then copied the contents of the installed cmake-out/include and cmake-out/lib into my repository.
  3. Updated my project’s CMakeLists.txt to point to these local copies.
  4. Verified with nm that the shared library contains the symbols.
  5. Tried both shared (libextension_module.so) and static (libextension_module_static.a) versions in the linking stage.

Question:
Given that the libraries appear to contain the necessary symbols and my include paths seem correct, what additional steps or changes are required to resolve these undefined references? Is there a known workaround or a specific configuration required when building executorch separately and then using the libraries/headers in a downstream project?

Any help would be greatly appreciated!!

@kimishpatel please let me know if it would be okay to re-open this issue, or if I rather create a new one.

Environment:

  • executorch version: v0.5.0-2-g1bc0699aa
  • OS: Ubuntu 22.04.5 LTS
  • GCC: 11.4.0
  • Clang: 14.0.0
  • CMake: 3.31.6
  • Python: 3.12.4

@larryliu0820
Copy link
Contributor

@copparihollmann

After building and installing, I copied the entire contents of cmake-out/lib and cmake-out/include into my repository (as local copies).

I'm curious why you would want to do this instead of simply do

add_subdirectory(executorch)

@larryliu0820
Copy link
Contributor

@copparihollmann if you have an open repo for your code and some repro steps, I'm happy to give it a try

@jpeng2012
Copy link
Author

Hi everyone!

I would like to re-open this issue because I'm experiencing a problem that I think might be related.

I’m encountering undefined reference errors when using the Module API in executorch. I built executorch with the following flags:

-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON
-DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON
-DEXECUTORCH_BUILD_XNNPACK=ON
-DEXECUTORCH_ENABLE_LOGGING=ON
-DPYTHON_EXECUTABLE=python

After building and installing, I copied the entire contents of cmake-out/lib and cmake-out/include into my repository (as local copies).

I’m using the following minimal example for testing a forward pass on a model:

#include <executorch/extension/module/module.h>
#include <executorch/extension/tensor/tensor.h>
#include <cassert>
#include <iostream>

using namespace executorch::extension;

int main() {
    // Create a Module using an exported model file
    Module module("/home/agustin_nahuel/projects/XNNPack/executorch-evaluation/models/executorch/convnext_tiny.pte");

    // Create input tensor (dummy data)
    float dummy[1 * 3 * 244 * 244] = {0};
    auto tensor = from_blob(dummy, {1, 3, 244, 244});

    // Perform inference
    const auto result = module.forward(tensor);

    // Print the result
    const auto output = result->at(0).toTensor().const_data_ptr<float>();
    for (int i = 0; i < result->at(0).toTensor().numel(); ++i) {
        std::cout << output[i] << " ";
    }
    std::cout << std::endl;

    return 0;
}

CMakeLists.txt for my downstream project:

cmake_minimum_required(VERSION 3.13)
project(Benchmarking)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Use the locally copied executorch headers and libraries
set(EXECUTORCH_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
set(EXECUTORCH_LIBS "${CMAKE_CURRENT_SOURCE_DIR}/lib")

# Find LibTorch with your specific path
message(STATUS "Looking for libtorch at: /home/agustin_nahuel/projects/XNNPack/libtorch")
find_package(Torch REQUIRED PATHS "/home/agustin_nahuel/projects/XNNPack/libtorch")
message(STATUS "Found Torch libraries at: ${TORCH_LIBRARIES}")

# Main executable
set(SOURCES main.cpp)
add_executable(Benchmark ${SOURCES})

# Include directories for main executable
target_include_directories(Benchmark PRIVATE
    ${TORCH_INCLUDE_DIRS}
    ${EXECUTORCH_INCLUDE_DIR}
    ${EXECUTORCH_INCLUDE_DIR}/executorch  # To pick up executorch/extension/module/module.h, etc.
)

# Link libraries (using the shared version of the Module API)
target_link_libraries(Benchmark PRIVATE
    ${TORCH_LIBRARIES}
    ${EXECUTORCH_LIBS}/libexecutorch.a
    ${EXECUTORCH_LIBS}/libexecutorch_core.a
    ${EXECUTORCH_LIBS}/libextension_module_static.a  
    ${EXECUTORCH_LIBS}/libextension_tensor.a
    ${EXECUTORCH_LIBS}/libportable_ops_lib.a
    ${EXECUTORCH_LIBS}/libextension_data_loader.a
)

The Issue: When building my downstream project, I get the following linker errors:

/usr/bin/ld: CMakeFiles/Benchmark.dir/main.cpp.o: in function `main':
main.cpp:(.text+0xa0): undefined reference to `executorch::extension::Module::Module(std::string const&, executorch::extension::Module::LoadMode, std::unique_ptr<executorch::runtime::EventTracer, std::default_delete<executorch::runtime::EventTracer> >)'
/usr/bin/ld: CMakeFiles/Benchmark.dir/main.cpp.o: in function `executorch::extension::Module::forward(std::vector<executorch::runtime::EValue, std::allocator<executorch::runtime::EValue> > const&)':
main.cpp:(.text._ZN10executorch9extension6Module7forwardERKSt6vectorINS_7runtime6EValueESaIS4_EE[_ZN10executorch9extension6Module7forwardERKSt6vectorINS_7runtime6EValueESaIS4_EE]+0x62): undefined reference to `executorch::extension::Module::execute(std::string const&, std::vector<executorch::runtime::EValue, std::allocator<executorch::runtime::EValue> > const&)'

I have verified using nm -gDC that the installed libextension_module.so (and even the one I’m referencing) contains the required symbols. For example, running:

nm -gDC /home/agustin_nahuel/projects/XNNPack/executorch/cmake-out/lib/libextension_module_static.a

I did find that the symbols are present:

000000000000c7f0 T executorch::extension::Module::Module(std::unique_ptr<executorch::runtime::DataLoader, std::default_delete<executorch::runtime::DataLoader> >, std::unique_ptr<executorch::runtime::MemoryAllocator, std::default_delete<executorch::runtime::MemoryAllocator> >, std::unique_ptr<executorch::runtime::MemoryAllocator, std::default_delete<executorch::runtime::MemoryAllocator> >, std::unique_ptr<executorch::runtime::EventTracer, std::default_delete<executorch::runtime::EventTracer> >)
000000000000c6a0 T executorch::extension::Module::Module(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, executorch::extension::Module::LoadMode, std::unique_ptr<executorch::runtime::EventTracer, std::default_delete<executorch::runtime::EventTracer> >)
000000000000c990 T executorch::extension::Module::Module(std::shared_ptr<executorch::runtime::Program>, std::unique_ptr<executorch::runtime::MemoryAllocator, std::default_delete<executorch::runtime::MemoryAllocator> >, std::unique_ptr<executorch::runtime::MemoryAllocator, std::default_delete<executorch::runtime::MemoryAllocator> >, std::unique_ptr<executorch::runtime::EventTracer, std::default_delete<executorch::runtime::EventTracer> >)
000000000000c7f0 T executorch::extension::Module::Module(std::unique_ptr<executorch::runtime::DataLoader, std::default_delete<executorch::runtime::DataLoader> >, std::unique_ptr<executorch::runtime::MemoryAllocator, std::default_delete<executorch::runtime::MemoryAllocator> >, std::unique_ptr<executorch::runtime::MemoryAllocator, std::default_delete<executorch::runtime::MemoryAllocator> >, std::unique_ptr<executorch::runtime::EventTracer, std::default_delete<executorch::runtime::EventTracer> >)
000000000000d980 T executorch::extension::Module::load_method(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, executorch::runtime::EventTracer*)
000000000000e980 T executorch::extension::Module::method_meta(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
000000000000cb60 T executorch::extension::Module::method_names[abi:cxx11]()
000000000000cb40 T executorch::extension::Module::load(executorch::runtime::Program::Verification)
000000000000e9e0 T executorch::extension::Module::execute(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<executorch::runtime::EValue, std::allocator<executorch::runtime::EValue> > const&)

I have also tried linking against the shared and static versions separately. However, the error persists.

Other similar issues have been reported (e.g., #7465 (here), #8196, and discussions on the PyTorch forum).

Steps I have taken (summarized):

  1. Built executorch with the Module extension enabled (EXECUTORCH_BUILD_EXTENSION_MODULE=ON) and installed headers using these commands in executorch’s CMakeLists.txt:
    install(
      DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/runtime
      DESTINATION include/executorch
      FILES_MATCHING PATTERN "*.h"
    )
    install(
      DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/extension
      DESTINATION include/executorch
      FILES_MATCHING PATTERN "*.h"
    )
    install(
      DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/devtools
      DESTINATION include/executorch
      FILES_MATCHING PATTERN "*.h"
    )
    
  2. Since I don’t have permission to install to system directories, I set -DCMAKE_INSTALL_PREFIX=cmake-out and then copied the contents of the installed cmake-out/include and cmake-out/lib into my repository.
  3. Updated my project’s CMakeLists.txt to point to these local copies.
  4. Verified with nm that the shared library contains the symbols.
  5. Tried both shared (libextension_module.so) and static (libextension_module_static.a) versions in the linking stage.

Question: Given that the libraries appear to contain the necessary symbols and my include paths seem correct, what additional steps or changes are required to resolve these undefined references? Is there a known workaround or a specific configuration required when building executorch separately and then using the libraries/headers in a downstream project?

Any help would be greatly appreciated!!

@kimishpatel please let me know if it would be okay to re-open this issue, or if I rather create a new one.

Environment:

  • executorch version: v0.5.0-2-g1bc0699aa
  • OS: Ubuntu 22.04.5 LTS
  • GCC: 11.4.0
  • Clang: 14.0.0
  • CMake: 3.31.6
  • Python: 3.12.4

Try to use -Wl,--whole-archive libexecutorch.a -Wl,--no-whole-archive to link most if not all your executorch libs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants