Handmade Hero»Forums»Code
Gavin Williams
26 posts
Day 8 : Linker errors
Edited by Gavin Williams on
Hi,

I just found out about this project, rushing through the vids to catch up, but only on day 8. I love it by the way, I'm a pretty die hard C# programmer, but really appreciate the opportunity to be walked through a C project (having only ever written 1 C program at university, a wav audio processing tool)

In regards to the project (day 8 ) however, I have linker errors:

// ------------------------------------------------------------------------------
Severity Description Project File Line
Warning warning LNK4272: library machine type 'UNKNOWN' conflicts with target machine type 'X86' HandmadeHero OLDNAMES.lib 1
// -----------------
Severity Description Project File Line
Error error LNK1120: 1 unresolved externals HandmadeHero HandmadeHero.exe
// -----------------
Severity Description Project File Line
Error error LNK2019: unresolved external symbol _DirectSoundCreate8@12 referenced in function "void __cdecl InitDirectSound(struct HWND__ *,int,int)" (?InitDirectSound@@YAXPAUHWND__@@HH@Z) HandmadeHero Main.obj
// ---------------------------------------------------------------------------

To overcome this, I had to use:

#pragma comment(lib, "dsound.lib")

I'm on Windows 8.1, using xinput9_1_0.dll. Not sure about sound.

Can anyone explain whats going on ?

Cheers.
Mārtiņš Možeiko
2559 posts / 2 projects
Day 8 : Linker errors
Not sure how you got first warning - but that is related how you set up project to compile 32-bit or 64-bit code. I think you are linking 64-bit code, but are passing 32-bit object file or library somewhere.

As for missing symbol and about #pragma - this is needed to instruct linker where to find external functions. When compiler compiles your source, it simply leaves kind of placeholders for external functions (in this case DirectSoundCreate8 function). When linker links object files to executable, it needs to know if either you implement functions (for example in different object files, or static libraries), or there is some dll file where this function is found (dsound.dll). In second case you typically pass dynamic import library (dsound.lib) to linker which contains list of functions dll file exports. You can pass this library either with #pragma statement you wrote, or by opening Project Properties dialog and adding dsound.lib there in Addition Dependencies setting.

Or you do what Casey does - loads library dynamically at runtime. Watch day 7 video more carefully, starting from 27:00. This is better in a sense that it allows you to silently fail. If dll file is not present on users machine, program will simply not load library and continue without it. If you are doing linking to library as above with #pragma or linker setting, then your application won't run at all.
Gavin Williams
26 posts
Day 8 : Linker errors
Ah, thanks.