Microsoft Developer Network > 포럼 홈 > Visual C++ General > Problem in creating Exe using MFC in static LIb
질문하기질문하기
 

답변됨Problem in creating Exe using MFC in static LIb

  • 2009년 5월 10일 일요일 오후 9:19nsham 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    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

답변

  • 2009년 5월 10일 일요일 오후 9:31masher2 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨
    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
    • 답변으로 표시됨nsham 2009년 5월 10일 일요일 오후 11:24
    •  
  • 2009년 5월 10일 일요일 오후 11:47nsham 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨
    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();

    • 답변으로 표시됨nsham 2009년 7월 13일 월요일 오후 6:09
    •  
  • 2009년 5월 11일 월요일 오전 12:58masher2 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨코드 있음
    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
    • 답변으로 표시됨nsham 2009년 5월 11일 월요일 오전 1:13
    •  

모든 응답

  • 2009년 5월 10일 일요일 오후 9:31masher2 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨
    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
    • 답변으로 표시됨nsham 2009년 5월 10일 일요일 오후 11:24
    •  
  • 2009년 5월 10일 일요일 오후 11:00nobugzMVP, 중재자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    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.
  • 2009년 5월 10일 일요일 오후 11:30nsham 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    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
  • 2009년 5월 10일 일요일 오후 11:37masher2 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    Can you post your actual code? 
    Michael Asher
  • 2009년 5월 10일 일요일 오후 11:47nsham 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨
    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();

    • 답변으로 표시됨nsham 2009년 7월 13일 월요일 오후 6:09
    •  
  • 2009년 5월 11일 월요일 오전 12:58masher2 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨코드 있음
    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
    • 답변으로 표시됨nsham 2009년 5월 11일 월요일 오전 1:13
    •  
  • 2009년 5월 11일 월요일 오전 1:13nsham 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    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
  • 2009년 7월 2일 목요일 오후 6:38solled 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    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