Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to browse to include reference in a Visual Studio C++ DLL project - any way to get around this?

I'm creating a DLL using C++ in Visual Studio 2015. I started my project by following these instructions.

I need to add a reference to my project so I can make use of an API and, unlike C# DLL projects (for example), I'm unable to access the Browse tab when clicking on Project > Add Reference.

According to this page this is because:

The number of tabs available at the top of the Add Reference dialog box can vary, depending on the type of project open and the resources it is using. C++ native projects contain only a Projects tab.

Why is there this restriction and is there any way to get around it?

EDIT: I've just found a solution here but I'm new to Visual Studio and I'm not sure how to set 'the CLR option' and then remove after adding my reference. If anyone can explain how to do this I would be very grateful!

like image 537
user7326333 Avatar asked Jan 04 '23 21:01

user7326333


2 Answers

I'm a little late to the party, but I recently encountered a similar problem and have a fix that might help the OP or others in the future.

Problem Overview:
Open the Visual C++ project[1] in Visual Studio[2]. In the top toolbar, click on "Project > Add Reference..." . In the window that pops up, there is no "Browse" button/option (see image No Browse option).

Solution:
In the top toolbar, click on "Project > Properties"[3]. In the left navigation panel of the window that pops up, click on "Configuration Properties > General" (this will probably be selected by default). In the right panel, click on "Project Defaults > Common Language Runtime Support". The field value should read "No Common Language Runtime Support" (see image No /clr). Using the drop-down menu in the Common Language Runtime Support field (the grey down-arrow box), select "Command Language Runtime Support (/clr)". Apply the change. The Property Page should now look like this. Click "OK" to close the Property Page. Now, when you go to add a reference, the window that shows up will have a "Browse..." button and look like this. If you want to subsequently remove CLR support[4], select the "No Common Language Runtime Support" option and apply the changes.


Notes:

[1] As you're probably aware, you can select from various project types when creating a new project in VS. I experimented with most of the Visual C++ project types included under the Visual C++ template. Since the problem -- lack of "Browse" option when adding references -- seems to be related to CLR support, you will encounter this problem in all Visual C++ project types that are not created as Visual C++ CLR projects. Thus, if you want avoid the problem from the get-go, consider creating a CLR project from the start.

[2] I was able to replicate the problem in Visual Studio 2015, 2017, and 2019; the same solution works for all versions.

[3] Before changing any Configuration Properties, use the Configuration drop-down list in the top-left of the Property Page to select which configuration you would like to change the properties for, e.g. Debug, Release, All.

[4] If you have added references after turning on CLR support, then turning off CLR support is dubious as suggested by @Cody Gray in the comments to the original question. I have not tried to build a project after doing something like this so I can't speak to the solution suggested here. My answer is just to tell you how to change the CLR support.

like image 189
C.J. Geering Avatar answered Jan 07 '23 12:01

C.J. Geering


For C++ projects, you need to get all the projects into the same solution and then when you go to Add Reference you'll see the other projects listed. You then just check the box to 'add the reference'. Keep in mind that this will cause the import library of the DLL (or a static library for a non-DLL library project) to link against your target project. It will not add any include paths you might need to get to the import headers for your DLL.

DirectX Tool Kit has instructions for adding project-to-project references for a C++ project that you might find useful to read over. See here.

For some general background on C++ project-to-project references. See this Visual C++ Team blog post which was published when they were updated for Visual C++ 2010.

like image 30
Chuck Walbourn Avatar answered Jan 07 '23 10:01

Chuck Walbourn