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

[Build] GCC Linker can't find re2 #20728

Closed
MustafaYounes1 opened this issue May 19, 2024 · 3 comments
Closed

[Build] GCC Linker can't find re2 #20728

MustafaYounes1 opened this issue May 19, 2024 · 3 comments
Labels
build build issues; typically submitted using template platform:windows issues related to the Windows platform

Comments

@MustafaYounes1
Copy link

MustafaYounes1 commented May 19, 2024

Describe the issue

I'm working on a cross-platform project, where I have to build ORT 1.15.1 from source on both Windows x64 and Linux AMD64.

ORT build process went smoothly on both platforms without any issues, however, I had an issue on Ubuntu 22.04 when tried to build a benchmark executable that was meant to test the ORT C++ API:

  • On windows x64 the executable ran successfully.
  • On Ubuntu 22.04 (GCC 11.4) the linker raised the following error:
[100%] Linking CXX executable ../../../onnxbenchmark
/usr/bin/ld: warning: libre2.so.9, needed by /home/mustafa/tmp/install/lib/libonnxruntime.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: /home/mustafa/tmp/install/lib/libonnxruntime.so: undefined reference to `re2::RE2::RE2(re2::StringPiece const&, re2::RE2::Options const&)'
/usr/bin/ld: /home/mustafa/tmp/install/lib/libonnxruntime.so: undefined reference to `re2::RE2::~RE2()'
/usr/bin/ld: /home/mustafa/tmp/install/lib/libonnxruntime.so: undefined reference to `re2::RE2::Match(re2::StringPiece const&, unsigned long, unsigned long, re2::RE2::Anchor, re2::StringPiece*, int) const'
collect2: error: ld returned 1 exit status
make[2]: *** [apps/tools/onnxbenchmark/CMakeFiles/onnxbenchmark.dir/build.make:151: onnxbenchmark] Error 1
make[1]: *** [CMakeFiles/Makefile2:2920: apps/tools/onnxbenchmark/CMakeFiles/onnxbenchmark.dir/all] Error 2
make: *** [Makefile:146: all] Error 2

When I checked the build tree of ORT on Windows, src/built-artifacts of re2 were in BUILD_DIR/onnxruntime/build/_deps, however, in the build tree on Ubuntu none of them was there.

Moreover, when I checked the ORT build log on Ubuntu, it turned out that re2 is not populated like the other deps even though it's present in onnxruntime-src/cmake/deps.txt:
load_ort_deps_ubuntu_2204.txt

Urgency

No response

Target platform

Linux AMD64

Build script

    set(ortargs -Donnxruntime_BUILD_UNIT_TESTS:BOOL=OFF
                -Donnxruntime_BUILD_SHARED_LIB=ON
                -Donnxruntime_DISABLE_RTTI:BOOL=OFF
                -Donnxruntime_BUILD_MS_EXPERIMENTAL_OPS:BOOL=OFF
                -Donnxruntime_ENABLE_CPU_FP16_OPS:BOOL=OFF 
                -DFETCHCONTENT_QUIET:BOOL=OFF
                -Dgtest_force_shared_crt=ON
                -Donnxruntime_PYBIND_EXPORT_OPSCHEMA:BOOL=OFF
                -DPython_EXECUTABLE=${Python_EXECUTABLE} 
                -DPYTHON_EXECUTABLE=${Python_EXECUTABLE})
                
    ExternalProject_Add(onnxruntime
      URL "${URLBASE}/onnxruntime-1.15.1.zip"
      PREFIX ${CMAKE_CURRENT_BINARY_DIR}/onnxruntime
      SOURCE_DIR ${SRCBASE}/onnxruntime
      STAMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/onnxruntime/stamp
      BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/onnxruntime/build
      CONFIGURE_COMMAND ${CMAKE_COMMAND} ${SRCBASE}/onnxruntime/cmake "--compile-no-warning-as-error" ${ortargs}
      BUILD_COMMAND ${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR}/onnxruntime/build
      INSTALL_DIR ${CMAKE_INSTALL_PREFIX}
    )

Error / output

[100%] Linking CXX executable ../../../onnxbenchmark
/usr/bin/ld: warning: libre2.so.9, needed by /home/mustafa/tmp/install/lib/libonnxruntime.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: /home/mustafa/tmp/install/lib/libonnxruntime.so: undefined reference to `re2::RE2::RE2(re2::StringPiece const&, re2::RE2::Options const&)'
/usr/bin/ld: /home/mustafa/tmp/install/lib/libonnxruntime.so: undefined reference to `re2::RE2::~RE2()'
/usr/bin/ld: /home/mustafa/tmp/install/lib/libonnxruntime.so: undefined reference to `re2::RE2::Match(re2::StringPiece const&, unsigned long, unsigned long, re2::RE2::Anchor, re2::StringPiece*, int) const'
collect2: error: ld returned 1 exit status
make[2]: *** [apps/tools/onnxbenchmark/CMakeFiles/onnxbenchmark.dir/build.make:151: onnxbenchmark] Error 1
make[1]: *** [CMakeFiles/Makefile2:2920: apps/tools/onnxbenchmark/CMakeFiles/onnxbenchmark.dir/all] Error 2
make: *** [Makefile:146: all] Error 2

Visual Studio Version

VS2019

GCC / Compiler Version

11.4

@MustafaYounes1 MustafaYounes1 added the build build issues; typically submitted using template label May 19, 2024
@github-actions github-actions bot added the platform:windows issues related to the Windows platform label May 19, 2024
@MustafaYounes1
Copy link
Author

While doing some investigations, I found that: cmake/external/onnxruntime_external_deps.cmake

FetchContent_Declare(
    re2
    URL ${DEP_URL_re2}
    URL_HASH SHA1=${DEP_SHA1_re2}
    FIND_PACKAGE_ARGS NAMES re2
)

Finds a pre-installed re2 in /home/mustafa/anaconda3/lib/cmake/re2, but still wondering why pre-installed deps didn't link successfully unlike deps built from source

@MustafaYounes1
Copy link
Author

MustafaYounes1 commented May 20, 2024

Finding re2 explicitly find_package(re2 REQUIRED) and link it against my executable target_link_libraries(EXEC re2::re2) solved my issue.

But is it meant to be like that? I mean should ORT users track the build log and figure out what pre-installed 3d-party deps were used when building ORT from source and link them manually against all targets that use ORT?

@snnn
Copy link
Member

snnn commented May 20, 2024

By default ORT prefers to pick up the libs that have been preinstalled in the library. However, in many cases(especially with anaconda) the installed lib might be broken. In these cases, users need to build ONNX runtime with FETCHCONTENT_TRY_FIND_PACKAGE_MODE=NEVER

@snnn snnn closed this as completed May 20, 2024
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 platform:windows issues related to the Windows platform
Projects
None yet
Development

No branches or pull requests

2 participants