I have been working on getting a basic ATL project to compile in Visual Studio 2008 and I keep running into errors. Ultimately I have gotten stuck with the following build errors:
1>Linking...
1> Creating library Debug\SomeProject.lib and object Debug\SomeProject.exp
1>dllmain.obj : error LNK2001: unresolved external symbol _LIBID_SomeProjectLib
1>SomeObject.obj : error LNK2001: unresolved external symbol _LIBID_SomeProjectLib
1>SomeObject.obj : error LNK2001: unresolved external symbol _IID_ISomeObject
1>Debug\SomeProject.dll : fatal error LNK1120: 2 unresolved externals
What am I overlooking or doing wrong? Here are the steps to reproduce.
- Create a new
ATL ProjectnamedSomeProject. Accept all defaults. - Right-click the project in the Solution Explorer and select
Add > Class. - Select
ATL Simple Objectand enterSomeObjectas its Short Name. Accept all other defaults.
At this points the project builds fine. However I want to split my IDL among multiple files for better organization (my IDL would be thousands of lines long).
- Right-click the project and select
Add > New Item. - Select
Midl Fileand enterISomeObjectas its filename. - Open
SomeProject.idland cut theISomeObjectinterface declaration. Replace it withimport "ISomeObject.idl";. - Paste the interface declaration in
ISomeObject.idl.
In order to satisfy Microsoft's IDL compiler we need to change some options:
- Right-click the project and open its Properties. Go to the
MIDL > Outputsection and enter the following values:- Header File:
$(InputName).h - IID File:
$(InputName)_i.cpp - Proxy File:
$(InputName)_p.cpp - Generate Type Library:
No
- Header File:
- Go to the
C/C++ > Precompiled Headerssection and setCreate/Use Precompiled HeadertoNot using Precompiled Header. There are errors later if precompiled headers are used. - Select the
SomeProject.idlfile so that its properties are displayed. Go to theMIDL > Outputsection and setGenerate Type LibrarytoYes. - Remove
SomeProject_i.handSomeProject_i.cfrom theGenerated Filesfilter. - Add the following Existing Items to the
Generated Filesfilter. You may need to attempt to compile the project first.SomeProject.hSomeProject_i.cppISomeObject.hISomeObject_i.cpp
Now, at this point I would expect the project to compile. But it doesn't. You should get the LNK1120 errors that I listed at the top of this question.
Any ideas? Am I overlooking something simple?