Advertisement

Visual Studio Add Reference to Project

Started by October 23, 2018 06:52 PM
12 comments, last by Rutin 6 years, 1 month ago

I am new to C++ and Visual Studio. I downloaded a library that consists of multiple Projects in one Project Folder(? my Version is not in english - basically multiple Projects summed into one) and some of those Projects are example programs using other Projects in the Project Folder as references. I was trying to build my very own test Project in this Project Folder and added the other Projects in the "reference settings". However they do not Show up in the external references list in the Project Explorer window and Visual Studio is also marking my "include" red, telling me it can't find the files I am referencing.

Does somebody know what I am doing wrong?

I find it easier to build each library separately and link to the .lib/.dll from my project instead of having multiple projects. You are going to have huge problems for every library you want to add as a project, at least this has been my experience.

🙂🙂🙂🙂🙂<←The tone posse, ready for action.

Advertisement

Thanks for the Reply, can you tell me how to add a .dll to a C++ Project in Visual Studio then? The only tutorials I can find a are for older versions. I tried this one https://stackoverflow.com/questions/809948/dll-references-in-visual-c but Visual Studio is still marking my include's red. I don't get it at all.

7 minutes ago, IceCave said:

Thanks for the Reply, can you tell me how to add a .dll to a C++ Project in Visual Studio then? The only tutorials I can find a are for older versions. I tried this one https://stackoverflow.com/questions/809948/dll-references-in-visual-c but Visual Studio is still marking my include's red. I don't get it at all.

If I'm guessing your question right you would do this once your project is loaded.

I made some screen shots:

image.png.0c4e52a096982f4318b09c2373b4e35b.png

You will need to reference your include and library directories (See the BOLD):

image.png.a63e552ac49fac7dd81055ba0233008d.png

or you can do it at a project level:

image.png.a6d6ee56f92df8325cb77810aabd4eed.png

and

image.png.f6b319c23ac6b9963d48dce7ef14d6da.png

Once your directories are referenced you will need to go to Link -> Input

image.png.24f6a388022ef6cde91e50eedf9cab04.png

Keep in mind some libs are for DEBUG and RELEASE only and you will need to set the configuration at the top left to those modes before adding your additional dependencies.

DEBUG:

image.png.a7ce5b1190941aa4b3322f02df871f22.png

 

RELEASE:

image.png.63571fa6996e898143256cadd4a503c0.png

Static linking would be done like so:

image.png.e30569ad2d0fa478a33fc22265cbc8fb.png

(Don't worry about the below as the above should be enough to get you going!)

If you want to work with the .DLL manually then you need to checkout these in the order I listed:

https://docs.microsoft.com/en-us/windows/desktop/api/libloaderapi/nf-libloaderapi-loadlibrarya

https://docs.microsoft.com/en-us/windows/desktop/api/libloaderapi/nf-libloaderapi-getprocaddress

https://docs.microsoft.com/en-us/windows/desktop/api/libloaderapi/nf-libloaderapi-freelibrary

Read up on this more here:

https://docs.microsoft.com/en-us/windows/desktop/Dlls/about-dynamic-link-libraries

https://docs.microsoft.com/en-us/windows/desktop/dlls/using-dynamic-link-libraries

Programmer and 3D Artist

Thank you very much for the tutorial, amazing!

I set the directory (with the .lib files) in all the places you mentioned above but when trying to include any it is still marked in red. You would think after many years it would be a matter of drag n drop. I guess I am going to dump C++ altogether again, my frustration level is just too high right now to deal with an obviously outdated platform and bind the functionalities I need to another language.

Thanks anyway.

1 hour ago, IceCave said:

Thank you very much for the tutorial, amazing!

I set the directory (with the .lib files) in all the places you mentioned above but when trying to include any it is still marked in red. You would think after many years it would be a matter of drag n drop. I guess I am going to dump C++ altogether again, my frustration level is just too high right now to deal with an obviously outdated platform and bind the functionalities I need to another language.

Thanks anyway.

If you let me know the library you're using and copy and paste your full error message I can try to help you. :) 

I would also recommend using a more up to date library and something more widely used, this will cut down a lot of incompatibility issues. A lot of people run into linker problems and so forth.

Programmer and 3D Artist

Advertisement

After your helpful Picture Show the includes work fine, again thanks for that. However Visual Studio is still marking my Code red that I copied straight out of the library source files (which compile totally fine), like i.e. that an object is Abstract and can't be initiated (but why is it working in the example Code in the library itself, then?) or a constructor can't be called because it is marked as deleted. Again, works fine in the library itself.

Maybe I should sum the functionality I need, in a class in the library itself and then just communicate over this .cpp.

6 minutes ago, IceCave said:

After your helpful Picture Show the includes work fine, again thanks for that. However Visual Studio is still marking my Code red that I copied straight out of the library source files (which compile totally fine), like i.e. that an object is Abstract and can't be initiated (but why is it working in the example Code in the library itself, then?) or a constructor can't be called because it is marked as deleted. Again, works fine in the library itself.

Maybe I should sum the functionality I need, in a class in the library itself and then just communicate over this .cpp.

I would need to see the message to help. I would normally caution against learning off other people's source code unless it's coming from a good book, or something as part of a library example and is up to date.

Programmer and 3D Artist

Yeah, but I need the DLL functionalities.

What I found out when pressing compile: he is telling me that he can't open some source files for various include statements in the Header files from the dlls I am including. I don't see the reason why he would want to do that, the dlls are already compiled and working(!), I just want to call some Methods on them. I don't have the Header files for the dlls they are referencing.

Any clues?

Ohhhh, I get it. Now I understand how this works. The tutorials in the Internet are way too simple in this specific case. All the Header files are in different directories and then there are 3rd Party libraries as well which have to be bind into the Project as well. Wow. Thats complicated. Let's see how this Plays out.

This topic is closed to new replies.

Advertisement