MEGAcmd icon indicating copy to clipboard operation
MEGAcmd copied to clipboard

Building without vcpkg issues

Open twaik opened this issue 1 year ago • 4 comments

Hello. I tried to build branch 2.0.0_Linux but had some problems.

  1. https://github.com/meganz/MEGAcmd/blob/e8b0858980a16e950258c64c04accf853ed485de/build/cmake/modules/megacmd_configuration.cmake#L27 you should not put , there, cmake perceives this as a part of aio_write and tries to check aio_write, function existense`.
  2. sdk/cmake/modules is being appended to CMAKE_MODULE_PATH, but sdk/cmake/modules/packages is not, so configuring fails with
CMake Error at sdk/cmake/modules/sdklib_libraries.cmake:125 (find_package):
  By not providing "FindFreeImage.cmake" in CMAKE_MODULE_PATH this project
  has asked CMake to find a package configuration file provided by
  "FreeImage", but CMake did not find one.

  Could not find a package configuration file provided by "FreeImage" with
  any of the following names:

    FreeImageConfig.cmake
    freeimage-config.cmake

  Add the installation prefix of "FreeImage" to CMAKE_PREFIX_PATH or set
  "FreeImage_DIR" to a directory containing one of the above files.  If
  "FreeImage" provides a separate development package or SDK, be sure it has
  been installed.
Call Stack (most recent call first):
  sdk/cmake/modules/sdklib_target.cmake:358 (load_sdklib_libraries)
  sdk/CMakeLists.txt:153 (include)

But it is can easily fixed with

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -25,6 +25,7 @@
 ## Modules location
 list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/build/cmake/modules) # Modules from MEGAcmd
 list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/sdk/cmake/modules) # Modules from MEGAsdk
+#list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/sdk/cmake/modules/packages)
 
 set(VCPKG_ROOT "${CMAKE_CURRENT_LIST_DIR}/../vcpkg" CACHE PATH "If set, it will build and use the VCPKG packages defined in the manifest file")
  1. Crypto++ pkg-config module is actually called libcryptopp.
--- a/sdk/cmake/modules/sdklib_libraries.cmake
+++ b/sdk/cmake/modules/sdklib_libraries.cmake
@@ -95,7 +95,7 @@
         find_package(PkgConfig REQUIRED) # For libraries loaded using pkg-config
 
-        pkg_check_modules(cryptopp REQUIRED IMPORTED_TARGET libcrypto++)
+        pkg_check_modules(cryptopp REQUIRED IMPORTED_TARGET libcryptopp)
         target_link_libraries(SDKlib PUBLIC PkgConfig::cryptopp) # TODO: Private for SDK core
 
         pkg_check_modules(sodium REQUIRED IMPORTED_TARGET libsodium)
  1. For some reason mega-cmd-server is not being linked to libpcrecpp and libz so I have to add -lpcrecpp -lz to LDFLAGS.
log
: && /home/twaik/.termux-build/_cache/android-r27c-api-24-v1/bin/clang++ --target=aarch64-none-linux-android --gcc-toolchain=/home/twaik/.termux-build/_cache/android-r27c-api-24-v1 --sysroot=/home/twaik/.termux-build/_cache/android-r27c-api-24-v1/sysroot -fstack-protector-strong -Oz --target=aarch64-linux-android24  -isystem/data/data/com.termux/files/usr/include/c++/v1 -isystem/data/data/com.termux/files/usr/include -DCODEC_CAP_TRUNCATED=0 -O3 -DNDEBUG -Wl,--gc-sections -L/data/data/com.termux/files/usr/lib -Wl,-rpath=/data/data/com.termux/files/usr/lib -Wl,--enable-new-dtags -Wl,--as-needed -Wl,-z,relro,-z,now -landroid-glob /home/twaik/.termux-build/_cache/android-r27c-api-24-v1/lib/clang/18/lib/linux/libclang_rt.builtins-aarch64-android.a --target=aarch64-linux-android24    -fPIE -pie CMakeFiles/mega-cmd-server.dir/src/megacmd_server_main.cpp.o CMakeFiles/mega-cmd-server.dir/src/megacmd.cpp.o CMakeFiles/mega-cmd-server.dir/src/megacmdexecuter.cpp.o CMakeFiles/mega-cmd-server.dir/src/megacmd_events.cpp.o CMakeFiles/mega-cmd-server.dir/src/megacmdtransfermanager.cpp.o CMakeFiles/mega-cmd-server.dir/src/megacmdlogger.cpp.o CMakeFiles/mega-cmd-server.dir/src/megacmdsandbox.cpp.o CMakeFiles/mega-cmd-server.dir/src/megacmdutils.cpp.o CMakeFiles/mega-cmd-server.dir/src/comunicationsmanager.cpp.o CMakeFiles/mega-cmd-server.dir/src/comunicationsmanagerfilesockets.cpp.o CMakeFiles/mega-cmd-server.dir/src/comunicationsmanagernamedpipes.cpp.o CMakeFiles/mega-cmd-server.dir/src/configurationmanager.cpp.o CMakeFiles/mega-cmd-server.dir/src/listeners.cpp.o CMakeFiles/mega-cmd-server.dir/src/sync_command.cpp.o CMakeFiles/mega-cmd-server.dir/src/sync_issues.cpp.o CMakeFiles/mega-cmd-server.dir/src/sync_ignore.cpp.o CMakeFiles/mega-cmd-server.dir/src/megacmd_rotating_logger.cpp.o CMakeFiles/mega-cmd-server.dir/src/megacmdcommonutils.cpp.o CMakeFiles/mega-cmd-server.dir/src/megacmd_utf8.cpp.o -o mega-cmd-server  libLMegacmdServer.a  sdk/libSDKlib.a  -latomic  /data/data/com.termux/files/usr/lib/libcryptopp.so  /data/data/com.termux/files/usr/lib/libsodium.so  -lsqlite3  /data/data/com.termux/files/usr/lib/libcurl.so  /data/data/com.termux/files/usr/lib/libicuuc.so  -ldl  /data/data/com.termux/files/usr/lib/libicudata.so  /data/data/com.termux/files/usr/lib/libssl.so  /data/data/com.termux/files/usr/lib/libcrypto.so  /data/data/com.termux/files/usr/lib/libfreeimage.so  /data/data/com.termux/files/usr/lib/libavformat.so  /data/data/com.termux/files/usr/lib/libavutil.so  /data/data/com.termux/files/usr/lib/libavcodec.so  /data/data/com.termux/files/usr/lib/libswscale.so  /data/data/com.termux/files/usr/lib/libswresample.so  /data/data/com.termux/files/usr/lib/libuv.so  /data/data/com.termux/files/usr/lib/libcares.so  /data/data/com.termux/files/usr/lib/libreadline.so  libLMEGAcmdCommonUtils.a  /data/data/com.termux/files/usr/lib/libpcre.so && :
ld.lld: error: undefined symbol: pcrecpp::RE::QuoteMeta(pcrecpp::StringPiece const&)
>>> referenced by megacmdutils.cpp
>>>               CMakeFiles/mega-cmd-server.dir/src/megacmdutils.cpp.o:(megacmd::isRegExp(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>))
>>> referenced by megacmdutils.cpp
>>>               CMakeFiles/mega-cmd-server.dir/src/megacmdutils.cpp.o:(megacmd::unquote(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>))

ld.lld: error: undefined symbol: pcrecpp::RE::Init(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const&, pcrecpp::RE_Options const*)
>>> referenced by megacmdutils.cpp
>>>               CMakeFiles/mega-cmd-server.dir/src/megacmdutils.cpp.o:(megacmd::patternMatches(char const*, char const*, bool))
>>> referenced by megacmdutils.cpp
>>>               CMakeFiles/mega-cmd-server.dir/src/megacmdutils.cpp.o:(megacmd::patternMatches(char const*, char const*, bool))
>>> referenced by megacmdutils.cpp
>>>               CMakeFiles/mega-cmd-server.dir/src/megacmdutils.cpp.o:(pcrecpp::RE::RE(char const*))

ld.lld: error: undefined symbol: pcrecpp::RE::Cleanup()
>>> referenced by megacmdutils.cpp
>>>               CMakeFiles/mega-cmd-server.dir/src/megacmdutils.cpp.o:(megacmd::patternMatches(char const*, char const*, bool))

ld.lld: error: undefined symbol: pcrecpp::RE::~RE()
>>> referenced by megacmdutils.cpp
>>>               CMakeFiles/mega-cmd-server.dir/src/megacmdutils.cpp.o:(megacmd::patternMatches(char const*, char const*, bool))
>>> referenced by megacmdutils.cpp
>>>               CMakeFiles/mega-cmd-server.dir/src/megacmdutils.cpp.o:(megacmd::patternMatches(char const*, char const*, bool))
>>> referenced by megacmdutils.cpp
>>>               CMakeFiles/mega-cmd-server.dir/src/megacmdutils.cpp.o:(megacmd::patternMatches(char const*, char const*, bool))
>>> referenced 1 more times

ld.lld: error: undefined symbol: pcrecpp::RE::no_arg
>>> referenced by megacmdutils.cpp
>>>               CMakeFiles/mega-cmd-server.dir/src/megacmdutils.cpp.o:(megacmd::patternMatches(char const*, char const*, bool))
>>> referenced by megacmdutils.cpp
>>>               CMakeFiles/mega-cmd-server.dir/src/megacmdutils.cpp.o:(megacmd::patternMatches(char const*, char const*, bool))

ld.lld: error: undefined symbol: pcrecpp::RE::FullMatch(pcrecpp::StringPiece const&, pcrecpp::Arg const&, pcrecpp::Arg const&, pcrecpp::Arg const&, pcrecpp::Arg const&, pcrecpp::Arg const&, pcrecpp::Arg const&, pcrecpp::Arg const&, pcrecpp::Arg const&, pcrecpp::Arg const&, pcrecpp::Arg const&, pcrecpp::Arg const&, pcrecpp::Arg const&, pcrecpp::Arg const&, pcrecpp::Arg const&, pcrecpp::Arg const&, pcrecpp::Arg const&) const
>>> referenced by megacmdutils.cpp
>>>               CMakeFiles/mega-cmd-server.dir/src/megacmdutils.cpp.o:(megacmd::patternMatches(char const*, char const*, bool))

ld.lld: error: undefined symbol: gzopen
>>> referenced by megacmd_rotating_logger.cpp
>>>               CMakeFiles/mega-cmd-server.dir/src/megacmd_rotating_logger.cpp.o:(megacmd::GzipCompressionEngine::gzipFile(std::__ndk1::__fs::filesystem::path const&, std::__ndk1::__fs::filesystem::path const&))

ld.lld: error: undefined symbol: gzputs
>>> referenced by megacmd_rotating_logger.cpp
>>>               CMakeFiles/mega-cmd-server.dir/src/megacmd_rotating_logger.cpp.o:(megacmd::GzipCompressionEngine::gzipFile(std::__ndk1::__fs::filesystem::path const&, std::__ndk1::__fs::filesystem::path const&))

ld.lld: error: undefined symbol: gzclose
>>> referenced by megacmd_rotating_logger.cpp
>>>               CMakeFiles/mega-cmd-server.dir/src/megacmd_rotating_logger.cpp.o:(megacmd::GzipCompressionEngine::gzipFile(std::__ndk1::__fs::filesystem::path const&, std::__ndk1::__fs::filesystem::path const&))
>>> referenced by megacmd_rotating_logger.cpp
>>>               CMakeFiles/mega-cmd-server.dir/src/megacmd_rotating_logger.cpp.o:(std::__ndk1::unique_ptr<gzFile_s, megacmd::GzipCompressionEngine::gzipFile(std::__ndk1::__fs::filesystem::path const&, std::__ndk1::__fs::filesystem::path const&)::$_0>::~unique_ptr[abi:ne180000]())
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

twaik avatar Mar 12 '25 07:03 twaik

Hi @twaik !

We'll take into account your notes. Thank you very much for reporting.

Note: from the looks of it you are attempting to build MEGAcmd without vcpkg. We encourage using it for a more smooth and heterogeneous building and executing experience.

One detail: may I ask you what is your building environment? (OS version ...?)

polmr avatar Mar 12 '25 17:03 polmr

vcpkg, conan and other similar solutions for fetching and building dependencies do not work fine in cross-compile mode. Additionally in most cases we patch sources of almost all packages because our environment is not FHS compliant and uses different libc (bionic). Pretty much non-standard situation.

One detail: may I ask you what is your building environment? (OS version ...?)

Builder (host) is debian-based docker image, compiler is Android NDK. Target environment is termux.

twaik avatar Mar 12 '25 17:03 twaik

Thanks @twaik, I'm having the same issue and your solution works for me!

We encourage using it for a more smooth and heterogeneous building and executing experience.

I'm afraid that it fetches and builds too many third party libraries (takes a lot of time & resources), and the security status of them is unknown (to us).

lilydjwg avatar Mar 20 '25 11:03 lilydjwg

Your doings work fine to me. I think your changes do really benefit people.

Question, where did you added lz and lpcrecpp to fix point 4? I don't know where are the LDFLAGS after (or before) cmake.

waltercool avatar Sep 15 '25 15:09 waltercool