Quantcast

Multiple definition of `_printf' with when using __USE_MINGW_ANSI_STDIO

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Multiple definition of `_printf' with when using __USE_MINGW_ANSI_STDIO

Alexander Shaduri

Hi all,

I'm resending this message because I haven't received any post
acknowledgmenet from sourceforge for 3 days. I hope the other
two messages I sent - "AttachConsole is incorrectly specified as
since win2k, not xp" and "Invalid prototype for _open_osfhandle() in io.h"
reached this list.
Sorry if you receive this twice.

The original message follows:


I have a linking problem when using -D__USE_MINGW_ANSI_STDIO.
I get "multiple definition of `_printf'" link-time error when linking several
objects which all use std::printf().


To reproduce:

File test_printf1.cpp :
----------------------------------------------------
#include <cstdio>
int main()
{
        std::printf("hello\n");
        return 0;
}
----------------------------------------------------


File test_printf2.cpp :
----------------------------------------------------
#include <cstdio>
void func()
{
        std::printf("world\n");
}
----------------------------------------------------


$ i386-pc-mingw32-g++ -D__USE_MINGW_ANSI_STDIO test_printf1.cpp -c -o test_printf1.o

$ i386-pc-mingw32-g++ -D__USE_MINGW_ANSI_STDIO test_printf2.cpp -c -o test_printf2.o

$ i386-pc-mingw32-g++ test_printf1.o test_printf2.o -o test_printf.exe
test_printf2.o:test_printf2.cpp:(.text+0x14): multiple definition of `_printf'
test_printf1.o:test_printf1.cpp:(.text+0x3e): first defined here
collect2: ld returned 1 exit status

$ i386-pc-mingw32-nm test_printf1.o
00000000 b .bss
00000000 d .data
00000000 r .rdata
00000000 t .text
         U ___main
         U ___mingw_vprintf
         U __alloca
00000000 T _main
0000003e T _printf

$ i386-pc-mingw32-nm test_printf2.o
00000000 b .bss
00000000 d .data
00000000 r .rdata
00000000 t .text
00000000 T __Z4funcv
         U ___mingw_vprintf
00000014 T _printf


I'm using gcc 3.4.5 (mingw version) cross-compiler (from linux),
binutils-2.19.1, mingwrt-3.16, w32api-3.13.


Thanks,
Alexander

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
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.

Most annoying abuses are:
1) Top posting
2) Thread hijacking
3) HTML/MIME encoded mail
4) Improper quoting
5) Improper trimming
_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Multiple definition of `_printf' with when using __USE_MINGW_ANSI_STDIO

John Brown
Alexander Shaduri <ashaduri@...> writes:

>
>
> Hi all,
>
<snip/>
>
> I have a linking problem when using -D__USE_MINGW_ANSI_STDIO.
> I get "multiple definition of `_printf'" link-time error when linking several
> objects which all use std::printf().

<snip/>

 $ i386-pc-mingw32-g++ -D__USE_MINGW_ANSI_STDIO test_printf1.cpp -c -o
test_printf1.o
>
> $ i386-pc-mingw32-g++ -D__USE_MINGW_ANSI_STDIO test_printf2.cpp -c -o
test_printf2.o
>
> $ i386-pc-mingw32-g++ test_printf1.o test_printf2.o -o test_printf.exe
> test_printf2.o:test_printf2.cpp:(.text+0x14): multiple definition of `_printf'
> test_printf1.o:test_printf1.cpp:(.text+0x3e): first defined here
> collect2: ld returned 1 exit status
>
<snip/>
>
> I'm using gcc 3.4.5 (mingw version) cross-compiler (from linux),
> binutils-2.19.1, mingwrt-3.16, w32api-3.13.
>
> Thanks,
> Alexander
>

I can only confirm that it happens with Windows MinGW (g++ 3.4.5,
mingwrt-3.15.2), but not with Kubuntu Jaunty (i586-mingw32msvc-g++ 4.2.1-sjlj,
mingw-runtime 3.13-1.)

Regards,
Alias John Brown.


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
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.

Most annoying abuses are:
1) Top posting
2) Thread hijacking
3) HTML/MIME encoded mail
4) Improper quoting
5) Improper trimming
_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Multiple definition of `_printf' with when using __USE_MINGW_ANSI_STDIO

Alexander Shaduri
On Tue, 1 Sep 2009 11:11:49 +0000 (UTC)
John Brown <[hidden email]> wrote:

>  $ i386-pc-mingw32-g++ -D__USE_MINGW_ANSI_STDIO test_printf1.cpp -c -o
> test_printf1.o
> >
> > $ i386-pc-mingw32-g++ -D__USE_MINGW_ANSI_STDIO test_printf2.cpp -c -o
> test_printf2.o
> >
> > $ i386-pc-mingw32-g++ test_printf1.o test_printf2.o -o test_printf.exe
> > test_printf2.o:test_printf2.cpp:(.text+0x14): multiple definition of `_printf'
> > test_printf1.o:test_printf1.cpp:(.text+0x3e): first defined here
> > collect2: ld returned 1 exit status
> >
> <snip/>
> >
> > I'm using gcc 3.4.5 (mingw version) cross-compiler (from linux),
> > binutils-2.19.1, mingwrt-3.16, w32api-3.13.
>
> I can only confirm that it happens with Windows MinGW (g++ 3.4.5,
> mingwrt-3.15.2), but not with Kubuntu Jaunty (i586-mingw32msvc-g++ 4.2.1-sjlj,
> mingw-runtime 3.13-1.)

Thanks, that's probably because -D__USE_MINGW_ANSI_STDIO had
no effect in mingwrt < 3.15. :)
The macro is supposed to enable standard C printf family of functions,
overriding the msvcrt ones. It seems that the implementation has
some problems though, as evidenced by the errors above.

Thanks,
Alexander

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
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.

Most annoying abuses are:
1) Top posting
2) Thread hijacking
3) HTML/MIME encoded mail
4) Improper quoting
5) Improper trimming
_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Multiple definition of `_printf' with when using __USE_MINGW_ANSI_STDIO

Keith Marshall
In reply to this post by Alexander Shaduri
On Tuesday 01 September 2009 09:46:36 Alexander Shaduri wrote:
> I'm resending this message because I haven't received any post
> acknowledgmenet from sourceforge for 3 days.

This is precisely why we prefer you to file bug reports on the
tracker, rather than on the list.  It isn't that we like to be
awkward, (as some might suggest); on the tracker, you get an
automatic acknowledgment that your report has been successfully
filed, and an automatic confirmation when a developer picks up the
assignment.

Instead, you got no confirmation of your original post, and now, by
impatiently demanding one, you distract me from the task, which I
had already begun, of identifying and resolving the bug.

On Tuesday 01 September 2009 12:11:49 John Brown wrote:
> I can only confirm that it happens with Windows MinGW (g++ 3.4.5,
> mingwrt-3.15.2),

Thank you, but I had already confirmed it for myself.

> but not with Kubuntu Jaunty (i586-mingw32msvc-g++
> 4.2.1-sjlj, mingw-runtime 3.13-1.)

Of course it doesn't; the feature which introduced the problem was
unavailable prior to mingwrt-3.15.

On Tuesday 01 September 2009 12:32:11 Alexander Shaduri wrote:
> It seems that the implementation has
> some problems though, as evidenced by the errors above.

Well, it isn't unusual for a new implementation to experience a few
teething troubles; that this one hasn't surfaced before suggests
that it doesn't get a lot of exposure.  In any case, you can fix it
by removing the `static' keyword from line 223 of include/stdio.h in
your mingwrt-3.16 headers set, as I have done in CVS.

--

Regards,
Keith.

2009-09-01  Keith Marshall  <[hidden email]>

        Avoid multiple link time definitions of _printf() for C++;
        (problem reported by Alexander Shaduri, via MinGW-users ML).

        * include/stdio.h [__USE_MINGW_ANSI_STDIO]:
        (__mingw_stdio_redirect__) [__cplusplus]: remove `static' keyword.

Index: include/stdio.h
===================================================================
RCS file: /cvs/src/src/winsup/mingw/include/stdio.h,v
retrieving revision 1.40
diff -u -r1.40 stdio.h
--- include/stdio.h 8 Aug 2009 13:26:11 -0000 1.40
+++ include/stdio.h 1 Sep 2009 20:36:14 -0000
@@ -220,7 +220,7 @@
  * For C++ we use inline implementations, to avoid interference
  * with namespace qualification, which may result from using #defines.
  */
-#  define __mingw_stdio_redirect__  static inline __cdecl __MINGW_NOTHROW
+#  define __mingw_stdio_redirect__  inline __cdecl __MINGW_NOTHROW
 
 # elif defined __GNUC__
 /*

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
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.

Most annoying abuses are:
1) Top posting
2) Thread hijacking
3) HTML/MIME encoded mail
4) Improper quoting
5) Improper trimming
_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Multiple definition of `_printf' with when using __USE_MINGW_ANSI_STDIO

Roumen Petrov
In reply to this post by Alexander Shaduri
Alexander Shaduri wrote:
> Hi all,
[SNIP]
> I have a linking problem when using -D__USE_MINGW_ANSI_STDIO.
> I get "multiple definition of `_printf'" link-time error when linking several
> objects which all use std::printf().
[SNIP]
> test_printf2.o:test_printf2.cpp:(.text+0x14): multiple definition of `_printf'
[SNIP]
> $ i386-pc-mingw32-nm test_printf1.o
[SNIP]
> 0000003e T _printf

Look like compiler bug. For GCC 4.4.0 (cross, mingw target) result is:
00000000 t _printf

[SNIP]
>
> I'm using gcc 3.4.5 (mingw version) cross-compiler (from linux),
> binutils-2.19.1, mingwrt-3.16, w32api-3.13.

Work-around for g++ 3.4.5 is to enable optimization: -O{|1|2|3}.

> Thanks,
> Alexander

Roumen

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
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.

Most annoying abuses are:
1) Top posting
2) Thread hijacking
3) HTML/MIME encoded mail
4) Improper quoting
5) Improper trimming
_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Multiple definition of `_printf' with when using __USE_MINGW_ANSI_STDIO

Alexander Shaduri
In reply to this post by Keith Marshall

Hello,

On Tue, 1 Sep 2009 21:48:21 +0100
Keith Marshall <[hidden email]> wrote:

> On Tuesday 01 September 2009 09:46:36 Alexander Shaduri wrote:
> > I'm resending this message because I haven't received any post
> > acknowledgmenet from sourceforge for 3 days.
>
> This is precisely why we prefer you to file bug reports on the
> tracker, rather than on the list.  It isn't that we like to be
> awkward, (as some might suggest); on the tracker, you get an
> automatic acknowledgment that your report has been successfully
> filed, and an automatic confirmation when a developer picks up the
> assignment.

Sorry, I'll file them on the tracker next time.

> Instead, you got no confirmation of your original post, and now, by
> impatiently demanding one, you distract me from the task, which I
> had already begun, of identifying and resolving the bug.

Well, I was demanding a confirmation from sourceforge, not you. :)
Sourceforge has been known to swallow emails (happened to me
lots of times). Since I already had resolved that issue by using
fprintf(stdout, ...), I just wanted to make sure that the information
was received by the list (I was not in any hurry for the fix). As for
the impatient part, 3 days for an automated confirmation is more
than enough, is it not?

Anyway, sorry if my email involunteerly caused you any discomfort,
and thank you for fixing the bug.

> > It seems that the implementation has
> > some problems though, as evidenced by the errors above.
>
> Well, it isn't unusual for a new implementation to experience a few
> teething troubles; that this one hasn't surfaced before suggests
> that it doesn't get a lot of exposure.

I guess that's probably due to insufficient documentation. I, myself,
stumbled across that feature only by chance, while searching the mingw
headers for something completely different. Perhaps a centralized
(non-.h-suffixed) document describing all such features would
solve that. (Unless it exists already and I missed it somehow).

Thanks,
Alexander

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
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.

Most annoying abuses are:
1) Top posting
2) Thread hijacking
3) HTML/MIME encoded mail
4) Improper quoting
5) Improper trimming
_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Loading...