How do I fix a linker error?

Started by
8 comments, last by Crypter 16 years, 2 months ago
Hey guys, I was making my first Direct X program to display a blue screen. After coding it completely, it complied without any errors. But when I wanted VC++ to build an EXE file for me it threw up an error saying - Linking... C:\PROGRAM FILES\MICROSOFT DIRECTX SDK (AUGUST 2007)\LIB\X64\d3d9.lib : fatal error LNK1113: invalid machine type Error executing link.exe. My EXE file isnt getting created. How do I fix this? Thanks!
Advertisement
Are you sure you want to be linking against the x64 library? Note the "lib\x64" in the path. Try switching to the "lib\x86" folder for your VC++ path.
Ok I changed that to X86 and I got 2 linker errors now...

Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/abhi.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

Any ideas?
Well I managed to correct that error. Now I have a new error coming up -

Linking...
LINK : fatal error LNK1181: cannot open input file "d3d9.lib"
Error executing link.exe

How do I fix this now?
What version of Visual Studio are you using? Did you set up the DirectX SDK paths correctly, or did you just add the full path to d3d9.lib to your linker options?
You need to link the library files (there is no comma! between files) d3dxof.lib dxguid.lib d3d9.lib d3dx9.lib winmm.lib into your project. Go to Project/Property Pages/Linker/Input/Additional Dependencies and just type in. In addition, you need to change character set. Go to Project/Property Pages/ Configuration Properties/General/Character Set and make Use Multi-byte Character Set.
Well I havent been able able to find the character set option. I use Visual C++ 6.0

I am getting the same error again...

LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/abhi.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

This is so damn irritating. I spend so much of time coding those huge DirectX codes only to end up with this stupid error! URGENT HELP NEEDED for a frustrated programmer! :(
Doesn't that error indicate you created your project as a Win32 console application, but provided a WinMain() instead of a main(), for example?
In your VC property page, select configuration properties->linker->input, and in the field provided for "Ignore specific library", put libcd.lib

-goodbye-
Quote:
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/abhi.exe : fatal error LNK1120: 1 unresolved externals

This means that the linker is looking for a routine to execute (_main, which is main() in C) It has been externally declared, but the linker cannot find its definition.

This is normally defined by the programmer - you. However, in Win32 applications, this entry point is _WinMain instead of _main. - This is where I suspect the problem is at.

Most DirectX programs that I have seen are written for Win32 applications (These use _WinMain) and not Win32 console projects (Default. These use _main), so I second Neverender's suggestion here.

I dont use Visual C++ 6.0, so cannot help you much there.

I do recommend upgrading to a Visual C++ Express Edition (Either 2005 or 2008 version) as Visual C++ 6.0 is both old and not very compilent with C99. Also, Visual C++ 6 has been known to have alot of problems with it.

Also, try to learn more about the linker and linking errors. It will help in understanding the errors and linking problems that you may encounter.

This topic is closed to new replies.

Advertisement