您的位置:首页 > 其它

雷塞SMC304系列控制器VC6.0例程在VS2015下编译遇到的若干问题及解决办法

2017-10-13 14:45 781 查看

雷塞SMC304系列控制器VC6.0例程在VS2015下编译遇到的若干问题及解决办法

标签(空格分隔): 雷塞 SM304 WIN10 VS2015

最近由于导师要求,负责喷涂机器人的控制部分,接触到雷塞公司的控制器产品SM304,首先想着从给的例程入手,但由于例程是VC6.0的程序,而我的电脑是WIN10系统,用VC6.0起来十分的不方便,因此想到在VS2015下重新编译一遍源代码,下面是编译过程中遇到的一系列问题。

0.在VS2015中创建一个空项目,将例程中所有文件按类别导入



配置:

(1)链接器–>系统–>子系统

选择:“窗口 (/SUBSYSTEM:WINDOWS)”

参考:MFC 必须定义入口点 解决办法

如果未配置出现错误:

d:\vs2015\vc\atlmfc\include\afx.h(38): warning C4996: ‘MBCS_Support_Deprecated_In_MFC’: MBCS support in MFC is deprecated and may be removed in a future version of MFC.

1> d:\vs2015\vc\atlmfc\include\afx.h(33): note: 参见“MBCS_Support_Deprecated_In_MFC”的声明

1> _WIN32_WINNT not defined. Defaulting to _WIN32_WINNT_MAXVER (see WinSDKVer.h)

1> DMCd1DLG.cpp

1> DMCd1.cpp

1>LINK : fatal error LNK1561: 必须定义入口点

(2)配置属性–>常规–>MFC的使用

选择:“在共享DLL中使用MFC”

参考:在共享DLL中使用MFC

如果未配置出现错误:

1>d:\vs2015\vc\atlmfc\include\afx.h(24): fatal error C1189: #error: Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d]

1> DMCd1DLG.cpp

1>d:\vs2015\vc\atlmfc\include\afx.h(24): fatal error C1189: #error: Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d]

1> DMCd1.cpp

1>d:\vs2015\vc\atlmfc\include\afx.h(24): fatal error C1189: #error: Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d]

(3)配置属性–>常规–>字符集

选择:“使用多字节字符集”

参考:CWnd::MessageBoxW”: 不能将参数 1 从“const char [16]”转换为“LPCTSTR

如果未配置出现错误:

1>g:\喷涂机器人\spraying robot\spraying robot\dmcd1dlg.cpp(90): error C2664: “int CWnd::MessageBoxW(LPCTSTR,LPCTSTR,UINT)”: 无法将参数 1 从“const char [11]”转换为“LPCTSTR”



1> g:\喷涂机器人\spraying robot\spraying robot\dmcd1dlg.cpp(181): note: 与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换

(4)配置属性–>C/C++–>预编译头

选择:“创建 (/Yc)”

参考:有关无法打开预编译头文件错误的思考

如果未配置出现错误:

1>d:\vs2015\vc\atlmfc\include\afx.h(38): warning C4996: ‘MBCS_Support_Deprecated_In_MFC’: MBCS support in MFC is deprecated and may be removed in a future version of MFC.

1> d:\vs2015\vc\atlmfc\include\afx.h(33): note: 参见“MBCS_Support_Deprecated_In_MFC”的声明

1> _WIN32_WINNT not defined. Defaulting to _WIN32_WINNT_MAXVER (see WinSDKVer.h)

1.错误1:Enable3dControls问题

参考:Enable3dControls警告

1.1 错误信息

1>g:\喷涂机器人\spraying robot\spraying robot\dmcd1.cpp(53): error C4996: ‘CWinApp::Enable3dControls’: CWinApp::Enable3dControls is no longer needed. You should remove this call.

1> d:\vs2015\vc\atlmfc\include\afxwin.h(5224): note: 参见“CWinApp::Enable3dControls”的声明



1.2 解决方法

定位到代码:

#ifdef _AFXDLL
Enable3dControls();         // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic();   // Call this when linking to MFC statically
#endif


主要由于版本问题所导致的,Windows95以后就不需要再调用这两个函数了,因此使用_MSC_VER对其进行隔离即可:

#if _MSC_VER <= 1200 // MFC 6.0 or earlier
#ifdef _AFXDLL
Enable3dControls();            // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic();    // Call this when linking to MFC statically
#endif
#endif


2.错误2:外部符号无法解析

参考:vs2015引用lib库

2.1 错误信息

1> DMCd1.cpp

1>DMCd1DLG.obj : error LNK2019: 无法解析的外部符号 _smc_board_init@16,该符号在函数 “protected: virtual int __thiscall CDMCd1Dlg::OnInitDialog(void)” (?OnInitDialog@CDMCd1Dlg@@MAEHXZ) 中被引用



1>DMCd1DLG.obj : error LNK2019: 无法解析的外部符号 _smc_get_position_unit@12,该符号在函数 “protected: void __thiscall CDMCd1Dlg::OnTimer(unsigned int)” (?OnTimer@CDMCd1Dlg@@IAEXI@Z) 中被引用

1>G:\喷涂机器人\Spraying robot\Debug\Spraying robot.exe : fatal error LNK1120: 17 个无法解析的外部命令



2.2 解决方法

(1)配置属性–>C/C++–>常规–>附加包含目录

添加:你的LTSMC.lib所在目录

(2)配置属性–>链接器–>输入–>附加依赖项

添加:LTSMC.lib

(3)将对应的dll文件放到与exe同一级目录下

3.显示结果

编译后得到一个简易的控制软件界面,连接好SMC304后根据文档设置好以太网参数即可直接控制,随后便在VS2015上对程序进行进一步修改,实现自定义控制!

例程软件界面:



SMC304用户手册内容:

本例中的 SMC304 的 IP 地址为 192.168.5.11, PC 机设置的 IP 与 SMC304 的 IP 前 3 个字段要相同,第 4 个字段要不同。如图 3-8 所示, PC 机设置的 IP 设为 192.168.5.6 即可。



PS:由于雷塞公司提供的是32位库,因此编译的时候必须选择x86

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息