雷塞SMC304系列控制器VC6.0例程在VS2015下编译遇到的若干问题及解决办法
雷塞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 _AFXDLLEnable3dControls(); // Call this when using MFC in a shared DLL #elseEnable3dControlsStatic(); // 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 #endif2.錯誤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
總結
以上是生活随笔為你收集整理的雷塞SMC304系列控制器VC6.0例程在VS2015下编译遇到的若干问题及解决办法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一篇搞定css基础(超详细,附代码)
- 下一篇: ArcEngine简单教程——要素的属性