雷塞SMC304系列控制器VC6.0例程在VS2015下编译遇到的若干问题及解决办法
雷塞SMC304系列控制器VC6.0例程在VS2015下編譯遇到的若干問題及解決辦法
標(biāo)簽(空格分隔): 雷塞 SM304 WIN10 VS2015
最近由于導(dǎo)師要求,負(fù)責(zé)噴涂機(jī)器人的控制部分,接觸到雷塞公司的控制器產(chǎn)品SM304,首先想著從給的例程入手,但由于例程是VC6.0的程序,而我的電腦是WIN10系統(tǒng),用VC6.0起來(lái)十分的不方便,因此想到在VS2015下重新編譯一遍源代碼,下面是編譯過程中遇到的一系列問題。
0.在VS2015中創(chuàng)建一個(gè)空項(xiàng)目,將例程中所有文件按類別導(dǎo)入
配置:
(1)鏈接器–>系統(tǒng)–>子系統(tǒng)
選擇:“窗口 (/SUBSYSTEM:WINDOWS)”
參考:MFC 必須定義入口點(diǎn) 解決辦法
如果未配置出現(xiàn)錯(cuò)誤:
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: 必須定義入口點(diǎn)
(2)配置屬性–>常規(guī)–>MFC的使用
選擇:“在共享DLL中使用MFC”
參考:在共享DLL中使用MFC
如果未配置出現(xiàn)錯(cuò)誤:
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)配置屬性–>常規(guī)–>字符集
選擇:“使用多字節(jié)字符集”
參考:CWnd::MessageBoxW”: 不能將參數(shù) 1 從“const char [16]”轉(zhuǎn)換為“LPCTSTR
如果未配置出現(xiàn)錯(cuò)誤:
1>g:\噴涂機(jī)器人\spraying robot\spraying robot\dmcd1dlg.cpp(90): error C2664: “int CWnd::MessageBoxW(LPCTSTR,LPCTSTR,UINT)”: 無(wú)法將參數(shù) 1 從“const char [11]”轉(zhuǎn)換為“LPCTSTR”
…
1> g:\噴涂機(jī)器人\spraying robot\spraying robot\dmcd1dlg.cpp(181): note: 與指向的類型無(wú)關(guān);轉(zhuǎn)換要求 reinterpret_cast、C 樣式轉(zhuǎn)換或函數(shù)樣式轉(zhuǎn)換
(4)配置屬性–>C/C++–>預(yù)編譯頭
選擇:“創(chuàng)建 (/Yc)”
參考:有關(guān)無(wú)法打開預(yù)編譯頭文件錯(cuò)誤的思考
如果未配置出現(xiàn)錯(cuò)誤:
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.錯(cuò)誤1:Enable3dControls問題
參考:Enable3dControls警告
1.1 錯(cuò)誤信息
1>g:\噴涂機(jī)器人\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 _AFXDLLEnable3dControls(); // Call this when using MFC in a shared DLL #elseEnable3dControlsStatic(); // Call this when linking to MFC statically #endif主要由于版本問題所導(dǎo)致的,Windows95以后就不需要再調(diào)用這兩個(gè)函數(shù)了,因此使用_MSC_VER對(duì)其進(jìn)行隔離即可:
#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 #endif2.錯(cuò)誤2:外部符號(hào)無(wú)法解析
參考:vs2015引用lib庫(kù)
2.1 錯(cuò)誤信息
1> DMCd1.cpp
1>DMCd1DLG.obj : error LNK2019: 無(wú)法解析的外部符號(hào) _smc_board_init@16,該符號(hào)在函數(shù) “protected: virtual int __thiscall CDMCd1Dlg::OnInitDialog(void)” (?OnInitDialog@CDMCd1Dlg@@MAEHXZ) 中被引用
…
1>DMCd1DLG.obj : error LNK2019: 無(wú)法解析的外部符號(hào) _smc_get_position_unit@12,該符號(hào)在函數(shù) “protected: void __thiscall CDMCd1Dlg::OnTimer(unsigned int)” (?OnTimer@CDMCd1Dlg@@IAEXI@Z) 中被引用
1>G:\噴涂機(jī)器人\Spraying robot\Debug\Spraying robot.exe : fatal error LNK1120: 17 個(gè)無(wú)法解析的外部命令
2.2 解決方法
(1)配置屬性–>C/C++–>常規(guī)–>附加包含目錄
添加:你的LTSMC.lib所在目錄
(2)配置屬性–>鏈接器–>輸入–>附加依賴項(xiàng)
添加:LTSMC.lib
(3)將對(duì)應(yīng)的dll文件放到與exe同一級(jí)目錄下
3.顯示結(jié)果
編譯后得到一個(gè)簡(jiǎn)易的控制軟件界面,連接好SMC304后根據(jù)文檔設(shè)置好以太網(wǎng)參數(shù)即可直接控制,隨后便在VS2015上對(duì)程序進(jìn)行進(jìn)一步修改,實(shí)現(xiàn)自定義控制!
例程軟件界面:
SMC304用戶手冊(cè)內(nèi)容:
本例中的 SMC304 的 IP 地址為 192.168.5.11, PC 機(jī)設(shè)置的 IP 與 SMC304 的 IP 前 3 個(gè)字段要相同,第 4 個(gè)字段要不同。如圖 3-8 所示, PC 機(jī)設(shè)置的 IP 設(shè)為 192.168.5.6 即可。
PS:由于雷塞公司提供的是32位庫(kù),因此編譯的時(shí)候必須選擇x86
總結(jié)
以上是生活随笔為你收集整理的雷塞SMC304系列控制器VC6.0例程在VS2015下编译遇到的若干问题及解决办法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一篇搞定css基础(超详细,附代码)
- 下一篇: domoticz 链接 百度云物联网MQ