使用 directX 和 Visual Studio 2010 的链接器错误
因此,我已经为此工作了两个小时的大部分时间,尽管我似乎遵循了互联网上每个论坛/指南的确切说明,但在尝试将 directX 与 Visual Studio 2010 一起使用时,我仍然遇到链接器错误。
以下是我开始使用的代码:
#include <D3DX10.h>
#include <iostream>
using namespace std;
ostream& operator<<(ostream& os, D3DXVECTOR3& v){
os << "(" << v.x << ", " << v.y << ", " << v.z << ")\n";
return os;
}
int main (){
return 0;
}
我已下载并安装了 SDK,并且在项目配置属性中手动设置了适当的包含目录和库目录。我还设置了额外的链接器输入依赖项:
d3dx10.lib
d3dx10d.lib
但是,我在编译时仍然收到以下错误:
1>MSVCRTD.lib(crtexew.obj) : error LNK2019: 无法解析的外部符号 WinMain@16 在函数 __tmainCRTStartup
1>C 中引用:\Users\Ben\Documents\Visual Studio 2010\Projects\DX Practice\Debug\DX Practice.exe:致命错误 LNK1120:1 未解决的外部问题
感谢任何和所有帮助。
编辑:将 int main() 更改为 int WinMain()。新错误:
1>c:\users\ben\documents\visual studio 2010\projects\dxpractice\dxpractice\main.cpp(10): warning C4007: 'WinMain' : 必须是 '__stdcall'
1>c:\用户\本\文档\ Visual Studio 2010 \项目\ dx实践\ dx实践\ main.cpp(10):错误C2731: 'WinMain' : 函数不能重载
1> c:\users\ben\documents\visual studio 2010\projects\dxpractice\dxpractice\main.cpp(10) :参见“WinMain”的声明
EDIT2:弄清楚了 -
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
感谢大家的帮助:)
So I've been working on this for the better part of two hours and although I appear to be following the exact instructions of every forum/guide on the internet, I'm still getting linker errors trying to use directX with Visual Studio 2010.
Here is the code I'm starting with:
#include <D3DX10.h>
#include <iostream>
using namespace std;
ostream& operator<<(ostream& os, D3DXVECTOR3& v){
os << "(" << v.x << ", " << v.y << ", " << v.z << ")\n";
return os;
}
int main (){
return 0;
}
I have the SDK downloaded and installed and I have the manually set up the appropriate include and library directories in the project configuration properties. I have also set up additional linker input dependencies:
d3dx10.lib
d3dx10d.lib
However, I am still getting the following errors upon compiling:
1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol WinMain@16 referenced in function __tmainCRTStartup
1>C:\Users\Ben\Documents\Visual Studio 2010\Projects\DX Practice\Debug\DX Practice.exe : fatal error LNK1120: 1 unresolved externals
Any and all help is appreciated.
EDIT: Changed int main() to int WinMain(). New errors:
1>c:\users\ben\documents\visual studio 2010\projects\dx practice\dx practice\main.cpp(10): warning C4007: 'WinMain' : must be '__stdcall'
1>c:\users\ben\documents\visual studio 2010\projects\dx practice\dx practice\main.cpp(10): error C2731: 'WinMain' : function cannot be overloaded
1> c:\users\ben\documents\visual studio 2010\projects\dx practice\dx practice\main.cpp(10) : see declaration of 'WinMain'
EDIT2: Figured it out -
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
Thanks all for the help :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
除非您在 Visual Studio 中使用特殊设置,否则窗口可执行文件将从
WinMain
函数开始,而不是常规的main
函数。因此,您应该创建一个控制台应用程序,使用WinMain
,或者使用设置来使用常规main
函数。请注意,实际创建窗口不需要从
WinMain
开始。这只是 Visual Studio 的约定。使用常规
main
的选项位于“项目设置”对话框中的“链接器->高级”下。它被称为“入口点”,要使用常规 main,请使用“mainCRTStartup”作为值。如果你坚持使用
WinMain
,那么你需要正确定义它:Unless you use a special setting in Visual Studio, windowed executables start with the
WinMain
function, not the regularmain
function. So you should either be creating a console app, be usingWinMain
, or use the setting to use the regularmain
function.Note that starting with
WinMain
is not required for actually creating windows. It's just a Visual Studio convention.The option to use regular
main
is under "Linker->Advanced" in the Project Settings dialog. It is called, "Entry Point", and to use the regular main, you use "mainCRTStartup" as the value.If you insist on using
WinMain
, then you need to define it correctly:如果您包含 Windows 标头,则链接器希望您提供
WinMain
函数,而不是常规的main
。 WinMain 入口点提供特定于 Windows 的数据,例如HINSTANCE
。If you include the Windows headers, then the linker expects you to provide a
WinMain
function, not the regularmain
. The WinMain entry point provides Windows-specific data likeHINSTANCE
s.