MSDN > Home page del forum > Visual C++ General > Problem in creating Exe using MFC in static LIb
Formula una domandaFormula una domanda
 

Con rispostaProblem in creating Exe using MFC in static LIb

  • domenica 10 maggio 2009 21.19nsham Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     
    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

Risposte

  • domenica 10 maggio 2009 21.31masher2 Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     Con risposta
    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
    • Contrassegnato come rispostansham domenica 10 maggio 2009 23.24
    •  
  • domenica 10 maggio 2009 23.47nsham Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     Con risposta
    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();

    • Contrassegnato come rispostansham lunedì 13 luglio 2009 18.09
    •  
  • lunedì 11 maggio 2009 0.58masher2 Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     Con rispostaContiene codice
    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
    • Contrassegnato come rispostansham lunedì 11 maggio 2009 1.13
    •  

Tutte le risposte

  • domenica 10 maggio 2009 21.31masher2 Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     Con risposta
    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
    • Contrassegnato come rispostansham domenica 10 maggio 2009 23.24
    •  
  • domenica 10 maggio 2009 23.00nobugzMVP, ModeratoreMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     
    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.
  • domenica 10 maggio 2009 23.30nsham Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     
    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
  • domenica 10 maggio 2009 23.37masher2 Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     
    Can you post your actual code? 
    Michael Asher
  • domenica 10 maggio 2009 23.47nsham Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     Con risposta
    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();

    • Contrassegnato come rispostansham lunedì 13 luglio 2009 18.09
    •  
  • lunedì 11 maggio 2009 0.58masher2 Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     Con rispostaContiene codice
    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
    • Contrassegnato come rispostansham lunedì 11 maggio 2009 1.13
    •  
  • lunedì 11 maggio 2009 1.13nsham Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     
    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
  • giovedì 2 luglio 2009 18.38solled Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     
    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