0
101 Jun 08, 2006 at 13:48

I’m creating my direct 3d interface object by using:

// in WinMain ...
if((pD3D = Direct3DCreate9(D3D_SDK_VERSION)) == NULL)
return E_FAIL;


pD3D is defined globally as a LPDIRECT3D9 and I’ve included d3d9.h but I’m getting this error message:

“1>main.obj : error LNK2019: unresolved external symbol _Direct3DCreate9@4 referenced in function _WinMain@16”

Any ideas what’s wrong? I remember I got the same error before when I did this but I can’t remember how I solved it.

#### 11 Replies

0
102 Jun 08, 2006 at 14:02

It looks like you aren’t linking to the D3D libraries…

0
101 Jun 08, 2006 at 14:38

0
101 Jun 09, 2006 at 15:06

… or add the .lib file to your solution, or #pragma comment(lib, “d3d9.lib”) in the header file of your pogram… so may ways :)

0
101 Jun 10, 2006 at 07:16

Oh ok. I was under the impression that including the header file allowed you to use those functions.

What exactly does linking to the library do?

[EDIT] Thanks btw! :)

0
101 Jun 10, 2006 at 09:40

@poita

Oh ok. I was under the impression that including the header file allowed you to use those functions.

What exactly does linking to the library do?

[EDIT] Thanks btw! :)

The way the build system works is in a couple of major parts (not counting the preprocessor and suchlike).

First, the compiler will take the raw source code and convert it into an object file. This is why you need to include header files. The header files contain the declarations of the functions you’re using. ie. the header files say to the compiler, “there is such a function matching this prototype - if it gets used, don’t give an error”. If you didn’t include the header, or used the function wrongly, the compiler would tell you about it.

That’s assuming you’re using dynamic linking, which I guess you probably are :).

0
101 Jun 11, 2006 at 11:02

Thanks for that baldurk, makes perfect sense now. :)

Off-topic:

Regarding you sig, I always heard that with 2 more lines:
“He that knows and knows not that he knows is asleep. Awaken him.
He that knows and knows that he knows is wise. Follow him.”

Don’t know if you already knew them but just though I’d put that out there.

0
102 Jun 12, 2006 at 14:02

Those sayings would be easier for me to follow in C++ rather than in English. ;)

void Person::FollowBaldurkAdvice(Person & other)
{
if (!other.Knows() && !other.ThinksHeKnows())
this->Teach(other);
else if (!other.Knows() && other.ThinksHeKnows())
this->Shun(other);
else if (other.Knows() && !other.ThinksHeKnows())
this->Awaken(other);
else if (other.Knows() && other.ThinksHeKnows())
this->Follow(other);
}


… or perhaps a truth table would help.

Knows | Thinks He Knows || Action
-----------------------------------
0  |        0        || Teach
0  |        1        || Shun
1  |        0        || Awaken
1  |        1        || Follow

0
101 Jun 12, 2006 at 17:35

hah. I did originally have the entire quote, but generally the first two lines are very relevant to forums, the second two aren’t :). Besides, 4 lines is a bit much for a sig.

monjardin: your JwN meter has gone down I see :).

0
102 Jun 12, 2006 at 18:48

Yes, the JwN meter has gone down. Lately, the MMO noobs are getting shot down before I even see their posts. This one cheered me up a bit. The poster took the constructive criticism for what it was.

Otherwise, the standard procedure has been to degrade the DevMaster forum members. In light of the answer you just gave poita, I don’t know how anyone could claim this forum is inhospitable to beginners. It’s a good question from someone that doesn’t have much programming experience, but a lot of places would flame him/her anyway.

Also, did you notice that the FollowBaldurkAdvice method does’t work with a const Person? ;)

0
101 Oct 17, 2009 at 07:31

I have this same problem, except when I check the Options->Directories, the directx includes and library folders are already added to the appropriate Directory tabs…

Is there something else I need to do to use DirectX in my code?

/Sincerely
Martin Enderleit

0
101 Oct 17, 2009 at 07:49

Never mind, I figured it out! :)