x265 - Undefined symbols for architecture arm64 (Apple Silicon) - apple-silicon

any ideas for this?
I try to build SDRangel on my M1 Mac but at 77% I get this error ...
-- GIT_EXECUTABLE /opt/local/bin/git
-- GIT LIVE REPO VERSION RETRIEVED
-- X265 RELEASE VERSION 3.5+68-40e37bce9
-- Detected CXX compiler using -O3 optimization level
-- Configuring done
-- Generating done
-- Build files have been written to: /opt/build/sdrangel/build/external/x265/src/x265-build
[ 27%] Performing build step for 'x265'
Consolidate compiler generated dependencies of target common
[ 45%] Built target common
Consolidate compiler generated dependencies of target encoder
[ 65%] Built target encoder
[ 76%] Built target x265-static
[ 77%] Linking CXX shared library libx265.dylib
Undefined symbols for architecture arm64:
"x265_entropyStateBits", referenced from:
_x265_costCoeffNxN_neon in pixel-util.S.o
(maybe you meant: _x265_entropyStateBits)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[5]: *** [libx265.206.dylib] Error 1
make[4]: *** [CMakeFiles/x265-shared.dir/all] Error 2
make[3]: *** [all] Error 2
make[2]: *** [external/x265/src/x265-stamp/x265-build] Error 2
make[1]: *** [external/CMakeFiles/x265.dir/all] Error 2
make: *** [all] Error 2
I am stuck. Don't know what to try to solve this issue.
I did not find anything anywhere ...

Working on it for most of 2 days, I did find this site that presents a working method of building libx265 stuff on Apple Silicon and works for me on macOS 13.0.1. https://www.osxexperts.net/ Problem is, it only builds the libraries for building it into ffmpeg, no executable binary.
When I tried to get the executable also, by removing -DENABLE_CLI=OFF from the last cmake command, the error comes back. Put it back in, everything completes without error.
Here is the full process that works for me (no executable). It builds a multilibrary that can encode 8, 10, or 12-bit video:
cd x265/source
#### 12 bit
cmake -DCMAKE_INSTALL_PREFIX:PATH=${TARGET} -DHIGH_BIT_DEPTH=ON -DMAIN12=ON -DENABLE_SHARED=NO -DEXPORT_C_API=NO -DENABLE_CLI=OFF .
make
mv libx265.a libx265_main12.a
make clean-generated
rm CMakeCache.txt
#### 10bit
cmake -DCMAKE_INSTALL_PREFIX:PATH=${TARGET} -DHIGH_BIT_DEPTH=ON -DMAIN10=ON -DENABLE_SHARED=NO -DEXPORT_C_API=NO -DENABLE_CLI=OFF .
make clean
make
mv libx265.a libx265_main10.a
make clean-generated && rm CMakeCache.txt
#### 8 bit and all together
# removed -DENABLE_CLI=OFF from last one so we get the x265 binary
cmake -DCMAKE_INSTALL_PREFIX:PATH=${TARGET} -DEXTRA_LIB="x265_main10.a;x265_main12.a" -DEXTRA_LINK_FLAGS=-L. -DLINKED_10BIT=ON -DLINKED_12BIT=ON -DENABLE_SHARED=OFF -DENABLE_CLI=OFF .
make clean
make
mv libx265.a libx265_main.a
# this is Apple's libtool
libtool -static -o libx265.a libx265_main.a libx265_main10.a libx265_main12.a
make install
When I remove the last -DENABLE_CLI=OFF, here's the error:
[100%] Linking CXX executable x265
Undefined symbols for architecture arm64:
"x265_entropyStateBits", referenced from:
_x265_costCoeffNxN_neon in libx265.a(pixel-util.S.o)
_x265_10bit_costCoeffNxN_neon in libx265_main10.a(pixel-util.S.o)
_x265_12bit_costCoeffNxN_neon in libx265_main12.a(pixel-util.S.o)
(maybe you meant: _x265_entropyStateBits)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [x265] Error 1
make[1]: *** [CMakeFiles/cli.dir/all] Error 2
make: *** [all] Error 2
JimsMBPro:source jim$
EDIT: #Peter Betz, see the issue report. Until the developers correct this error, it will compile if you edit x265/source/common/aarch64/pixel-util.S, line 2410. Add an underscore as follows. Change:
movrel x1, x265_entropyStateBits
to
movrel x1, _x265_entropyStateBits

Related

How to solve cmake linking error `lld: error: undefined symbol: llvm::ConstantInt::get(llvm::IntegerType*, unsigned long, bool) ...`

I am trying to compile from source ypsilon, but couldn't get it installed on Ubunut 22.04 LTS after multiple trial-and-errors.
I followed the official instructions linked above but process fails at cmake --build ., complaining that it couldn't find llvm. Then, I used cmake -DLLVM_DIR=/usr/lib/llvm-14/cmake .... Now, the compilation is OK, but there are many link errors even after trying out -DCMAKE_EXE_LINKER_FLAGS_RELEASE=:
$ cmake -DLLVM_DIR=/usr/lib/llvm-14/cmake -DCMAKE_EXE_LINKER_FLAGS_RELEASE=-L/usr/lib/llvm-14/lib -DCMAKE_BUILD_TYPE=Release .. && cmake --build . |& tee ~/a.txt
-- Build type: Release
-- Found LLVM 14.0.0
-- Using LLVMConfig.cmake in: /usr/lib/llvm-14/cmake
-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/tmp/ypsilon/build
[ 2%] Building CXX object CMakeFiles/ypsilon.dir/src/arith.cpp.o
...
[100%] Linking CXX executable ypsilon
ld.lld: error: undefined symbol: llvm::Type::getInt32Ty(llvm::LLVMContext&)
>>> referenced by ld-temp.o
>>> lto.tmp:(digamma_t::reg_cache_t<8>::copy(llvm::Value*))
>>> referenced by ld-temp.o
>>> lto.tmp:(digamma_t::reg_cache_t<24>::copy(llvm::Value*))
>>> referenced by ld-temp.o
>>> lto.tmp:(digamma_t::reg_cache_t<16>::copy(llvm::Value*))
>>> referenced 96 more times
ld.lld: error: undefined symbol: llvm::ConstantInt::get(llvm::IntegerType*, unsigned long, bool)
...
ld.lld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
gmake[2]: *** [CMakeFiles/ypsilon.dir/build.make:817: ypsilon] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:164: CMakeFiles/ypsilon.dir/all] Error 2
gmake: *** [Makefile:146: all] Error 2
I am not familiar with cmake or its linking flags on the command line.
Does any one know how to fix the cmake linking issue in the above commands?
The steps I tried are as follows:
sudo apt install clang lld
git clone https://github.com/fujita-y/ypsilon.git
cd ypsilon/ ; mkdir -p build ; cd build
cmake -DLLVM_DIR=/usr/lib/llvm-14/cmake -DCMAKE_EXE_LINKER_FLAGS_RELEASE=-L/usr/lib/llvm-14/lib -DCMAKE_BUILD_TYPE=Release .. && cmake --build .

Cannot find -l<nameOfTheLibrary>, even after setting LD_LIBRARY_PATH

I'm trying to build OpenMVG, and can't resolve some dependency errors. I'm in an anaconda environment and using conda installed versions of g++ and some of the libs (I do not have root priveleges).
$ cmake --build . --target install
... (lots of output from seemingly successful steps) ...
[ 77%] Built target openMVG_sample_main_features_repeatability_dataset
[ 77%] Linking CXX executable ../../Linux-x86_64-RELEASE/openMVG_sample_features_affine
/home/user/anaconda3/envs/sfm/bin/../lib/gcc/x86_64-conda_cos6-linux-gnu/7.3.0/../../../../x86_64-conda_cos6-linux-gnu/bin/ld: cannot find -ljpeg
/home/user/anaconda3/envs/sfm/bin/../lib/gcc/x86_64-conda_cos6-linux-gnu/7.3.0/../../../../x86_64-conda_cos6-linux-gnu/bin/ld: cannot find -lpng
/home/user/anaconda3/envs/sfm/bin/../lib/gcc/x86_64-conda_cos6-linux-gnu/7.3.0/../../../../x86_64-conda_cos6-linux-gnu/bin/ld: cannot find -lz
/home/user/anaconda3/envs/sfm/bin/../lib/gcc/x86_64-conda_cos6-linux-gnu/7.3.0/../../../../x86_64-conda_cos6-linux-gnu/bin/ld: cannot find -ltiff
collect2: error: ld returned 1 exit status
gmake[2]: *** [Linux-x86_64-RELEASE/openMVG_sample_features_affine] Error 1
gmake[1]: *** [openMVG_Samples/features_affine_demo/CMakeFiles/openMVG_sample_features_affine.dir/all] Error 2
gmake: *** [all] Error 2
But libjpeg, libpng etc. are all /home/user/anaconda3/envs/sfm/lib/. For example:
(sfm) [openMVG]$ find /home/user/anaconda3/envs/sfm/ -name 'libjpeg*'
/home/user/anaconda3/envs/sfm/conda-meta/libjpeg-turbo-cos6-x86_64-1.2.1-h24432d5_0.json
/home/user/anaconda3/envs/sfm/lib/libjpeg.a
/home/user/anaconda3/envs/sfm/lib/libjpeg.so
...
So I've tried both of the following:
export LD_PRELOAD=/home/user/anaconda3/envs/sfm/lib/libjpeg.so
and
export LD_LIBRARY_PATH=/home/user/anaconda3/envs/sfm/lib/:/home/user/anaconda3/lib/:/usr/lib64/:/usr/lib/
before rerunning$ cmake --build . --target install, but get the same result.
It seems to me that the compiler couldn't find some libs. So I told it exactly where to look, and even tried preoloading them, and it still can't find them. Adding the paths to LD_LIBRARY_PATH was necessary to get this far - so it does seem to have worked for other things. Just not this problem. How do I troubleshoot from here?

How to link ICU4C in cmake via pkg-config on MacOS? [duplicate]

This question already has answers here:
Cmake cannot find library using "link_directories"
(4 answers)
Closed 3 years ago.
I work on macbook with newest OS. Installed icu4c library via homebrew. But I cannot link libicuuc correctly. In case of find library, I use
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/Cellar/icu4c/64.2/lib/pkgconfig
on my ~/.bashrc, but still got link error.
This is a very simple CMakeLists.txt:
cmake_minimum_required(VERSION 3.4)
project(xeditd CXX)
find_package(PkgConfig REQUIRED)
pkg_search_module(ICU_UC icu-uc)
set(LIB_DIR
${ICU_UC_LIBRARY_DIRS}
)
set(LIB
${ICU_UC_LIBRARIES}
)
set(INC_DIR
${ICU_UC_INCLUDE_DIRS}
)
set(SRC_FILE
xeditd.cpp
)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -o2 ${ICU_UC_CXXFLAGS_OTHER}")
message(${LIB_DIR})
message(${LIB})
message(${INC_DIR})
message(${CMAKE_CXX_FLAGS})
add_executable(xeditd ${SRC_FILE})
link_directories(${LIB_DIR})
target_link_libraries(xeditd ${LIB})
target_include_directories(xeditd PUBLIC ${INC_DIR})
It generate:
/usr/local/Cellar/icu4c/64.2/lib (${LIB_DIR})
icuucicudata (${LIB})
/usr/local/Cellar/icu4c/64.2/include (${INC_DIR})
-std=c++14 -std=c++14 -o2 (${CMAKE_CXX_FLAGS})
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/rolin/workspace/github/xedit/.bin
[ 50%] Linking CXX executable xedit
ld: library not found for -licuuc
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [xedit/xedit] Error 1
make[1]: *** [xedit/CMakeFiles/xedit.dir/all] Error 2
make: *** [all] Error 2
[ 50%] Linking CXX executable xeditd
ld: library not found for -licuuc
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [xeditd/xeditd] Error 1
make[1]: *** [xeditd/CMakeFiles/xeditd.dir/all] Error 2
make: *** [all] Error 2
I don't known why libicuuc.dylib not found.
link_directories only affects targets that come AFTER it. So I move add_executable after the link_directories call.

cmake error with grpc in tensorflow

When trying to build tensorflow using cmake, I got the following error. I'm not sure whether it's an issue related to tensorflow or grpc. Any idea on what's going on?
This is on Mac OS Sierra.
steps to reproduce:
# clone tensorflow repo
# in tensorflow directory
cd tensorflow/contrib/cmake
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DPYTHON_EXECUTABLE=/usr/local/bin/python3
make tf_tutorials_example_trainer
Errors:
# ...
Scanning dependencies of target tf_tutorials_example_trainer
[100%] Building CXX object CMakeFiles/tf_tutorials_example_trainer.dir/Users/kevenwang/VirtualBoxShared/another_tf/tensorflow/cc/tutorials/example_trainer.cc.o
[100%] Linking CXX executable tf_tutorials_example_trainer
Undefined symbols for architecture x86_64:
"_ares_cancel", referenced from:
on_readable_cb(grpc_exec_ctx*, void*, grpc_error*) in libgrpc_unsecure.a(grpc_ares_ev_driver_posix.cc.o)
on_writable_cb(grpc_exec_ctx*, void*, grpc_error*) in libgrpc_unsecure.a(grpc_ares_ev_driver_posix.cc.o)
"_ares_destroy", referenced from:
grpc_ares_ev_driver_unref(grpc_ares_ev_driver*) in libgrpc_unsecure.a(grpc_ares_ev_driver_posix.cc.o)
...
_grpc_ares_ev_driver_create in libgrpc_unsecure.a(grpc_ares_ev_driver_posix.cc.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [tf_tutorials_example_trainer] Error 1
make[2]: *** [CMakeFiles/tf_tutorials_example_trainer.dir/all] Error 2
make[1]: *** [CMakeFiles/tf_tutorials_example_trainer.dir/rule] Error 2
Maybe you install the grpc lib by Homebrew.
In that case , you need to link the c-ares lib.
e.g.
TARGET_LINK_LIBRARIES(demo "/usr/local/lib/libcares.a" ...)

CMake: satisfying dependencies when building shared object file (.so) from object file (.o)

I am able to do this without CMake using a handwritten Makefile, like so:
g++ $(CXSCINC) -c -fPIC cellComplex_extern.cpp -o cellComplex_extern.o
g++ $(CXSCINC) -shared -Wl -o cellComplex_lib.so cellComplex_extern.o $(CXSCLIB) -lcxsc
This gets me shared library cellComplex_lib.so, which then gets picked up by ctypes as a dynamically linked library (lib = ctypes.cdll.LoadLibrary('./cellComplex_lib.so') for later use.
My project has moved to CMake as a build system and I am looking to emulate the functionality of my Makefile above.
So far I have discovered the add_library() command for CMakeLists.txt, but the link to the CXSC library is never made (as evidenced by horrible complaining when I run make after cmake.
How can I tell CMake to build cellComplex_lib with the third-party library CXSC?
-- non-working CMakeLists.txt --
add_library(include/python/cellComplex_extern OBJECT
include/python/cellComplex_extern.cpp ${all_headers})
add_library(include/python/cellComplex_lib SHARED
include/python/cellComplex_extern)
target_link_libraries(include/python/cellComplex_lib ${CXSC_LIB_DIR}/libcxsc.a)
Result of running cmake followed by make:
.
.
.
[ 75%] Built target include/python/cellComplex_extern
Linking CXX shared library libinclude/python/cellComplex_lib.dylib
ld: can't open output file for writing: libinclude/python/cellComplex_lib.dylib, errno=2 for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [libinclude/python/cellComplex_lib.dylib] Error 1
make[1]: *** [CMakeFiles/include/python/cellComplex_lib.dir/all] Error 2
make: *** [all] Error 2
I think you need to use target_link_libraries
target_link_libraries(include/python/cellComplex_lib ${CXSLIB})
This is what I use during Win32 development:
link_directories(${LIB_ROOT_DIR}/lib ${LIB_ROOT_DIR2}/lib/morelibs)
add_library(MyDll1 SHARED File1.cpp File2.cpp)
add_library(MyDll2 SHARED File3.cpp File4.cpp)
add_dependencies(MyDll2 Dll1)
target_link_libraries(MyDll2 Dll1 some.lib another.lib)
Here you specify that Dll2 requires Dll1 and two other external lib's.