Sign in to follow this  
Inuyashakagome16

LNK2028 Error when creating instance of class

Recommended Posts

			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.

 

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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? 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Okay I understand now. :P 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!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this