Le réseau pour les développeurs >
Forums - Accueil
>
Visual C++ General
>
Problem in creating Exe using MFC in static LIb
Problem in creating Exe using MFC in static LIb
- Hi All,
I have application which was using MFC dynamic lib but with this when i create the MFC application(exe) it is depend the MFC dll (I cannot runs this with MFC installed). So to make it DLL independent i switched to MFC static lib.. With this configuration i getting the following
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _fread already defined in libcmt.lib(fread.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _sprintf already defined in libcmt.lib(sprintf.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _fwrite already defined in libcmt.lib(fwrite.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _fflush already defined in libcmt.lib(fflush.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _getenv already defined in libcmt.lib(getenv.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _malloc already defined in libcmt.lib(malloc.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _free already defined in libcmt.lib(free.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _exit already defined in libcmt.lib(crt0dat.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: __errno already defined in libcmt.lib(dosmap.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _fprintf already defined in libcmt.lib(fprintf.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _memmove already defined in libcmt.lib(memmove.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _fputs already defined in libcmt.lib(fputs.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _printf already defined in libcmt.lib(printf.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _strncmp already defined in libcmt.lib(strncmp.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: __strnicmp already defined in libcmt.lib(strnicmp.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: __snprintf already defined in libcmt.lib(snprintf.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _toupper already defined in libcmt.lib(toupper.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _tolower already defined in libcmt.lib(tolower.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _fclose already defined in libcmt.lib(fclose.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _strncpy already defined in libcmt.lib(strncpy.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _setlocale already defined in libcmt.lib(setlocal.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _fopen already defined in libcmt.lib(fopen.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: __setmode already defined in libcmt.lib(setmode.obj)
LINK : warning LNK4098: defaultlib "LIBC" conflicts with use of other libs; use /NODEFAULTLIB:library
LINK : warning LNK4098: defaultlib "MSVCRT" conflicts with use of other libs; use /NODEFAULTLIB:library
..\PC\Release\MPEG4VideoPlayerStreamer.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
Thanks
shiv
Réponses
- It's telling you what's wrong -- see the "use /NODEFAULTLIB" statement? You're trying to link in multiple references to those functions:
http://msdn.microsoft.com/en-us/library/3tz4da4a(vs.71).aspx
Michael Asher- Marqué comme réponsensham dimanche 10 mai 2009 23:24
- michael is the my code
TRY { while (1) { WaitForSingleObject( poMainFrame->m_hContinueEvent, INFINITE ); if ( vdWindow.windowDismissed == TRUE ) { break; } try { decoder_main( ptrVideoStream ); } catch(...) { } { FILE *fp; fp = fopen("data.yuv","ab"); fwrite( ptrVideoStream ->out_buffer, 1, xsize * ysize * 3 / 2, fp ); fclose(fp); } TotalFrameCount++; if ( vdWindow.windowDismissed == TRUE ) { break; } now = (int) (iStartTime + (TotalFrameCount - 1) * fFrameInterval); after = GetTickCount();- Marqué comme réponsensham lundi 13 juillet 2009 18:09
- Well, it pretty clearly looks like a thread timing issue, not an optimization issue, e.g. the reason it works in debug mode is just because the code runs slower. The first step is to find out why your loop is exiting: is it breaking because the windowDismissed member is being set, or is the outer try block catching some exception?
Also, just curious but if this function is being called at 30fps, why are you closing and reopening the file each loop? That's going to kill performance.
Michael Asher- Marqué comme réponsensham lundi 11 mai 2009 01:13
Toutes les réponses
- It's telling you what's wrong -- see the "use /NODEFAULTLIB" statement? You're trying to link in multiple references to those functions:
http://msdn.microsoft.com/en-us/library/3tz4da4a(vs.71).aspx
Michael Asher- Marqué comme réponsensham dimanche 10 mai 2009 23:24
- You've got some code that was compiled with /MD. Probably in a .lib. You'll need to recompile that code with /MT.
Hans Passant. - Hi Michael,
I have one more question. In my application i have fwrite statement writing to a file. This call is happening 30 times in a seconds. But the visual C ++ 6.0 compiler is removing this statement (fwrite) after executing it first time i.e, it dumps only one time. This is happing in release mode and it is working fine in debug mode. I don't want to change optimization to debug mode from max speed mode.
Thanks
shiv - Can you post your actual code?
Michael Asher - michael is the my code
TRY { while (1) { WaitForSingleObject( poMainFrame->m_hContinueEvent, INFINITE ); if ( vdWindow.windowDismissed == TRUE ) { break; } try { decoder_main( ptrVideoStream ); } catch(...) { } { FILE *fp; fp = fopen("data.yuv","ab"); fwrite( ptrVideoStream ->out_buffer, 1, xsize * ysize * 3 / 2, fp ); fclose(fp); } TotalFrameCount++; if ( vdWindow.windowDismissed == TRUE ) { break; } now = (int) (iStartTime + (TotalFrameCount - 1) * fFrameInterval); after = GetTickCount();- Marqué comme réponsensham lundi 13 juillet 2009 18:09
- Well, it pretty clearly looks like a thread timing issue, not an optimization issue, e.g. the reason it works in debug mode is just because the code runs slower. The first step is to find out why your loop is exiting: is it breaking because the windowDismissed member is being set, or is the outer try block catching some exception?
Also, just curious but if this function is being called at 30fps, why are you closing and reopening the file each loop? That's going to kill performance.
Michael Asher- Marqué comme réponsensham lundi 11 mai 2009 01:13
- Thanks Michael,
I got it. your prediction is correct , while loop is getting executed only once and at the end of while loop there is function call and it was never coming out of it. And i removed it now it is working fine.
Thanks
shiv - I got this error when I tried to use the glui32.lib library. As someone else suggested I rebuilt glui32.lib changing \MD to \MT. And that worked! (I also had to change \MD to \MDd in my code that I was building to clear up some other linker errors). thanks to nobugz
see: http://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx

