Can't do partial linking with libmoldname.a?

classic Classic list List threaded Threaded
17 messages Options
Reply | Threaded
Open this post in threaded view
|

Can't do partial linking with libmoldname.a?

张博洋

Hello,
     I'm trying to do partial linking a .o file with libmoldname.a, the
partial linking is OK, but when I linking the generated .o to .exe, the
linking failed. Here are my steps:
     I have a C source file, test.c, with the following code:
         #include <stdio.h>
         #include <string.h>
         int main()
         {
             puts(strdup("hello"));
                 // strdup() is in libmoldname.a
             return 0;
         }
     Compile the C code (success):
         gcc -c -o test.o test.c
         Partial linking (success):
         ld -o big.o -r test.o /mingw/lib/libmoldname.a
     Finally, link to generate EXE file (failed):
         gcc -o test.exe big.o
     The error message is:
 
c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/bin/ld.exe:
final link failed: File truncated

     Is this a bug? Or the libmoldname.a can't be partial linked?

--
Regards,
Zhang Boyang
School of Computer Science, Fudan University, P.R.China

------------------------------------------------------------------------------
_______________________________________________
MinGW-users mailing list
[hidden email]

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:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: Can't do partial linking with libmoldname.a?

frank muhoro
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.

On 25/11/2016, 张博洋 <[hidden email]> wrote:

>
> Hello,
>      I'm trying to do partial linking a .o file with libmoldname.a, the
> partial linking is OK, but when I linking the generated .o to .exe, the
> linking failed. Here are my steps:
>      I have a C source file, test.c, with the following code:
>          #include <stdio.h>
>          #include <string.h>
>          int main()
>          {
>              puts(strdup("hello"));
>                  // strdup() is in libmoldname.a
>              return 0;
>          }
>      Compile the C code (success):
>          gcc -c -o test.o test.c
>          Partial linking (success):
>          ld -o big.o -r test.o /mingw/lib/libmoldname.a
>      Finally, link to generate EXE file (failed):
>          gcc -o test.exe big.o
>      The error message is:
>
> c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/bin/ld.exe:
> final link failed: File truncated
>
>      Is this a bug? Or the libmoldname.a can't be partial linked?
>
> --
> Regards,
> Zhang Boyang
> School of Computer Science, Fudan University, P.R.China
>
> ------------------------------------------------------------------------------
> _______________________________________________
> MinGW-users mailing list
> [hidden email]
>
> 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:[hidden email]?subject=unsubscribe
>

------------------------------------------------------------------------------
_______________________________________________
MinGW-users mailing list
[hidden email]

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:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: Can't do partial linking with libmoldname.a?

张博洋
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.
>
> On 25/11/2016, 张博洋 <[hidden email]> wrote:
>>
>> Hello,
>>      I'm trying to do partial linking a .o file with libmoldname.a, the
>> partial linking is OK, but when I linking the generated .o to .exe, the
>> linking failed. Here are my steps:
>>      I have a C source file, test.c, with the following code:
>>          #include <stdio.h>
>>          #include <string.h>
>>          int main()
>>          {
>>              puts(strdup("hello"));
>>                  // strdup() is in libmoldname.a
>>              return 0;
>>          }
>>      Compile the C code (success):
>>          gcc -c -o test.o test.c
>>          Partial linking (success):
>>          ld -o big.o -r test.o /mingw/lib/libmoldname.a
>>      Finally, link to generate EXE file (failed):
>>          gcc -o test.exe big.o
>>      The error message is:
>>
>> c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/bin/ld.exe:
>> final link failed: File truncated
>>
>>      Is this a bug? Or the libmoldname.a can't be partial linked?
>>
>> --
>> Regards,
>> Zhang Boyang
>> School of Computer Science, Fudan University, P.R.China
>>
>> ------------------------------------------------------------------------------
>> _______________________________________________
>> MinGW-users mailing list
>> [hidden email]
>>
>> 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:[hidden email]?subject=unsubscribe
>>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> MinGW-users mailing list
> [hidden email]
>
> 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:[hidden email]?subject=unsubscribe
>


------------------------------------------------------------------------------
_______________________________________________
MinGW-users mailing list
[hidden email]

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:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: Can't do partial linking with libmoldname.a?

frank muhoro
please file the error that gcc compiler yields

On 25/11/2016, 张博洋 <[hidden email]> 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.
>>
>> On 25/11/2016, 张博洋 <[hidden email]> wrote:
>>>
>>> Hello,
>>>      I'm trying to do partial linking a .o file with libmoldname.a, the
>>> partial linking is OK, but when I linking the generated .o to .exe, the
>>> linking failed. Here are my steps:
>>>      I have a C source file, test.c, with the following code:
>>>          #include <stdio.h>
>>>          #include <string.h>
>>>          int main()
>>>          {
>>>              puts(strdup("hello"));
>>>                  // strdup() is in libmoldname.a
>>>              return 0;
>>>          }
>>>      Compile the C code (success):
>>>          gcc -c -o test.o test.c
>>>          Partial linking (success):
>>>          ld -o big.o -r test.o /mingw/lib/libmoldname.a
>>>      Finally, link to generate EXE file (failed):
>>>          gcc -o test.exe big.o
>>>      The error message is:
>>>
>>> c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/bin/ld.exe:
>>> final link failed: File truncated
>>>
>>>      Is this a bug? Or the libmoldname.a can't be partial linked?
>>>
>>> --
>>> Regards,
>>> Zhang Boyang
>>> School of Computer Science, Fudan University, P.R.China
>>>
>>> ------------------------------------------------------------------------------
>>> _______________________________________________
>>> MinGW-users mailing list
>>> [hidden email]
>>>
>>> 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:[hidden email]?subject=unsubscribe
>>>
>>
>> ------------------------------------------------------------------------------
>> _______________________________________________
>> MinGW-users mailing list
>> [hidden email]
>>
>> 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:[hidden email]?subject=unsubscribe
>>
>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> MinGW-users mailing list
> [hidden email]
>
> 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:[hidden email]?subject=unsubscribe

------------------------------------------------------------------------------
_______________________________________________
MinGW-users mailing list
[hidden email]

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:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: Can't do partial linking with libmoldname.a?

frank muhoro
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 <[hidden email]> wrote:

> please file the error that gcc compiler yields
>
> On 25/11/2016, 张博洋 <[hidden email]> 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.
>>>
>>> On 25/11/2016, 张博洋 <[hidden email]> wrote:
>>>>
>>>> Hello,
>>>>      I'm trying to do partial linking a .o file with libmoldname.a, the
>>>> partial linking is OK, but when I linking the generated .o to .exe, the
>>>> linking failed. Here are my steps:
>>>>      I have a C source file, test.c, with the following code:
>>>>          #include <stdio.h>
>>>>          #include <string.h>
>>>>          int main()
>>>>          {
>>>>              puts(strdup("hello"));
>>>>                  // strdup() is in libmoldname.a
>>>>              return 0;
>>>>          }
>>>>      Compile the C code (success):
>>>>          gcc -c -o test.o test.c
>>>>          Partial linking (success):
>>>>          ld -o big.o -r test.o /mingw/lib/libmoldname.a
>>>>      Finally, link to generate EXE file (failed):
>>>>          gcc -o test.exe big.o
>>>>      The error message is:
>>>>
>>>> c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/bin/ld.exe:
>>>> final link failed: File truncated
>>>>
>>>>      Is this a bug? Or the libmoldname.a can't be partial linked?
>>>>
>>>> --
>>>> Regards,
>>>> Zhang Boyang
>>>> School of Computer Science, Fudan University, P.R.China
>>>>
>>>> ------------------------------------------------------------------------------
>>>> _______________________________________________
>>>> MinGW-users mailing list
>>>> [hidden email]
>>>>
>>>> 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:[hidden email]?subject=unsubscribe
>>>>
>>>
>>> ------------------------------------------------------------------------------
>>> _______________________________________________
>>> MinGW-users mailing list
>>> [hidden email]
>>>
>>> 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:[hidden email]?subject=unsubscribe
>>>
>>
>>
>> ------------------------------------------------------------------------------
>> _______________________________________________
>> MinGW-users mailing list
>> [hidden email]
>>
>> 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:[hidden email]?subject=unsubscribe
>

------------------------------------------------------------------------------
_______________________________________________
MinGW-users mailing list
[hidden email]

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:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: Can't do partial linking with libmoldname.a?

frank muhoro
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 <[hidden email]> 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 <[hidden email]> wrote:
>> please file the error that gcc compiler yields
>>
>> On 25/11/2016, 张博洋 <[hidden email]> 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.
>>>>
>>>> On 25/11/2016, 张博洋 <[hidden email]> wrote:
>>>>>
>>>>> Hello,
>>>>>      I'm trying to do partial linking a .o file with libmoldname.a,
>>>>> the
>>>>> partial linking is OK, but when I linking the generated .o to .exe,
>>>>> the
>>>>> linking failed. Here are my steps:
>>>>>      I have a C source file, test.c, with the following code:
>>>>>          #include <stdio.h>
>>>>>          #include <string.h>
>>>>>          int main()
>>>>>          {
>>>>>              puts(strdup("hello"));
>>>>>                  // strdup() is in libmoldname.a
>>>>>              return 0;
>>>>>          }
>>>>>      Compile the C code (success):
>>>>>          gcc -c -o test.o test.c
>>>>>          Partial linking (success):
>>>>>          ld -o big.o -r test.o /mingw/lib/libmoldname.a
>>>>>      Finally, link to generate EXE file (failed):
>>>>>          gcc -o test.exe big.o
>>>>>      The error message is:
>>>>>
>>>>> c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/bin/ld.exe:
>>>>> final link failed: File truncated
>>>>>
>>>>>      Is this a bug? Or the libmoldname.a can't be partial linked?
>>>>>
>>>>> --
>>>>> Regards,
>>>>> Zhang Boyang
>>>>> School of Computer Science, Fudan University, P.R.China
>>>>>
>>>>> ------------------------------------------------------------------------------
>>>>> _______________________________________________
>>>>> MinGW-users mailing list
>>>>> [hidden email]
>>>>>
>>>>> 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:[hidden email]?subject=unsubscribe
>>>>>
>>>>
>>>> ------------------------------------------------------------------------------
>>>> _______________________________________________
>>>> MinGW-users mailing list
>>>> [hidden email]
>>>>
>>>> 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:[hidden email]?subject=unsubscribe
>>>>
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> _______________________________________________
>>> MinGW-users mailing list
>>> [hidden email]
>>>
>>> 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:[hidden email]?subject=unsubscribe
>>
>

------------------------------------------------------------------------------
_______________________________________________
MinGW-users mailing list
[hidden email]

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:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: Can't do partial linking with libmoldname.a?

frank muhoro
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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> wrote:
>>> please file the error that gcc compiler yields
>>>
>>> On 25/11/2016, 张博洋 <[hidden email]> 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.
>>>>>
>>>>> On 25/11/2016, 张博洋 <[hidden email]> wrote:
>>>>>>
>>>>>> Hello,
>>>>>>      I'm trying to do partial linking a .o file with libmoldname.a,
>>>>>> the
>>>>>> partial linking is OK, but when I linking the generated .o to .exe,
>>>>>> the
>>>>>> linking failed. Here are my steps:
>>>>>>      I have a C source file, test.c, with the following code:
>>>>>>          #include <stdio.h>
>>>>>>          #include <string.h>
>>>>>>          int main()
>>>>>>          {
>>>>>>              puts(strdup("hello"));
>>>>>>                  // strdup() is in libmoldname.a
>>>>>>              return 0;
>>>>>>          }
>>>>>>      Compile the C code (success):
>>>>>>          gcc -c -o test.o test.c
>>>>>>          Partial linking (success):
>>>>>>          ld -o big.o -r test.o /mingw/lib/libmoldname.a
>>>>>>      Finally, link to generate EXE file (failed):
>>>>>>          gcc -o test.exe big.o
>>>>>>      The error message is:
>>>>>>
>>>>>> c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/bin/ld.exe:
>>>>>> final link failed: File truncated
>>>>>>
>>>>>>      Is this a bug? Or the libmoldname.a can't be partial linked?
>>>>>>
>>>>>> --
>>>>>> Regards,
>>>>>> Zhang Boyang
>>>>>> School of Computer Science, Fudan University, P.R.China
>>>>>>
>>>>>> ------------------------------------------------------------------------------
>>>>>> _______________________________________________
>>>>>> MinGW-users mailing list
>>>>>> [hidden email]
>>>>>>
>>>>>> 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:[hidden email]?subject=unsubscribe
>>>>>>
>>>>>
>>>>> ------------------------------------------------------------------------------
>>>>> _______________________________________________
>>>>> MinGW-users mailing list
>>>>> [hidden email]
>>>>>
>>>>> 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:[hidden email]?subject=unsubscribe
>>>>>
>>>>
>>>>
>>>> ------------------------------------------------------------------------------
>>>> _______________________________________________
>>>> MinGW-users mailing list
>>>> [hidden email]
>>>>
>>>> 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:[hidden email]?subject=unsubscribe
>>>
>>
>

------------------------------------------------------------------------------
_______________________________________________
MinGW-users mailing list
[hidden email]

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:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: Can't do partial linking with libmoldname.a?

Sergio NNX

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?


------------------------------------------------------------------------------

_______________________________________________
MinGW-users mailing list
[hidden email]

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:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: 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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> wrote:
 >>>> please file the error that gcc compiler yields
 >>>>
 >>>> On 25/11/2016, 张博洋 <[hidden email]> 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
[hidden email]

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:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: Can't do partial linking with libmoldname.a?

Eli Zaretskii
> From: 张博洋 <[hidden email]>
> Date: Sat, 26 Nov 2016 15:37:37 +0800
>
> // do the partial linking
> zby@winxp-vbox /c/src
> $ ld -r -o big.o test.o /mingw/lib/libmoldname.a

Is there any reason to assume "ld -r" works with MinGW?

------------------------------------------------------------------------------
_______________________________________________
MinGW-users mailing list
[hidden email]

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:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: Can't do partial linking with libmoldname.a?

张博洋
Yes, linking some .o together works:
        ld -r -o big.o somecode1.o somecode2.o somecode3.o
        (OK, gcc -o test.exe big.o will generate runnable executable)
linking .o with libgcc.a or libmingwex.a also work:
        ld -r -o big.o somecode1.o somecode2.o somecode3.o /mingw/lib/libmingwex.o
        (OK)
But, linking with libmoldname.a will result in failure at the final step.



>> From: 张博洋 <[hidden email]>
>> Date: Sat, 26 Nov 2016 15:37:37 +0800
>>
>> // do the partial linking
>> zby@winxp-vbox /c/src
>> $ ld -r -o big.o test.o /mingw/lib/libmoldname.a
>
> Is there any reason to assume "ld -r" works with MinGW?
>
> ------------------------------------------------------------------------------
> _______________________________________________
> MinGW-users mailing list
> [hidden email]
>
> 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:[hidden email]?subject=unsubscribe
>

------------------------------------------------------------------------------
_______________________________________________
MinGW-users mailing list
[hidden email]

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:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: Can't do partial linking with libmoldname.a?

Eli Zaretskii
> From: 张博洋 <[hidden email]>
> Date: Sat, 26 Nov 2016 17:26:41 +0800
>
> Yes, linking some .o together works:
> ld -r -o big.o somecode1.o somecode2.o somecode3.o
> (OK, gcc -o test.exe big.o will generate runnable executable)
> linking .o with libgcc.a or libmingwex.a also work:
> ld -r -o big.o somecode1.o somecode2.o somecode3.o /mingw/lib/libmingwex.o
> (OK)
> But, linking with libmoldname.a will result in failure at the final step.

libmoldname is an import library, while libmingwex is not, so these
two examples are not the same use case.

Let me rephrase: is there any reason to assume "ld -r" works with
MinGW import libraries?

And what is the semantics of "partial linking" with an import library,
anyway?

------------------------------------------------------------------------------
_______________________________________________
MinGW-users mailing list
[hidden email]

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:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: Can't do partial linking with libmoldname.a?

张博洋
OK, I'm not sure whether "ld -r" works with import libraries ...


Maybe partial linking with an import library means gluing .text sections
of many objects and preserve import sections?

// import libraries is also a bunch of object files
// extract the corresponding object file from archive
zby@winxp-vbox /c/src
$ ar x /mingw/lib/libmoldname.a doois00080.o

// see what is in that object file
zby@winxp-vbox /c/src
$ objdump -t -r -d doois00080.o

doois00080.o:     file format pe-i386

SYMBOL TABLE:
[  0](sec  5)(fl 0x00)(ty   0)(scl   3) (nx 0) 0x00000000 .idata$5
[  1](sec  7)(fl 0x00)(ty   0)(scl   3) (nx 0) 0x00000000 .idata$6
[  2](sec  1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 _strdup
[  3](sec  5)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 __imp__strdup
[  4](sec  0)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000
__head_libmoldname_a

// there is also .text section in the object file, and have runnable
code in it

Disassembly of section .text:

00000000 <_strdup>:
    0:   ff 25 00 00 00 00       jmp    *0x0
                         2: dir32        .idata$5
    6:   90                      nop
    7:   90                      nop



So the issue is that the "ld -r" can't work with import libraries?


>> From: 张博洋 <[hidden email]>
>> Date: Sat, 26 Nov 2016 17:26:41 +0800
>>
>> Yes, linking some .o together works:
>> ld -r -o big.o somecode1.o somecode2.o somecode3.o
>> (OK, gcc -o test.exe big.o will generate runnable executable)
>> linking .o with libgcc.a or libmingwex.a also work:
>> ld -r -o big.o somecode1.o somecode2.o somecode3.o /mingw/lib/libmingwex.o
>> (OK)
>> But, linking with libmoldname.a will result in failure at the final step.
>
> libmoldname is an import library, while libmingwex is not, so these
> two examples are not the same use case.
>
> Let me rephrase: is there any reason to assume "ld -r" works with
> MinGW import libraries?
>
> And what is the semantics of "partial linking" with an import library,
> anyway?
>



------------------------------------------------------------------------------
_______________________________________________
MinGW-users mailing list
[hidden email]

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:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: Can't do partial linking with libmoldname.a?

Eli Zaretskii
> From: 张博洋 <[hidden email]>
> Date: Sat, 26 Nov 2016 18:05:59 +0800
>
> // there is also .text section in the object file, and have runnable
> code in it
>
> Disassembly of section .text:
>
> 00000000 <_strdup>:
>     0:   ff 25 00 00 00 00       jmp    *0x0
>                          2: dir32        .idata$5
>     6:   90                      nop
>     7:   90                      nop

Yes, that indirect jump through an import table is what import
libraries are all about.

> So the issue is that the "ld -r" can't work with import libraries?

I don't really know, I never tried "ld -r".  I asked what would be the
semantics of that, and I still don't know the answer to that.

------------------------------------------------------------------------------
_______________________________________________
MinGW-users mailing list
[hidden email]

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:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: Can't do partial linking with libmoldname.a?

张博洋


在 2016年11月26日 19:29, Eli Zaretskii 写道:

> I don't really know, I never tried "ld -r".  I asked what would be the
> semantics of that, and I still don't know the answer to that.

I think the semantics of "ld -r" is gluing input object files together,
output a single and big object file.

The object files in an import library just like other object files, it
can has it's own .text segment (maybe .data as well), the difference is
that it have some import section.

So "ld -r" an object and an import library can generate a single big
object, with .text segment gluing together, and preserving import data.



In fact, I'm using this technique to compile my code (used some GCC only
extensions) to a single and MSVC usable .obj file. As a temporary
solution, I replaced all "strdup" to "_strdup" by defining a macro, to
avoid linking to libmoldname.a

------------------------------------------------------------------------------
_______________________________________________
MinGW-users mailing list
[hidden email]

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:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: Can't do partial linking with libmoldname.a?

Eli Zaretskii
> From: 张博洋 <[hidden email]>
> Date: Sat, 26 Nov 2016 19:57:31 +0800
>
> 在 2016年11月26日 19:29, Eli Zaretskii 写道:
>
> > I don't really know, I never tried "ld -r".  I asked what would be the
> > semantics of that, and I still don't know the answer to that.
>
> I think the semantics of "ld -r" is gluing input object files together,
> output a single and big object file.
>
> The object files in an import library just like other object files, it
> can has it's own .text segment (maybe .data as well), the difference is
> that it have some import section.
>
> So "ld -r" an object and an import library can generate a single big
> object, with .text segment gluing together, and preserving import data.

Maybe it's worth reporting a bug to the Binutils developers.

------------------------------------------------------------------------------
_______________________________________________
MinGW-users mailing list
[hidden email]

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:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: Can't do partial linking with libmoldname.a?

张博洋
OK, Thank you, I would try to report this to binutils.

>> From: 张博洋 <[hidden email]>
>> Date: Sat, 26 Nov 2016 19:57:31 +0800
>>
>> 在 2016年11月26日 19:29, Eli Zaretskii 写道:
>>
>>> I don't really know, I never tried "ld -r".  I asked what would be the
>>> semantics of that, and I still don't know the answer to that.
>>
>> I think the semantics of "ld -r" is gluing input object files together,
>> output a single and big object file.
>>
>> The object files in an import library just like other object files, it
>> can has it's own .text segment (maybe .data as well), the difference is
>> that it have some import section.
>>
>> So "ld -r" an object and an import library can generate a single big
>> object, with .text segment gluing together, and preserving import data.
>
> Maybe it's worth reporting a bug to the Binutils developers.
>



------------------------------------------------------------------------------
_______________________________________________
MinGW-users mailing list
[hidden email]

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:[hidden email]?subject=unsubscribe