【问题标题】:undefined reference to WinMain@16 and unknown pragmas [duplicate]未定义对 WinMain@16 的引用和未知的编译指示 [重复]
【发布时间】:2012-12-09 11:38:01
【问题描述】:

可能重复:
undefined reference to `WinMain@16'

我正在运行最新版本的 CodeBlocks。我尝试编译在教程站点中找到的代码,但由于某种原因出现错误。我将我的项目设置为 DirectX9,并安装了 2010 年 6 月的 DirectX SDK。我还收到警告“未知的编译指示”,告诉​​我代码即使编译也无法正常运行。

// include the basic windows header files and the Direct3D header file
#include <windows.h>
#include <windowsx.h>
#include <d3d9.h>

// include the Direct3D Library file
#pragma comment (lib, "d3d9.lib")

// global declarations
LPDIRECT3D9 d3d;    // the pointer to our Direct3D interface
LPDIRECT3DDEVICE9 d3ddev;    // the pointer to the device class

// function prototypes
void initD3D(HWND hWnd);    // sets up and initializes Direct3D
void render_frame(void);    // renders a single frame
void cleanD3D(void);    // closes Direct3D and releases memory

// the WindowProc function prototype
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

// this function initializes and prepares Direct3D for use
void initD3D(HWND hWnd)
{
    d3d = Direct3DCreate9(D3D_SDK_VERSION);    // create the Direct3D interface

    D3DPRESENT_PARAMETERS d3dpp;    // create a struct to hold various device information

    ZeroMemory(&d3dpp, sizeof(d3dpp));    // clear out the struct for use
    d3dpp.Windowed = TRUE;    // program windowed, not fullscreen
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;    // discard old frames
    d3dpp.hDeviceWindow = hWnd;    // set the window to be used by Direct3D

    // create a device class using this information and information from the d3dpp stuct
    d3d->CreateDevice(D3DADAPTER_DEFAULT,
                      D3DDEVTYPE_HAL,
                      hWnd,
                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                      &d3dpp,
                      &d3ddev);
}

// this is the function used to render a single frame
void render_frame(void)
{
    // clear the window to a deep blue
    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0);

    d3ddev->BeginScene();    // begins the 3D scene

    // do 3D rendering on the back buffer here

    d3ddev->EndScene();    // ends the 3D scene

    d3ddev->Present(NULL, NULL, NULL, NULL);    // displays the created frame
}

// this is the function that cleans up Direct3D and COM
void cleanD3D(void)
{
    d3ddev->Release();    // close and release the 3D device
    d3d->Release();    // close and release Direct3D
}

【问题讨论】:

  • 问题太多了。看起来你只是在猜测。请阅读初学者书籍或教程。投票结束不是一个真正的问题。
  • 您使用的是哪个编译器?你得到的编译错误有点告诉我它的gcc。无论如何,如果您尝试为 Windows 编写应用程序是帮自己一个忙并获得 Visual Studio Express 的帮助。与 windows sdk 一起用于您拥有的任何版本的 windows。

标签: c++ compiler-errors codeblocks directx-9


【解决方案1】:

您可能正在使用 C++ 编译器编译 C 程序。 如果是这种情况,您需要将导出的函数声明为 extern "C"。 例如:

extern "C" int CALLBACK WinMain(...);

【讨论】:

  • CALLBACK 是一个用于声明正确调用约定的宏。
  • 但它不包括 extern "C",这在这种情况下很重要。
猜你喜欢
  • 2012-02-20
  • 2021-11-18
  • 2013-01-15
相关资源
最近更新 更多