Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem Compiling MFC in a Static Library 1

Status
Not open for further replies.

Bones3

Programmer
Jul 27, 2003
151
US
I am trying to compile a console application so that it will work on more than just my computer. When it is compiled using MFC in a shared DLL, it compiles and runs without errors. But when I switch it to use MFC in a static library I get two errors: 1 - error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in libcpmt.lib(newop.obj) and 2 - error LNK1169: one or more multiply defined symbols found. Where are these things comeing from when I switch to use MFC in a static library? And how do I fix it?



-Bones
 
Hi Bones,

For problems like this make sure to post your environment specifications [wink]

I am unable to reproduce the problem using VC6/SP5 Latest Platform SDK on Windows 2000

NOTE: You did a "Rebuild All" after changing the project settings right?

-pete
 
I am using Visual C++ .net 2003 on Windows XP.

-Bones
 
VS.NET 2002, Latest Platform SDK, Windows 2000 Pro.

Tried both DEBUG and RELEASE builds.

Unable to reproduce the problem

Surely you must have changed some of the default project settings. Here are my C++ and Linker command line settings.
Code:
/O2 /Ob1 /Oy /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /GF /FD /EHsc /MT /GS /Gy /Yu"stdafx.h" /Fp"Release/MfcCon.pch" /Fo"Release/" /Fd"Release/vc70.pdb" /W3 /nologo /c /Wp64 /Zi /TP
Code:
/OUT:"Release/MfcCon.exe" /INCREMENTAL:NO /NOLOGO /DEBUG /PDB:"Release/MfcCon.pdb" /SUBSYSTEM:CONSOLE /OPT:REF /OPT:ICF /MACHINE:IX86

-pete
 
Here are mine:

/OUT:"Release/Computer Beep.exe" /INCREMENTAL:NO /NOLOGO /DELAYLOAD:"OleAcc.dll" /DEBUG /PDB:"Release/Computer Beep.pdb" /SUBSYSTEM:CONSOLE /OPT:REF /OPT:ICF /MACHINE:X86 DelayImp.lib DelayImp.lib

and

/D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FD /EHsc /MT /GS /Fo"Release/" /Fd"Release/vc70.pdb" /W3 /nologo /c /Wp64 /Zi /TP

I noticed that in the link command line, it adds the "DelayImp.lib DelayImp.lib" after building with the new settings. Is this normal? I also can't find how to add /O2 /Ob1 /Oy to the front of the C++ command line. Are they important?

-Bones
 
ok, I acctually got it to link by putting the runtime library setting at multi threaded. I still have the problem of it working on a second computer however. When trying to run it on another computer, the error says it is missing a dll. Do I have to export the program with the the dlls it uses, and if so how do I do that?

-Bones
 
>> Do I have to export the program with the the dlls it uses

I don’t know what you mean by export. Certainly if your program uses a DLL it must be present on the machine it runs on. There is no magic way obtain dependent DLL’s.

Which DLL is missing? Is this other computer the same OS and Service Pack version as the first one? Not all DLL’s are universally available across different versions of Windows.


-pete
 
The missing dlls are:

mscoree.dll,
MSVCr71.DLL, and
msvcr71d.dll.

Sorry, I don't know very much about how dlls work yet. :( I guess I was wondering if there was a way to compile the program so it included the information in the dlls or if you can make a type of installer that makes sure if there are no missing dlls and if there are install them. It just seems like if a user is missing the dlls for a program he should'nt have to figure out how to obtain them. I guess I was kindof nervous about the future: what would I do if I made a cool program and wanted to make it available on the internet?

The program was made on XP sp1 with visual C++ .net and sent to a computer with 2000 sp3.

-Bones
 
Mscoree is part of the .NET runtime system. If your application uses the .NET system the computer will need the entire system installed. You are not required to depend on the .NET runtime for all VC++ type projects. Your specific project must be a Managed project, therefore the dependency to .NET.

The other two DLLs are C runtime system files. I believe the one with the D on the end should be a debug version that you should not need to support when you do a release build.

There are installation project types in the Visual Studio project type list. I recommend starting with the Wizard setup type project to get started.



-pete
 
Thanks for the help pablano! And yes I believe that that partucular application was set on debug come to think of it. Woops, o well.

-Bones
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top