如何在Windows上添加库包括NetBeans和gcc的路径?
使用:
mingw-get-inst-20120426.exe)我重新安装了Code :: Blocks(我安装了一个用于Windows 7的GCC编译器(codeblocks-10.05mingw-setup.exe)).然后我尝试编译这个非常简单的代码:
int wmain(int argc, wchar_t* argv[])
{
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误消息:
C:\研发\ IDE \代码块\ MinGW的\ BIN ..\LIB\GCC \的mingw32\4.4.1 ......\libmingw32.a(main.o),此:main.c中|| 未定义的引用`WinMain @ 16'| || ===构建完成:1个错误,0个警告=== |
当我尝试使用main()条目运行我的代码时,它会按预期运行而不会出现任何错误或警告.我如何wmain()在我的代码中使用?我需要做哪些修改?
我知道这听起来很愚蠢,但我在Windows7上使用MinGW32,并且" to_string未在此范围内声明." 这是一个真正的GCC Bug,我已经按照这些说明进行操作了.那么,如何在不使用to_string或stoi?的情况下将int转换为C++ 11中的字符串?(另外,我-std=c++11启用了标志).
通常我使用视觉工作室,但我切换到mingw,我喜欢使我的应用程序可以从unicode和多字节轻松更改,在我的mingw项目中我有我的定义,包括这样:
#define WIN32_LEAN_AND_MEAN
#define WINVER 0x0700
#define _UNICODE
#include <windows.h>
#include <commctrl.h>
#include <stdio.h>
#include <stdlib.h>
#include <tchar.h>
#define WND_MAIN_CLASS _T("MainWindowFrame")
Run Code Online (Sandbox Code Playgroud)
然后我注册并创建我的窗口,例如
WNDCLASSEX wc;
...
wc.lpszClassName = WND_MAIN_CLASS;
RegisterClassEx(&wc);
hwnd = CreateWindowEx(0, WND_MAIN_CLASS, _T("Main Window"),
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, NULL, NULL, hInst, NULL);
Run Code Online (Sandbox Code Playgroud)
但是当我去编译时,我得到错误,它无法将Wchar_t转换为WNDCLASSEX上的CHAR*和类名称和窗口标题上的CreateWindowEx上的CHAR*.
如果我右键单击并转到createwindowex和WNDCLASSEX的声明,它会从winuser.h中得到这些:
typedef WNDCLASSEXW WNDCLASSEX,*LPWNDCLASSEX,*PWNDCLASSEX;
#define CreateWindowEx CreateWindowExW
Run Code Online (Sandbox Code Playgroud)
如果我注释掉定义_UNICODE它编译并且没有任何问题
所以我尝试使用 Win32 在CodeBlocks中创建一个窗口,到目前为止只有这个版本的 WinMain 可以工作(注意:这只是一个简单而幼稚的示例):
#include <windows.h>
INT WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow ) {
MessageBox( NULL, "Title", "Message", MB_OKCANCEL );
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但这个版本没有:
#include <windows.h>
INT WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, INT nCmdShow ) {
MessageBox( NULL, "Title", "Message", MB_OKCANCEL );
return 0;
}
Run Code Online (Sandbox Code Playgroud)
据我所知,后者期望第三个参数是指向宽字符字符串的指针,而前者则不然。但是当我在 CodeBlocks 中编译时,我得到的只是这条消息:
对 WinMain@16 的未定义引用
显然,CodeBlocks 期望 WinMain 的版本不接收 LPWSTR 值作为参数。我的问题是,如何配置 CodeBlocks 以便它与 wWinMain 一起编译?
第一次切换到GCC,我对编译器在这里告诉我的内容感到有些困惑.基本上,它的行为类似于boost :: xpressive :: wsregex未定义(我相信).
这是相关代码:
#include "criterion.h"
#include <string>
#include <boost/xpressive/xpressive.hpp>
//More lines of code omitted here
class perlRegex : public regexClass
{
private:
std::wstring regexString;
boost::xpressive::wsregex regex; // This is the line complained about
public:
unsigned __int32 getPriorityClass() const;
BOOL include(fileData &file) const;
unsigned int directoryCheck(const std::wstring& /*directory*/) const;
std::wstring debugTree() const;
perlRegex(const std::wstring& inRegex);
};
Run Code Online (Sandbox Code Playgroud)
这是错误:
regex.h:46: error: using-declaration for non-member at class scope
regex.h:46: error: expected `;' before "regex"
Run Code Online (Sandbox Code Playgroud)
我在这里感到困惑的是,我宣布成员,但它抱怨我在其他地方使用其他成员.
我忘记了#include什么吗?
在此先感谢Billy3
我已经阅读了有关如何在C ++中创建简单窗口的Microsoft页面。这是代码:
#ifndef UNICODE
#define UNICODE
#endif
#include <windows.h>
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow) {
// Register the window class.
const wchar_t CLASS_NAME[] = L"Sample Window Class";
WNDCLASS wc = { };
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
RegisterClass(&wc);
// Create the window.
HWND hwnd = CreateWindowEx(
0, // Optional window styles.
CLASS_NAME, // Window class
L"Learn to Program Windows", // Window text …Run Code Online (Sandbox Code Playgroud)