链接到静态库与管理组件

链接到静态库与管理组件

问题描述:

创建一个图形用户界面我个人的小应用程序后,我试图把它编译成静态库在其他项目中使用。该GUI被创建并具有穿过,目前仅具有5个功能的托管公共引用类与它执行的其他任务,但将被添加到

After creating a GUI for my personal little application, I am trying to compile it as a static library to use in another project. The GUI is created and has other tasks performed with it through a managed public ref class that currently only has 5 functions, but will be added to.

这是静态库,将被包含在其他项目中(当然,至少有一个新的,只有公共职能,所有多余的东西会被删除),我的头文件;

This is my header file in the static library that would be included in the other project (well, at least a new one with only the public functions, all the extra stuff would be removed);


#ifndef GUIInterface_H
#define GUIInterface_H
#include 
#include "MainForm.h"

using namespace System;
using namespace System::Threading;

 public ref class GUIInterface
{
private:
    ThreadStart^ GUIThreadDelegate;
    Thread^ GUIThread;
    void GUIThreadFunction()
    {
        ANNGUI::Application::EnableVisualStyles();
        ANNGUI::Application::Run(gcnew ANNGUI::MainForm());
        return;
    }

public:
    int CreateGUI();

    int DestroyGUI();

    int GetInputData();

    bool CheckNewInput();

    int NetworkState();
};
#endif

这是如何会从其他项目中访问文件(.exe)

This is how it would be accessed from the other project (.exe)


#include "main.h"

int main()
{
    GUIInterface ^GUI = gcnew(GUIInterface);
    GUI->CreateGUI();
    return 0;
}

在main.h只包含上面所示的头文件,减去私人的东西的类定义。

The main.h just contains the class definitions like the header file shown above, minus the private stuff.

我使用的Visual Studio 2010的前preSS C ++。这两个项目都使用/ clr开关编译。静态库被设定为在.exe项目的参考。当我编译静态库作为一个DLL代替,该方案完美地运行(之后我删除了main.h中的应用程序)。当它被编译成静态库,我得到一个LNK2020错误为每个使用的图形用户界面进行通信的功能。

I am using Visual Studio 2010 Express C++. Both projects are compiled with /clr switch. The static library is set as a reference in the .exe project. When I compile the static library as a DLL instead, the program runs perfectly (after I remove the main.h in the application). When it is compiled as a static library I get a LNK2020 Error for each of the functions used to communicate with the GUI.

我联系的。exe使用/ verbose选项来查看输出。链接程序会确切位置的.lib是多次,但从来没有说,它发现它,即使它看起来正好在正确的道路,并为正确的文件。此外,如果这意味着什么,我的.lib建立正常,但得到以此为戒。

I linked the .exe with the /VERBOSE option to see the output. The linker looks exactly where the .lib is multiple times, but never says it found it even though it's looking EXACTLY in the right path and for the right file. Also, if it means anything, my .lib builds fine but gets this as a warning.

.NETFramework,Version=v4.0.AssemblyAttributes.obj : warning LNK4221: This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library

我的问题是,为什么链接器在寻找合适的地方为.LIB,但没有看到它的权利在它的面前?我该如何去修复,这样我可以用我的静态的.lib?

My question is, why is the linker looking in the right place for the .lib, but not seeing it right in front of it's face? How can I go about fixing this so that I can use my static .lib?

一个静态的.lib不是管理code有效的目标选项。有没有实现的机制来获取与管理的类型相同的待遇为code有关的所有重要的元数据。它不能被刻在比特块,并再次粘在一起。该MSFT团队可能认为它,但得到吓跑了所需要的obj文件格式的巨大变化。这是一个猜测。一个好的错误信息本来不错。这是一个事实。

A static .lib is not a valid target option for managed code. There is no implemented mechanism to get the all-important metadata associated with managed types the same kind of treatment as code. It cannot be carved up in bits in pieces and glued together again. The MSFT team probably considered it but got scared away by the massive changes required to the .obj file format. That's a guess. A good error message would have been nice. That's a fact.

您必须选择一个DLL作为目标。在运行时,JIT编译器执行相同的功能的连接器,它只吸入code从实际上是由客户端使用该DLL装配

You must select a DLL as the target. At runtime, the JIT compiler performs the same function as the linker, it only pulls code from the DLL assembly that is actually used by the client.