即使正确完成了 Visual Studio 项目的设置,也出现未解决的外部符号错误
简而言之,
我尝试使用现有的 C++ 库。 问题是它没有编译。 我获取了 src 代码(一个 Visual Studio 项目)并尝试编译它。 问题是我无法将我的项目链接到库。
更具体的细节是:
我已经完成的操作如下:
- 我打开了 .sln 文件并添加了另一个名为“Sampler”的子项目
- 我下载了库 src 代码依赖的所有 Microsoft 附加包。
- 我将该库编译到 Windows 32 平台 x86(使用 Visual Studio 2022)。编译成功。
- 我在
.sln
文件的同一目录中创建了一个目录Dependencies\OPCClientToolKit
,Dependencies\OPCClientToolKit
包含两个目录include
和lib
。 - 我将
.lib
放入Dependencies\OPCClientToolKit\lib
- 编译后的输出。 - 我将sdk库的src代码的
.h
文件放入Dependency\OPCClientToolKit\include
中。 - 我通过 Sampler Project > 添加了依赖
.h
文件属性> C++ 通用。请参阅下面的图片。 - 我通过 Sampler Project > 添加了一个依赖文件夹
Dependencies\OPCClientToolKit\lib
属性>链接器将军。请参阅下面的图片。 - 我通过 Sampler Project > 添加了依赖项
OPCClientToolKit.lib
属性>链接器输入。请参阅下面的图片。
据我所知,我的所有步骤似乎都是有效且良好的。
但是,当我编译(通过 Visual Studio 点击“构建”)Sampler 项目代码(请参阅下面的代码)时,我收到一条错误消息:
错误消息:
1>------ Build started: Project: Sampler, Configuration: Release Win32 ------
1>Sampler.cpp
1>Sampler.obj : error LNK2001: unresolved external symbol "public: static class COPCHost * __cdecl COPCClient::makeHost(class ATL::CStringT<wchar_t,class ATL::StrTraitATL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > const &)" (?makeHost@COPCClient@@SAPAVCOPCHost@@ABV?$CStringT@_WV?$StrTraitATL@_WV?$ChTraitsCRT@_W@ATL@@@ATL@@@ATL@@@Z)
1>C:\Users\Mark\Desktop\Projects\PID\OPC_DA\Release\Sampler.exe : fatal error LNK1120: 1 unresolved externals
1>Done building project "Sampler.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
请向我解释应该如何解决此问题。我只想包含并使用这个库,而不是修改它。
Dependecies\OPCClientToolKit\lib
Dependecies\OPCClientToolKit\include
采样器项目>属性> C++>一般
采样器项目>属性>链接器>一般
采样器项目>属性>链接器>输入
我正在使用这个库(OPC客户端sdk):
https://sourceforge.net/projects/opcclient/
互联网上其他人制作的使用示例:
https://github.com/Tibalt/OPC_DA/blob/master/OPCClientDemo/OPCClientDemo.cpp
我的代码只使用该库的函数和对象。
详细来说,只是尝试初始化与本地主机上的服务器的 opc 连接:
#include <iostream>
#include <vector>
#include <string>
#include <stdio.h>
#include <sys\timeb.h>
#include "opcda.h"
#include "OPCClient.h"
#include "OPCHost.h"
#include "OPCServer.h"
#include "OPCGroup.h"
#include "OPCItem.h"
using namespace std;
int main(void) {
COPCClient::init();
cout << "Done Init";
cout << endl;
CString hostName = "localhost";
COPCHost* host = COPCClient::makeHost(hostName);
}
In a nutshell
I am tring to use an existing C++ library.
The problem is that it's not compiled.
I took the src code (a visual studio project) and tried to compile it.
The thing is that I can't link my project to the library.
More specific details are:
What I have already done is the following:
- I opened the
.sln
file and added another sub-project called "Sampler" - I downloaded all Microsoft additional packages that the library src code depends on.
- I compiled the library to Windows 32 platform x86 (using Visual Studio 2022). The compilation was successful.
- I created a directory
Dependencies\OPCClientToolKit
in same directory of.sln
file,Dependencies\OPCClientToolKit
contains two directoriesinclude
andlib
. - I put in
Dependencies\OPCClientToolKit\lib
the.lib
- the output after compilation. - I put in
Dependencies\OPCClientToolKit\include
the.h
files of the src code of sdk library. - I added a dependency
.h
files via Sampler Project > Properies > C++ General. See pictures below. - I added a dependency folder
Dependencies\OPCClientToolKit\lib
via Sampler Project > Properies > Linker General. See pictures below. - I added a dependency
OPCClientToolKit.lib
via Sampler Project > Properies > Linker Input. See pictures below.
As far as I know all my step seems valid and fine.
But when, I am compiling (hitting Build via Visual Studio) the Sampler project code (see the code below) I am getting an error message:
Error Message:
1>------ Build started: Project: Sampler, Configuration: Release Win32 ------
1>Sampler.cpp
1>Sampler.obj : error LNK2001: unresolved external symbol "public: static class COPCHost * __cdecl COPCClient::makeHost(class ATL::CStringT<wchar_t,class ATL::StrTraitATL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > const &)" (?makeHost@COPCClient@@SAPAVCOPCHost@@ABV?$CStringT@_WV?$StrTraitATL@_WV?$ChTraitsCRT@_W@ATL@@@ATL@@@ATL@@@Z)
1>C:\Users\Mark\Desktop\Projects\PID\OPC_DA\Release\Sampler.exe : fatal error LNK1120: 1 unresolved externals
1>Done building project "Sampler.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Please explain to me how should I resolve this issue. I just want to include and use this library and not to modify it.
Dependecies\OPCClientToolKit\lib
Dependecies\OPCClientToolKit\include
Sampler Project > Properties > C++ > General
Sampler Project > Properties > Linker > General
Sampler Project > Properties > Linker > Input
I am using this library (OPC client sdk):
https://sourceforge.net/projects/opcclient/
A usage example made by other guy on the internet:
https://github.com/Tibalt/OPC_DA/blob/master/OPCClientDemo/OPCClientDemo.cpp
My code just use functions and objects of that library.
In details, just trying to initialize opc connection to a server on localhost:
#include <iostream>
#include <vector>
#include <string>
#include <stdio.h>
#include <sys\timeb.h>
#include "opcda.h"
#include "OPCClient.h"
#include "OPCHost.h"
#include "OPCServer.h"
#include "OPCGroup.h"
#include "OPCItem.h"
using namespace std;
int main(void) {
COPCClient::init();
cout << "Done Init";
cout << endl;
CString hostName = "localhost";
COPCHost* host = COPCClient::makeHost(hostName);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该项目 OPCClientToolKit 非常古老。它看起来像是使用 ANSI 字符集构建的,没有使用宏
_UNICODE
。您应该_UNICODE
。_UNICODE
添加到该项目。_UNICODE
重建静态库OPCClientToolKit.lib。That project OPCClientToolKit is very old. It looks like built with using ANSI character set, without using the macro
_UNICODE
. You should either_UNICODE
from the preprocessor settings in your project._UNICODE
to that project._UNICODE
.