Skip to content

"libtdclient.a: error adding symbols: file format not recognized" and "ld returned 1 exit status" #1244

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
Mazuh opened this issue Oct 14, 2020 · 5 comments

Comments

@Mazuh
Copy link

Mazuh commented Oct 14, 2020

after #1241 (so there might be a few more evidences there, like the printed commands I used), I tried to run a few simple codes.

main.cpp:

#include <iostream>
#include <td/telegram/Client.h>
#include <td/telegram/td_api.h>
#include <td/telegram/td_api.hpp>

namespace td_api = td::td_api;

int main()
{
    td::Client::execute({0, td_api::make_object<td_api::setLogVerbosityLevel>(1)}); // if I remove this, everything works
    std::cout << "Hello World!" << std::endl;
    return 0;
}

(I tried to copy and paste the cpp example but the result is the same, any attempt to call the actual functions are bad, only the includes are working.)

and cmakelists.txt:

cmake_minimum_required(VERSION 3.10 FATAL_ERROR)

project("mysampleproject")

find_package(Td PATHS "../td/tdlib/" REQUIRED NO_DEFAULT_PATH)

add_executable("${PROJECT_NAME}" "src/main.cpp")

set_property(TARGET "${PROJECT_NAME}" PROPERTY CXX_STANDARD 14)

target_link_libraries("${PROJECT_NAME}" PRIVATE Td::TdStatic)
target_link_libraries("${PROJECT_NAME}" PRIVATE Td::TdJson)

then I get this error:

...
libtdclient.a: error adding symbols: file format not recognized

if I try to rebuild everything without Link Time Optimization:

...
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/mysampleproject.dir/build.make:96: mysampleproject] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/mysampleproject.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

I tried to compile using both master branch and v.1.6.0 tagged head, and erased build/ and tdlib/ before retrying.


does someone have any idea?

@levlam
Copy link
Contributor

levlam commented Oct 14, 2020

Do you have enough memory on the server for successful build?

@Mazuh
Copy link
Author

Mazuh commented Oct 14, 2020

yep, @levlam, there's more than enough, it's my own machine here, all good.

But I have more evidences!

Curiously, I switched the instructions to g++ instead of clang++ to buld tdlib and, tho memory consumption increased A LOT... my sample is now working.

here's what worked, to be specific:

export CXXFLAGS=""
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=../tdlib -DTD_ENABLE_LTO=ON ..
cmake --build . --target install

@levlam
Copy link
Contributor

levlam commented Oct 14, 2020

g++ is known to need 2-2.5 times more memory than clang to build TDLib.

And the most common way to create a broken static library is to observe a compiler crash due to memory exhaustion.

@Mazuh
Copy link
Author

Mazuh commented Oct 15, 2020

But anyway, the g++ build is fine, even using more memory.

I think there's an issue with this clang++ instructions, then. Or it's just bad luck that it doesn't work for me, haha

@levlam
Copy link
Contributor

levlam commented Nov 15, 2020

libtdclient.a: error adding symbols: file format not recognized

This is expected with LTO, because when Link-Time optimization is used .a files contain parsed source code in a compiler-specifiс format to be used by linker instead of a compiled static library functions.

collect2: error: ld returned 1 exit status

This isn't expected without LTO, but it is impossible to find the reason without debugging the issue. One way to do that is to run

make VERBOSE=1

to find exactly invoked command and then retry it manually to investigate.

I managed to build TDLib on Ubuntu 20 using clang and build instructions from https://tdlib.github.io/td/build.html on a freshly installed Ubuntu 20 without any issues.

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

2 participants