在 2018/12/24 6:18, Maarten Verhage 写道:
> Hi Liu,
> 
> Thanks for your message. No I'm sorry, I shouldn't ask about LLVM specific 
> things. I should have more patience.
> 

If you insist on use of `-nodefaultlibs` or `-nostdlib` you may want to
see how the linker is invoked by g++ (with `-v` during linking) and copy
those options, then remove some until none can be removed any further.

> I learned that LLVM libc++abi provide equivalent facilities as libsupc++. As 
> I'm using libc++ I thought it would be best to also use libc++abi then. So I 
> build a static libc++abi and linked it with my libc++.
> 
> Now the link of of my example code goes much better. As much more of the 
> implementation is found in libraries.
> The link command for my example code:
> 
> g++ -v -nodefaultlibs -static -mconsole test.o 
> $(LIBPATH_LLVM_LIBCXX) -l:libc++.a -l:libmingw32.a -l:libgcc_s.a -l:libgcc.a 
>  -l:libmingwex.a -l:libgcc_s.a -l:libgcc.a -l:libmsvcrt.a 
> $(LIBSWIN) -Wl,-Map,test_map.txt -o test.exe > link_result.txt 2>&1
> 
> link gives one undefined reference:
> libmsvcrt.a(lib64_libmsvcrt_os_a-__p__fmode.o):__p__fmode.c:(.rdata$.refptr.__imp__fmode[.refptr.__imp__fmode]+0x0):
>  
> undefined reference to `__imp__fmode'
> 

`_fmode` is exported from MSVCRT without the `__imp_` prefix. However,
GNU LD should handle this without problems [1]. You may try adding
`-Wl,--enable-auto-import` and see whether it fixes this for you.

I can't say more about this error due to lack of knowledge. Jacek might
know something as it was he that authored this commit
(2e64b9e4537d564478f17b873b2f655f518325ed).


[1] https://sourceware.org/binutils/docs/ld/Options.html#Options

> I think it has something to do with the crtbegin.o and crtend.o, because the 
> option -nodefaultlibs does include the startfiles. And the option -nostdlib 
> does not include the startfiles.
> 
> So when I replace -nodefaultlibs with -nostdlib in the above command line 
> I'm getting a different undefined reference:
> ertr000001.o:(.rdata+0x0): undefined reference to 
> `_pei386_runtime_relocator'
> 
> My questions are:
> Do you think the gcc supplied startfiles are interoperable with LLVM libc++?
> Can you think of a way to get my example to link correctly?
> 

Those startup .o files are provided mainly by mingw-w64 (GCC provides
'crtbegin.o' and 'crtend.o' but they are empty in this case). There are
a few checks for the pre-defined macro `__clang__`  in our crt code so I
presume those compiled for GCC and those for clang aren't fully compatible.



> Best regards,
> Maarten Verhage 
> 
> 


-- 
Best regards,
LH_Mouse

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to