gpt4 book ai didi

c++ - 尝试将 C++ 项目转换为与 CLR 兼容的静态库

转载 作者:太空宇宙 更新时间:2023-11-04 14:13:38 24 4
gpt4 key购买 nike

因此,我成功地使用/clr 标志将我正在开发的项目编译为 .lib。我现在努力做的是为它创建一个 CLR 类库包装器,以允许我将它与 .NET 一起使用。

当我尝试编译我的 CLR 类库时出现以下错误:

Renderer.obj : error LNK2028: unresolved token (0A000017) "public: __thiscall cMain::cMain(void)" (??0cMain@@$$FQAE@XZ) referenced in function "private: void __clrcall Renderer::GraphicsBox::NewGraphicsBox(int,int,int,int)" (?NewGraphicsBox@GraphicsBox@Renderer@@$$FA$AAMXHHHH@Z)

Renderer.obj : error LNK2019: unresolved external symbol "public: __thiscall cMain::cMain(void)" (??0cMain@@$$FQAE@XZ) referenced in function "private: void __clrcall Renderer::GraphicsBox::NewGraphicsBox(int,int,int,int)" (?NewGraphicsBox@GraphicsBox@Renderer@@$$FA$AAMXHHHH@Z)

我已将相关条目添加到 include 目录,以及相关条目到 lib 目录。

代码如下所示:

stdafx.h

#pragma once

#include "cMain.h"

渲染器.h

#pragma once

#include "Stdafx.h"



using namespace System;

namespace Renderer {

public ref class GraphicsBox
{
GraphicsBox();
~GraphicsBox();

void NewGraphicsBox(System::Int32 scrw, System::Int32 scrh, System::Int32 posx, System::Int32 posy);
// TODO: Add your methods for this class here.
};
}

渲染器.cpp

#include "stdafx.h"

#include "Renderer.h"

pragma comment(lib "DX11test.lib")

using namespace Renderer;

GraphicsBox::GraphicsBox()
{

}

GraphicsBox::~GraphicsBox()
{

}

void GraphicsBox::NewGraphicsBox(System::Int32 scrw, System::Int32 scrh, System::Int32 posx, System::Int32 posy)
{
cMain *base;

bool result;

base = new cMain;
if (!base)
{
throw runtime_error("Failed at base = cMain");
}
}

我要引用的类:

cMain.h

#ifndef _CMAIN_H_
#define _CMAIN_H_

#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <vector>
#include <map>
#include <string>

#include "InputHandler.h"
#include "cGraphics.h"
#include "cVehicleObject.h"
#include "cVehicleModel.h"
#include "cTerrainModel.h"
#include "cLight.h"

using namespace std;

public class cMain
{
public:
cMain();
cMain(const cMain& other);
~cMain();

bool Initialize(int scrWidth, int scrHeight);
void Shutdown();
void Run();

LRESULT CALLBACK MessageHandler(HWND hwnd, UINT umessage, WPARAM wparam, LPARAM lparam);
private:
bool Frame();
void InitializeWindows(int& scrw, int& scrh);
void CreateNewWindow(int& scrw, int& scrh, int posx, int posy);
void ShutdownWindows();

void ErrorDump(vector<string> errors, string filename);
void ErrorDump(string error, string filename);

bool SetUpLights();
bool SetUpObjects();

LPCWSTR m_applicationName;
HINSTANCE m_hinstance;
HWND m_hwnd;

InputHandler* m_input;
cGraphics* m_graphics;

cObject::GameObjects m_gameObjects;

vector<cLight> m_lights;
};

static LRESULT CALLBACK WndProc(HWND hwnd, UINT umessage, WPARAM wparam, LPARAM lparam);
static cMain* ApplicationHandle = 0;

#endif

我的直觉告诉我,这与我尝试设置为库的项目中 Windows API 的使用有关,但我没有经验将它们联系在一起,所以老实说我不知道​​。

我想把整个东西转换成完全 CLR 友好的,我不想不遗余力。感谢您的帮助

最佳答案

链接器错误与程序的包含路径无关,与函数的实现有关。在您发布的示例中,我没有看到 cMain.cpp,所以您可能忘记实现它或者您只是忘记实现 cMain::cMain()

关于c++ - 尝试将 C++ 项目转换为与 CLR 兼容的静态库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12942553/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com