1

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.

  1. Create a new ATL Project named SomeProject. Accept all defaults.
  2. Right-click the project in the Solution Explorer and select Add > Class.
  3. Select ATL Simple Object and enter SomeObject as 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).

  1. Right-click the project and select Add > New Item.
  2. Select Midl File and enter ISomeObject as its filename.
  3. Open SomeProject.idl and cut the ISomeObject interface declaration. Replace it with import "ISomeObject.idl";.
  4. Paste the interface declaration in ISomeObject.idl.

In order to satisfy Microsoft's IDL compiler we need to change some options:

  1. Right-click the project and open its Properties. Go to the MIDL > Output section and enter the following values:
    • Header File: $(InputName).h
    • IID File: $(InputName)_i.cpp
    • Proxy File: $(InputName)_p.cpp
    • Generate Type Library: No
  2. Go to the C/C++ > Precompiled Headers section and set Create/Use Precompiled Header to Not using Precompiled Header. There are errors later if precompiled headers are used.
  3. Select the SomeProject.idl file so that its properties are displayed. Go to the MIDL > Output section and set Generate Type Library to Yes.
  4. Remove SomeProject_i.h and SomeProject_i.c from the Generated Files filter.
  5. Add the following Existing Items to the Generated Files filter. You may need to attempt to compile the project first.
    • SomeProject.h
    • SomeProject_i.cpp
    • ISomeObject.h
    • ISomeObject_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?

4

2 回答 2

1

打开 VS 2008 命令提示符并转到中间/输出目录并查看 someproject_i.obj。尝试这样的事情:

dumpbin someproject_i.obj /symbols | find "LIBID"

如果目标文件中没有定义 libid,那就是问题所在。也许它有错误的名字?如果有一个名称正确,那么问题是链接器没有使用它。

于 2010-07-27T18:52:49.293 回答
1

不知道你在做什么,或者你为什么这样做,但是在某个地方你丢失了 midl.exe 生成的 blah_i.c 源代码文件。它包含接口、coclasses 和类型库的 GUID,链接器抱怨的那些。如果找不到,请在 *.c 文件中搜索 MIDL_DEFINE_GUID。

编辑:我现在看到了问题,您将 blah_i.c 重命名为 blah_i.cpp。错了,该文件包含 C 声明。当编译为 C++ 代码时,编译器会以不同的方式处理标识符。将其重命名为 .c。或者使用 /Tc 编译选项。

于 2010-07-27T18:54:50.413 回答