Error C1189: #error: Please use the /MD switch for _AFXDLL builds

在VS 2017中编译程序时出现错误:

错误提示1:

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]

原因:

常规里面是:在静态库中使用MFC,或使用标准Windows库,此时该处可能无论是什么都会报错

运行库中多线程调试是:MDd(多线程调试DLL)

解决方法:

将MDd改成MTd,如果改正后报错误2,按下面方法更改。

错误提示2:

error C1189: #error: Please use the /MD switch for _AFXDLL builds

原因:

常规里面是:在共享DLL中使用MFC,

运行库中多线程调试是:MTd(多线程调试)

解决方法:

将常规改成:在静态库中使用MFC,或使用标准Windows库

常规和运行库 如下图:

常规: 右击项目->属性->配置属性->常规,然后在右边的“项目默认值”中的“MFC的使用”选项中选择“在静态库中使用MFC”,

多线程调试: 右击项目–>属性->配置属性->c/c+±>代码生成->运行时库->多线程调试(/MTd)
在这里插入图片描述
在这里插入图片描述
相关注释:

MFC的使用,有三种设置:

1.使用标准Windows库

2.在静态库中使用MFC:是将DLL中的相关代码写进EXE文件中,文件较大,但是可以在没有相关DLL的机器上运行;

3.在共享DLL中使用MFC:指的是打包时一些MFC的DLL的内容没有被包含在EXE文件中,所以EXE文件较小,但是运行时要求系统中要有相关的DLL文件;

多线程调试

/MD:在dll中使用多线程,创建动态链接库的release版本,需要选择。

/MT: 在exe里使用多线程,创建exe的release版本,需要选择。

/MTd:同/MT一样,不过是在Debug版本中使用。

/MDL:同/MD一样,不过是在Debug版本中使用。

如果是Debug的“在静态库中使用MFC”,不要使用MDd,改用MTd,然后编译即可通过。

如果是Debug的“在共享DLL中使用MFC”,注意不要使用MTd,改用MDd;

如果是Release版本“在静态库中使用MFC”,不要使用MD,使用MT;

如果是Release版本的“在共享DLL中使用MFC”,不要使用MT,使用MD。

  • 1
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
很全面的通讯录。各种项目还可自行修改。// Lab_link.cpp : Defines the class behaviors for the application. // #include "stdafx.h" #include "Lab_link.h" #include "Lab_linkDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CLab_linkApp BEGIN_MESSAGE_MAP(CLab_linkApp, CWinApp) //{{AFX_MSG_MAP(CLab_linkApp) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG ON_COMMAND(ID_HELP, CWinApp::OnHelp) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CLab_linkApp construction CLab_linkApp::CLab_linkApp() { // TODO: add construction code here, // Place all significant initialization in InitInstance } ///////////////////////////////////////////////////////////////////////////// // The one and only CLab_linkApp object CLab_linkApp theApp; ///////////////////////////////////////////////////////////////////////////// // CLab_linkApp initialization BOOL CLab_linkApp::InitInstance() { AfxEnableControlContainer(); // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif CLab_linkDlg dlg; m_pMainWnd = &dlg; int nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel } // Since the dialog has been closed, return FALSE so that we exit the // application, rather than start the applicati
小型计算器的源程序,基于MFC. // MyCalrr.cpp : Defines the class behaviors for the application. // #include "stdafx.h" #include "MyCalrr.h" #include "MyCalrrDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CMyCalrrApp BEGIN_MESSAGE_MAP(CMyCalrrApp, CWinApp) //{{AFX_MSG_MAP(CMyCalrrApp) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG ON_COMMAND(ID_HELP, CWinApp::OnHelp) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CMyCalrrApp construction CMyCalrrApp::CMyCalrrApp() { // TODO: add construction code here, // Place all significant initialization in InitInstance } ///////////////////////////////////////////////////////////////////////////// // The one and only CMyCalrrApp object CMyCalrrApp theApp; ///////////////////////////////////////////////////////////////////////////// // CMyCalrrApp initialization BOOL CMyCalrrApp::InitInstance() { AfxEnableControlContainer(); // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif CMyCalrrDlg dlg; m_pMainWnd = &dlg; int nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel } // Since the dialog has been closed, return FALSE so that we exit the // application, rather than start the application's message pump. return FALSE; }
聊天程序一般由两大部分组成:服务器端聊天程序和客户端聊天程序。服务器端聊天程序负责接收来自客户端的聊天信息,并且根据客户端的要求把这些信息转发到另外一个或多个客户中。客户端聊天程序则负责建立和维护与服务器端的连接,向服务器发送本客户的聊天内容,同时从服务器接收对方的响应。 本设计是为了使同学加深理解对话框编程的知识而设计的,对于网络技术这一应用,可不用深究其原理。 #include "stdafx.h" #include "chat.h" #include "chatDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CChatApp BEGIN_MESSAGE_MAP(CChatApp, CWinApp) //{{AFX_MSG_MAP(CChatApp) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG ON_COMMAND(ID_HELP, CWinApp::OnHelp) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CChatApp construction CChatApp::CChatApp() { // TODO: add construction code here, // Place all significant initialization in InitInstance } ///////////////////////////////////////////////////////////////////////////// // The one and only CChatApp object CChatApp theApp; ///////////////////////////////////////////////////////////////////////////// // CChatApp initialization BOOL CChatApp::InitInstance() { if (!AfxSocketInit()) { AfxMessageBox(IDP_SOCKETS_INIT_FAILED); return FALSE; } AfxEnableControlContainer(); // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif CChatDlg dlg; m_pMainWnd = &dlg; int nResponse = dlg.DoModal();
// FiveChess.cpp : Defines the class behaviors for the application. // #include "stdafx.h" #include "FiveChess.h" #include "MainFrm.h" #include "FiveChessDoc.h" #include "FiveChessView.h" #include "afxsock.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif //////////////////////////////////////////////////////////////////////////// // CFiveChessApp BEGIN_MESSAGE_MAP(CFiveChessApp, CWinApp) //{{AFX_MSG_MAP(CFiveChessApp) ON_COMMAND(ID_APP_ABOUT, OnAppAbout) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG_MAP // Standard file based document commands ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew) ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen) // Standard print setup command ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CFiveChessApp construction CFiveChessApp::CFiveChessApp() { // TODO: add construction code here, // Place all significant initialization in InitInstance } ///////////////////////////////////////////////////////////////////////////// // The one and only CFiveChessApp object CFiveChessApp theApp; ///////////////////////////////////////////////////////////////////////////// // CFiveChessApp initialization BOOL CFiveChessApp::InitInstance() { AfxEnableControlContainer(); // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif // Change the registry key under which our settings are stored. // TODO: You should modify this string to be something appropriate // such as the name of your company or organization. SetRegistryKey(_T("Local AppWizard-Generated Applications")); LoadStdProfileSettings(); // Load standard INI file options (including MRU) // Register the application's document templates. Document templates // serve as the connection between documents, frame windows and views. CSingleDocTemplate* pDocTemplate; pDocTemplate = new CSingleDocTemplate( IDR_MAINFRAME, RUNTIME_CLASS(CFiveChessDoc), RUNTIME_CLASS(CMainFrame), // main SDI frame window RUNTIME_CLASS(CFiveChessView)); AddDocTemplate(pDocTemplate); // Parse command line for standard shell commands, DDE, file open CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); // Dispatch commands specified on the command line if (!ProcessShellCommand(cmdInfo)) return FALSE; // The one and only window has been initialized, so show and update it. m_pMainWnd->ShowWindow(SW_SHOW); m_pMainWnd->UpdateWindow(); return TRUE; } ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: //{{AFX_MSG(CAboutDlg) // No message handlers //}}AFX_MSG DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() // App command to run the dialog void CFiveChessApp::OnAppAbout() { CAboutDlg aboutDlg; aboutDlg.DoModal(); } ///////////////////////////////////////////////////////////////////////////// // CFiveChessApp message handlers
自己定义的ip地址控件,好用 #include "stdafx.h" #include "IPTest.h" #include "IPTestDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CIPTestApp BEGIN_MESSAGE_MAP(CIPTestApp, CWinApp) //{{AFX_MSG_MAP(CIPTestApp) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG ON_COMMAND(ID_HELP, CWinApp::OnHelp) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CIPTestApp construction CIPTestApp::CIPTestApp() { // TODO: add construction code here, // Place all significant initialization in InitInstance } ///////////////////////////////////////////////////////////////////////////// // The one and only CIPTestApp object CIPTestApp theApp; ///////////////////////////////////////////////////////////////////////////// // CIPTestApp initialization BOOL CIPTestApp::InitInstance() { // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif CIPTestDlg dlg; m_pMainWnd = &dlg; int nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel } // Since the dialog has been closed, return FALSE so that we exit the // application, rather than start the application's message pump. return FALSE; }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值