User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,493 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,677 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 15879 | Replies: 5
Reply
Join Date: Apr 2004
Location: Dhaka, Bangladesh
Posts: 344
Reputation: Asif_NSU is on a distinguished road 
Rep Power: 5
Solved Threads: 3
Asif_NSU's Avatar
Asif_NSU Asif_NSU is offline Offline
Posting Whiz

Using MFC in a Static Library

  #1  
Aug 8th, 2004
guys, i have been working on a project, i have been trying to use dxsmithlib (a directx wrapper from codeproject) and win32 CONSOLE application in visual c++ 6. When i try to build the project by specifying "use MFC in a shared DLL"
it shows no errors or warnings and works fine. But in case of "use MFC in a static library" i get the following errors:
Linking...  msvcrtd.lib(MSVCRTD.dll) : error LNK2005: _sprintf already defined in libcmtd.lib(sprintf.obj)  
msvcrtd.lib(MSVCRTD.dll) : error LNK2005: _atol already defined in libcmtd.lib(atox.obj) 
msvcrtd.lib(MSVCRTD.dll) : error LNK2005: _strncpy already defined in libcmtd.lib(strncpy.obj)  
msvcrtd.lib(MSVCRTD.dll) : error LNK2005: _fclose already defined in libcmtd.lib(fclose.obj)  
msvcrtd.lib(MSVCRTD.dll) : error LNK2005: __vsnprintf already defined in libcmtd.lib(vsnprint.obj)  
msvcrtd.lib(MSVCRTD.dll) : error LNK2005: __strcmpi already defined in libcmtd.lib(stricmp.obj)  
msvcrtd.lib(MSVCRTD.dll) : error LNK2005: __stricmp already defined in libcmtd.lib(stricmp.obj)  
LINK : warning LNK4098: defaultlib "mfc42d.lib" conflicts with use of other libs; use /NODEFAULTLIB:library  
LINK : warning LNK4098: defaultlib "mfcs42d.lib" conflicts with use of other libs; use /NODEFAULTLIB:library  
LINK : warning LNK4098: defaultlib "msvcrtd.lib" conflicts with use of other libs; use /NODEFAULTLIB:library  
Debug/Asteroid.exe : fatal error LNK1169: one or more multiply defined symbols found  Error executing link.exe.


can anyone help me remedy the problem?

The file runs okay on win 98 SE -- the platform i have been using to develop the project. But gives the following error on winXP:
"cannot find mfc42d.dll". Actually i was suggested by someone to use MFC in a static library in the project settings so that it also runs on XP...

And also another problem is that if i execute it from visual C++ the program runs smoothly but when i run the exe file outside VC++(the way user will use it) the program doesnt run smoothly-it somewhat stucks at every key i press on my keyboard. i need some help here guys... :-|
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2004
Location: Dhaka, Bangladesh
Posts: 344
Reputation: Asif_NSU is on a distinguished road 
Rep Power: 5
Solved Threads: 3
Asif_NSU's Avatar
Asif_NSU Asif_NSU is offline Offline
Posting Whiz

Re: Using MFC in a Static Library

  #2  
Aug 9th, 2004
when I try to build the release version of the project i get the same errors. the debug version is error free though.



--Asif_NSU
Reply With Quote  
Join Date: Apr 2004
Posts: 3,755
Reputation: Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light 
Rep Power: 17
Solved Threads: 147
Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Using MFC in a Static Library

  #3  
Aug 9th, 2004
Here and here it mentions something like this:
Check your project settings under 'C++|Code generation'. That should read "Multithreaded DLL"
Other possibilities.
Reply With Quote  
Join Date: Jun 2004
Location: Marin, CA, USA
Posts: 434
Reputation: Chainsaw is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 10
Chainsaw's Avatar
Chainsaw Chainsaw is offline Offline
Unprevaricator

Re: Using MFC in a Static Library

  #4  
Aug 9th, 2004
All the code needs to be compiled the same way. Rebuild all the code (build ALL); if the directx library code was built the other way you'll have to rebuild it too. If they didn't supply the code, they should have supplied various versions of the lib you can link with. Make sure you are linking with the right one.
Reply With Quote  
Join Date: Apr 2004
Location: Dhaka, Bangladesh
Posts: 344
Reputation: Asif_NSU is on a distinguished road 
Rep Power: 5
Solved Threads: 3
Asif_NSU's Avatar
Asif_NSU Asif_NSU is offline Offline
Posting Whiz

Re: Using MFC in a Static Library

  #5  
Aug 11th, 2004
I had to stick to shared dll, but i successfully built the release version.
The staic library seems to give the same errors though. However i happened to work away with that.

Thanx for ur help.
I m quite new to vc++;
Can anyone explain what MFC in shared dll and static library means, what r the differences and when should i use what?
Reply With Quote  
Join Date: Jun 2004
Location: Marin, CA, USA
Posts: 434
Reputation: Chainsaw is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 10
Chainsaw's Avatar
Chainsaw Chainsaw is offline Offline
Unprevaricator

Re: Using MFC in a Static Library

  #6  
Aug 12th, 2004
The static library is where the MFC code has been compiled into a LIB file and the linker includes the actual MFC compiled code into your program (as if you had compiled the source).

The shared DLL is where the MFC code has been built as a standalone DLL and the linker of your program uses a LIB that has references to the DLL, so that your program will load the MFC DLL at runtime and use it.

The DLL means your program has less stuff in it and so is smaller on disk.

The static lib makes your code larger, but it loads just a tad faster (probably insignificantly so). On the other hand, it takes a moment longer to link.

If your project is large enough to be broken up into DLLs then the MFC DLL is generally better because you need only one copy of the MFC code rather than lots of copies.

On the other hand if you are going to give your program to someone else to run, the static binding means you don't have to give them the DLL, or worry about what VERSION of the dll they have.


For most small sample programs, it really doesn't matter.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 3:21 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC