• Create Account

LNK2028 Error when creating instance of class

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

8 replies to this topic

#1Inuyashakagome16  Members

Posted 04 February 2013 - 08:31 PM

InitializeComponent();
D3DClass* D3D_class;
D3D_class = new D3DClass;

So i'm having this issue. I've created a small C++ application with a basic window and a bunch of engine type classes for DirectX 11. (Via Rastek) Well I made a CLR application for a type of editor and I'm having issues creating an instance of the D3DClass to initialize. (Full source of above snippet http://pastebin.com/xuvxWdmh )

1>Testing.obj : error LNK2028: unresolved token (0A00002C) "public: __thiscall D3DClass::D3DClass(void)" (??0D3DClass@@$$FQAE@XZ) referenced in function "public: __clrcall Testing::Form1::Form1(void)" (??0Form1@Testing@@$$FQ$AAM@XZ) 1>Testing.obj : error LNK2019: unresolved external symbol "public: __thiscall D3DClass::D3DClass(void)" (??0D3DClass@@$$FQAE@XZ) referenced in function "public: __clrcall Testing::Form1::Form1(void)" (??0Form1@Testing@@$$FQ$AAM@XZ)

^ this is the error i'm getting. Now i'm linking to the DX Sdk, and I'm setting up a link for the Editor project which is also in the solution where the engine is for the class files / header files obviously. I'm not sure why this is happening. I've looked it up and none of the solutions seem to help.

Here is the D3DClass http://pastebin.com/ni1zSQmw (its a bit long to just put in this thread)

I'm not sure what I'm missing. All i'm doing is initializing the class and it's throwing those errors. I'm not even ACTUALLY initializing D3D yet.

#2Yourself  Members

Posted 05 February 2013 - 02:06 AM

is the D3D_class part of a DLL ?

if so, I looks like that you do not export/import the D3D_class (using __declspec(dllexport) and __declspec(dllimport) ).

#3Inuyashakagome16  Members

Posted 05 February 2013 - 08:52 AM

No it is not. D3D_Class is an instance of D3DClass which is a class from the other project in my solution. Which I've already successfully linked to and using the methods from said class and it seems like it works fine. And what do you mean export/import? I'm not sure what you are trying to say.

#4EWClay  Members

Posted 05 February 2013 - 11:27 AM

The linker won't automatically bring in a class that's in another project in the solution. You would have to either include the cpp file in the new project, or compile the code you need into a library and then link to that.

In this case, it's complaining that the constructor of D3DClass is missing, because you called new.

#5Inuyashakagome16  Members

Posted 05 February 2013 - 12:12 PM

I believe I am including the cpp file in the new project. In the Properties for the project I went to Configuration Properties > C/C++ > General > And under "Additional Include Directories" i put \$(SolutionDir)EngineName which includes the cpp's from that project. And they show up when I put in #include ""

If that's what you mean then yes I am including them. Maybe in the wrong place?

EDIT: If it has to do with scope or something, I actually have the D3D function(s) i'm trying to access set to public and it's still not working.

Edited by Inuyashakagome16, 05 February 2013 - 12:15 PM.

#6EWClay  Members

Posted 05 February 2013 - 12:43 PM

No, that only allows the preprocessor to find the headers. You have to actually put the cpp file into the project as a source file, or make a library, as I said.

#7Inuyashakagome16  Members

Posted 05 February 2013 - 01:58 PM

No, that only allows the preprocessor to find the headers. You have to actually put the cpp file into the project as a source file, or make a library, as I said.

I feel like I'm asking the same question again but, does the file have to be IN the project folder even though its in the same solution? I feel like that would be strange if you were lets say using like the DX SDK. But that's probably a set of libraries. How would I make the file a library?

#8Yourself  Members

Posted 05 February 2013 - 04:15 PM

No, that only allows the preprocessor to find the headers. You have to actually put the cpp file into the project as a source file, or make a library, as I said.

I feel like I'm asking the same question again but, does the file have to be IN the project folder even though its in the same solution? I feel like that would be strange if you were lets say using like the DX SDK. But that's probably a set of libraries. How would I make the file a library?

No it does not, you have to add the files to the project inside Visual Studio (right click on project in solution explorer, add, existing item).

You do not make a file a library, you make a project a library.

You either make it a static library (.lib file) or a dynamic library (.dll file). Both have pros and cons but remember converting projects to libraries is often not trivial...

see http://msdn.microsoft.com/en-us/library/ms235627(v=vs.80).aspx and http://msdn.microsoft.com/en-us/library/vstudio/ms235636.aspx for more info on creating and using  libraries.

#9Inuyashakagome16  Members

Posted 07 February 2013 - 04:34 AM

Okay I understand now. Sorry about that, I ended up just Right Clicking the project > Add > Existing Item And selecting the CPP file and it worked! I had to change the imported CPP file to not precompile a header because it was throwing an error but its good now. Thanks all!

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.