visual studio 2010 - c++错误LNK2028, LNK2019和LNK1120.它们是什么意思,我
visual studio 2010 - C++ errors LNK2028, LNK2019 and LNK1120. What do they mean and how do I solve them?
我得到了这三个错误,它们似乎对我没有什么意义。如果我注释UserInstruction1(P1, P2, P3);在控制台应用程序中,错误消失了。两个项目都是/CLR项目
error LNK2028: unresolved token (0A000930) "void __cdecl UserInstruction1(double *,wchar_t *,wchar_t *)" (?UserInstruction1@@$$FYAXPANPA_W1@Z) referenced in function "int __cdecl wmain(int,wchar_t * * const)" (?wmain@@$$HYAHHQAPA_W@Z)
error LNK2019: unresolved external symbol "void __cdecl UserInstruction1(double *,wchar_t *,wchar_t *)" (?UserInstruction1@@$$FYAXPANPA_W1@Z) referenced in function "int __cdecl wmain(int,wchar_t * * const)" (?wmain@@$$HYAHHQAPA_W@Z)
error LNK1120: 2 unresolved externals C:WorkspaceCompany.PinsBankSourceDebugCompany.Pins.Bank.Win32Console.exe
//Console App.
#include "stdafx.h"
#include "UInstruction.h"
int _tmain(int argc, _TCHAR* argv[])
{
auto P2 = (TCHAR *)"3 Barrowstead";
TCHAR* P3;
double* P1;
P1[0] = 13;
UserInstruction1(P1, P2, P3);
return 0;
}
,
//UInstruction.h
#ifndef __UINSTRUCTION_H__
#include "stdafx.h"
#include "UInstruction.h"
#include "common.h"
#include <iostream>
#include <stdio.h>
#define PRES_NOCOMMAND_FOUND 2000
#define DllExport __declspec(dllexport)
void ReconcileUHParameter(const double* lpNumeric, TCHAR* lpAlpha1, TCHAR* lpAlpha2);
extern void UserInstruction1(double* lpNumeric, TCHAR* lpAlpha1, TCHAR* lpAlpha2);
#endif
,
//UInstruction.cpp
#include "stdafx.h"
#include "UInstruction.h"
#include "common.h"
#using "Company.Pins.Bank.Decryption.dll"
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace System;
using namespace System::Runtime::InteropServices;
CPReSInterfaceApp theApp;
extern void UserInstruction1(
double* lpNumeric,
TCHAR* lpAlpha1, TCHAR* lpAlpha2)
{
//logic goes here
}
我假设这里所有的代码都驻留在一个项目(Company.Pins.Bank.Win32Console)中。如果是这样,您应该将<iostream>和<stdio.h> include(以及从不/很少更改的头文件的任何其他include)移动到stdafx.h:
//stdafx.h
#include <iostream>
#include <stdio.h>
//other headers that are widely used but never/seldom change...
#define DllExport __declspec(dllexport)
#define DllImport __declspec(dllimport)
和
//UInstruction.h
#pragma once //you are in VS 2010...
#include "common.h"
//ommited code for brevity...
void UserInstruction1(double* lpNumeric, TCHAR* lpAlpha1, TCHAR* lpAlpha2);
和
//UInstruction.cpp
#include "stdafx.h"
#include "UInstruction.h"
//ommitted code for brevity...
void UserInstruction1( double* lpNumeric,
TCHAR* lpAlpha1, TCHAR* lpAlpha2 )
{
//logic goes here
}
如果UserInstruction1驻留在Company.Pins.Bank使用的Dll中。Win32Console项目:
确保在stdafx.h中为dll和控制台项目定义:
#define DllExport __declspec(dllexport)
#define DllImport __declspec(dllimport)
打开DLL项目的属性,转到"配置属性"->"C/c++"->"预处理器",并在"预处理器定义"中添加预处理器符号(如果没有的话)。也就是说,我把它命名为MY_DLL。别忘了在所有配置中定义它…
确保从Dll中导出函数
//UInstruction.h
#pragma once //you are in VS 2010...
#ifdef MY_DLL
#define MY_DLL_EXPORTS DllExport
#else
#define MY_DLL_EXPORTS DllImport
#endif //MY_DLL
#include "common.h"
#define PRES_NOCOMMAND_FOUND 2000
//ommited code for brevity...
void MY_DLL_EXPORTS UserInstruction1(double* lpNumeric, TCHAR* lpAlpha1, TCHAR* lpAlpha2);
UInstruction的cpp文件和上面的一样…
编辑:为了完整…
//UInstruction.cpp
#include "stdafx.h"
#include "UInstruction.h"
//ommitted code for brevity...
//no extern needed...
void UserInstruction1( double* lpNumeric,
TCHAR* lpAlpha1, TCHAR* lpAlpha2 )
{
//logic goes here
}
不要忘记在Company.Pins.Bank中添加对Dll项目的引用。Win32Console项目从Company.Pins.Bank的属性。Win32Console "Common Properties" -> "Framework and References"
您正在尝试在使用/clr选项编译的项目中使用函数。托管代码。从没有/clr选项编译的控制台应用程序项目。本机代码。您正在获得链接器错误,因为它正在寻找__cdecl函数,它实际上被编译为__clrcall函数。
这只是链接器问题,还有一个运行时问题,因为你的控制台应用程序没有加载和初始化CLR,准备执行托管代码。您需要考虑如何与托管代码进行互操作。最明显的解决方案是让你的主机应用也成为托管应用。或者使您的DLL成为非托管的DLL,您不会明显使用。net框架。或者你可以通过在本地应用程序中托管CLR (google CorBindToRuntimeEx())或将DLL转换为COM服务器来复杂化你的生活。
- 为不同配置设置MSVC_RUNTIME_LIBRARY的正确方法是什么
- C++避免重复声明的语法是什么
- 在C++中,将大的无符号浮点数四舍五入为整数的最佳方法是什么
- 实现无开销push_back的最佳方法是什么
- C++从另一个类访问公共静态向量的正确方法是什么
- "throw expression code" 1e7 >返回 d 是什么?投掷标准::overflow_error( "too big" ) : d;意味 着?
- C++中名称篡改的目的是什么
- 在 c++ 中拥有一组结构的正确方法是什么?
- 这个指针和内存代码打印是什么?我不知道是打印垃圾还是如何打印我需要的值
- 是什么阻止DOMTimerCoordinator::NextID进入无休止的循环
- 派生类销毁的最佳实践是什么
- 这个语法std::class<>{}(arg1, arg2) 在C++中是什么意思?
- 通过JNI传递数据数组的最快方法是什么
- "using namespace std;"在C++的作用是什么?
- 在两台机器之间进行时间戳的最佳c++chrono函数是什么
- 文件系统:复制功能的速度秘诀是什么
- 用常见虚拟函数实现的任意组合来实现派生类的正确方法是什么
- 使用QQuickFramebufferObject时同步数据的最佳方式是什么
- 是什么原因导致它无法编译?它是声明签名还是在函数本身的实现中
- visual studio 2010 - c++错误LNK2028, LNK2019和LNK1120.它们是什么意思,我