Web lists-archives.com

Re: [Mingw-users] Can't do partial linking with libmoldname.a?




 > Hi.
 >
 >
 > It seems to work fine in my environment.
 >
 >
 > $ gcc -c -o test.o test.c
 >
 > $ ld -o big.o -r test.o /mingw/lib/libmoldname.a
 >
 > $ gcc -o test.exe big.o
 >
 > $ test.exe
 > hello
 >
 > Administrator@melbourne /src
 > $
 >
 >
 >> oh , before using mingw have ensuring that collect.exe run  , there is
 >> always a missing dll that need to be copied from binutils folder that
 >
 > I never had to do that!
 >
 >> Is this a bug? Or the libmoldname.a can't be partial linked?
 > Maybe your issue is related to your particular setup or gcc version? 
Do you have both x86 & x64 installations on the same box?
 >
 >


That's strange, I can reproduce the problem in a clean environment.
Is there any wrong in my installing steps?

Here are my steps:
(1) Start a new and clean Windows XP 32-bit virtual machine
(2) Use mingw-get.exe to install mingw (with package 'mingw32-base' and 
'msys-base' installed)
(3) Run C:\MinGW\msys\1.0\msys.bat to start a MSYS environment
(4) Create C:\src\test.c
(5) Run the commands

Here are my commands:

// first remove all object files
zby@winxp-vbox /c/src
$ rm *.o

// compile the C source without linking
zby@winxp-vbox /c/src
$ gcc -c -o test.o test.c

// see what symbols is in the object file
zby@winxp-vbox /c/src
$ nm test.o
00000000 b .bss
00000000 d .data
00000000 r .eh_frame
00000000 r .rdata
00000000 r .rdata$zzz
00000000 t .text
          U ___main
00000000 T _main
          U _puts
          U _strdup


// see what symbols the archive file provides
zby@winxp-vbox /c/src
$ nm /mingw/lib/libmoldname.a | grep strdup
00000000 I __imp__strdup
00000000 T _strdup

// do the partial linking
zby@winxp-vbox /c/src
$ ld -r -o big.o test.o /mingw/lib/libmoldname.a

// see what symbols is in the newly generated object file
zby@winxp-vbox /c/src
$ nm big.o
00000000 b .bss
00000000 d .data
00000000 r .eh_frame
00000004 i .idata$4
00000004 i .idata$5
00000000 i .idata$5
00000000 i .idata$6
00000000 r .rdata
00000000 r .rdata$zzz
00000000 t .text
          U ___main
00000000 I __head_libmoldname_a
00000000 I __imp__strdup
00000000 I __libmoldname_a_iname
00000000 T _main
          U _puts
0000002c T _strdup

// do the final link, should generate executable
// but is failed with the following error message
zby@winxp-vbox /c/src
$ gcc -o test.exe big.o
c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/bin/ld.exe: 
final link failed: File truncated
collect2.exe: error: ld returned 1 exit status






 > oh , before using mingw have ensuring that collect.exe run  , there is
 > always a missing dll that need to be copied from binutils folder that
 > is C:/MinGW/bin  to that folder containing linker , please ensure
 > that all binutils run before using MinGW gcc compiler collection
 >
 > On 25/11/2016, frank muhoro <frankmuhoro76@xxxxxxxxx> wrote:
 >> To be sincere I have been using makefiles since and the same MinGW
 >> from sourceforge using mingw-get.exe  and things are always good for
 >> me , I also use CMake , but I normally program as a hobby
 >>
 >> On 25/11/2016, frank muhoro <frankmuhoro76@xxxxxxxxx> wrote:
 >>> if you want an executable called frank.exe  you have to link lets say
 >>> frank.o  boyang.o or a static library , this is the reason makefiles
 >>> are there for you , I would suggest you to learn how to write gnu
 >>> makefiles www.gnu.org/software/make/manual  then use MSYS base to run
 >>> make  make --always-make to produce executable , learn how to invoke
 >>> binutils within the makefile
 >>>
 >>> On 25/11/2016, frank muhoro <frankmuhoro76@xxxxxxxxx> wrote:
 >>>> please file the error that gcc compiler yields
 >>>>
 >>>> On 25/11/2016, 张博洋 <zhangboyang.id@xxxxxxxxx> wrote:
 >>>>> emm... I'm not linking an executable and an object file. In fact, I
 >>>>> tried to partial linking an object file and a library (or archive
 >>>>> file),
 >>>>> that succeeds. But when I tried to generate EXE from the partial
 >>>>> linking
 >>>>> output object file, it failed.
 >>>>>
 >>>>> my first step:
 >>>>> 	test.c  ===== gcc C compiler =====> test.o
 >>>>> 	(compile only, no linking, succeed)
 >>>>> second step:
 >>>>> 	test.o + libmoldname.a === ld linker ===> big.o
 >>>>> 	(partial linking an object file 'test.o' and an archive file
 >>>>> 'libmoldname.a', should generate an object file 'big.o', succeed)
 >>>>> third step:
 >>>>> 	big.o ==== use gcc as linker ====> test.exe
 >>>>> 	(generate executable from one object file, failed)
 >>>>>
 >>>>> 	
 >>>>>> an executable  is as a result of linking two object files , you 
can't
 >>>>>> link an executable and an object file , again gcc is a c 
compiler not
 >>>>>> a linker although it can invoke it  ,  in your  command you seem to
 >>>>>> want gcc to combine an object file to an executable , if you have
 >>>>>> issues with linking I suggest you learn to use makefiles,makefile
 >>>>>> generators(cmake) etc and analyze the generated makefiles , 
ld.exe is
 >>>>>> the linker ,thank you.

I don't think a makefile will help in this situation.
Manually entering these commands should make the problem easier to 
understand.

------------------------------------------------------------------------------
_______________________________________________
MinGW-users mailing list
MinGW-users@xxxxxxxxxxxxxxxxxxxxx

This list observes the Etiquette found at 
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:mingw-users-request@xxxxxxxxxxxxxxxxxxxxx?subject=unsubscribe