Linker error: C++ compilation with pre-compiled Linux binaries

Home Forums Forum Linker error: C++ compilation with pre-compiled Linux binaries

This topic contains 5 replies, has 2 voices, and was last updated by  KarasevLS 8 years, 11 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1935

    Hal Clark

    Hi Rich,

    I’m trying to compile a test C++11 file using ellcc-x86_64-linux-2014-Feb-25-15-13-13.tgz and have encountered a few problems. The file is

    
    #include <functional>
    #include <iostream>
    #include <string>
    int main(int argc, char **argv){
        std::string test;
        test += "Hello World!";
        std::cout << test << std::endl;
        auto lambda = [&](const std::string &in) -> void {
            std::cout << "Text was: " << in << std::endl;
            return;
        };
        lambda("extra text.");
        return 0;
    }
    

    I’ve unpacked ellcc into /tmp/ and run

    
    ./bin/ecc++ --std=c++11 -stdlib=libc++ -nobuiltininc -nostdinc -nostdinc++ -D__ELLCC__ -I./libecc/include/linux/ -I./libecc/include/c++/ -I./libecc/include/ -I./libecc/include/x86_64/linux/ -L./libecc/lib/x86_64/linux/ Test.cc -o test -v -Wl,-v
    

    which spits out

    
    guy@machine:/tmp# ./bin/ecc++ --std=c++11 -stdlib=libc++ -nobuiltininc -nostdinc -nostdinc++ -D__ELLCC__ -I./libecc/include/linux/ -I./libecc/include/c++/ -I./libecc/include/ -I./libecc/include/x86_64/linux/ -L./libecc/lib/x86_64/linux/ Test.cc -o test -v -Wl,-v
    clang version 3.5 (trunk)
    Target: x86_64-unknown-linux-gnu
    Thread model: posix
    Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.4
    Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.4.4
    Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.4.5
    Found candidate GCC installation: /usr/lib64/gcc/x86_64-linux-gnu/4.4
    Found candidate GCC installation: /usr/lib64/gcc/x86_64-linux-gnu/4.4.4
    Found candidate GCC installation: /usr/lib64/gcc/x86_64-linux-gnu/4.4.5
    Selected GCC installation: /usr/lib64/gcc/x86_64-linux-gnu/4.4
    ecc: warning: argument unused during compilation: '-nobuiltininc'
     "/tmp/bin/ecc" -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -main-file-name Test.cc -mrelocation-model static -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-linker-version 2.23.2 -v -nostdsysteminc -nobuiltininc -resource-dir /tmp/bin/../libecc -D __ELLCC__ -I ./libecc/include/linux/ -I ./libecc/include/c++/ -I ./libecc/include/ -I ./libecc/include/x86_64/linux/ --std=c++11 -fdeprecated-macro -fdebug-compilation-dir /tmp -ferror-limit 19 -fmessage-length 226 -mstackrealign -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -vectorize-slp -o /tmp/Test-d19800.o -x c++ Test.cc
    clang -cc1 version 3.5 based upon LLVM 3.5svn default target x86_64-unknown-linux-gnu
    #include "..." search starts here:
    #include <...> search starts here:
     ./libecc/include/linux
     ./libecc/include/c++
     ./libecc/include
     ./libecc/include/x86_64/linux
    End of search list.
     "/usr/bin/ld" --hash-style=both --build-id --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o test /usr/lib64/gcc/x86_64-linux-gnu/4.4/../../../../lib64/crt1.o /usr/lib64/gcc/x86_64-linux-gnu/4.4/../../../../lib64/crti.o /usr/lib64/gcc/x86_64-linux-gnu/4.4/crtbegin.o -L./libecc/lib/x86_64/linux/ -L/usr/lib64/gcc/x86_64-linux-gnu/4.4 -L/usr/lib64/gcc/x86_64-linux-gnu/4.4/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib64/gcc/x86_64-linux-gnu/4.4/../../.. -L/lib -L/usr/lib /tmp/Test-d19800.o -v -lc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib64/gcc/x86_64-linux-gnu/4.4/crtend.o /usr/lib64/gcc/x86_64-linux-gnu/4.4/../../../../lib64/crtn.o
    GNU ld (GNU Binutils for Debian) 2.20.1-system.20100303
    /usr/lib64/gcc/x86_64-linux-gnu/4.4/../../../../lib64/crt1.o: In function "_start":
    (.text+0x12): undefined reference to "__libc_csu_fini"
    /usr/lib64/gcc/x86_64-linux-gnu/4.4/../../../../lib64/crt1.o: In function "_start":
    (.text+0x19): undefined reference to "__libc_csu_init"
    ecc: error: linker command failed with exit code 1 (use -v to see invocation)
    

    I suspect the issue is that the system linker is being called, so I tried dumping LLVM byte code (ala ) but ecc-ld (painfully) complains with

    
    ./bin/ecc-ld: cannot find -: No such file or directory
    

    Clang supposedly cannot simply be told which linker to use.

    It is possibly relevant that I had to define __ELLCC__ to get around strtoull_l symbol not being defined. (Comments in the source lead me to believe you’re aware of that…)

    Do you have any suggestions here?

    #1936

    Hal Clark

    Whoops. The (ala ) part should read (ala this).

    #1999

    rich
    Keymaster

    Hi Hal,

    I’m not sure how to coerce clang work the way you want it to, but here’s what I did:

    [~] dev% ellcc/bin/ecc++ -target x86_64-ellcc-linux --std=c++11 test.cpp
    [~] dev% ./a.out
    Hello World!
    Text was: extra text.
    [~] dev%
    

    This tells ecc to use the correct include paths, libraries, and linker for the x86_64.

    -Rich

    #2090

    Hal Clark

    Thanks – I was hoping I had made some silly mistake.

    In case someone finds this later I’ll state what my error was. I was targeting x86_64 from an x86_64 machine. I thought I could (or should) provide include and library paths for ellcc, to swap the local system files with ellcc’s provided files (e.g., swapping ./libecc/include/c++/ for /usr/include/c++/).

    The correct approach is to explicitly pass the correct target. (Even if you’re targeting the same architecture!)

    #2107

    rich
    Keymaster

    Yes. By default ecc uses the host system’s include files and libraries, just like clang. The -target option overrides the default.

    -Rich

    #23624

    KarasevLS

    Hello world! Have a nice day!

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.