How to reference a DLL from a nuget package being restored as part of another project in the solution - nuget-package

Let's say I have a project A that restores a nuget package which includes a specific DLL named D. Another project B in that solution needs to use/reference the D dll that is being restored as part of the nuget pack when project A is compiled. If I simply reference project A from my project B, then the classes in D are not visible within my project B. How I can achieve that, so I use functionality buried in D within my project B (the limitation is I cannot reference that same nuget package from project B)?

Related

How to use classes from a Test project in another Test Project in VC++?

I normally work with C#. In C# I can have a hierarchy, and they reference each other.
I am trying to do the same in VC++, but I dont know how. I don't have much experience with C++ in general.
I have:
TestProject1
TestProject2: I need to use classes that are in TestProject1 here.
I tried adding TestProject1 as reference of TestProject2:
Right Clikc on the TestProject1-> Properties -> Common Properties -> Framework and References -> Add New Reference -> Selected TestProject2
But this results in an error, because TestProject2 is not built as a lib.
From what I can see only a list of obj files are generated.
What is the correct way to reference TestProject2 in TestProject1 so I can use its classes?
Update: How I solved it
I solved the issues by following SOReader instructions, but I added the lib in a different way:
First I changed the TestProject1 project type as SOReader indicated (Right Click on TestProject1 project -> Properties-> Configuration Properties -> General-> Set Configuration Type to Static library (lib)
Add reference to TestProject1 in TestProject2 -> Right Click on TestProject2 project -> Properties-> Common Properties -> Framework and References -> Add New Reference -> Select TestProject1
It's not so easy as it is in C#.
You must have TestProject1 build as static library if you want to simply include it to another project. After this you go to dependent project properties and add lib file to linker and headers folder for headers lookup.
Assuming Dll has its include .h file in its root folder (which actually should not have) you simply add an entry to Additional Include Directories to point the place where Dll root folder is.
Now you can just write #include <theheaderfile.h> in you cpp file in Main application to reference exported functionality.
Here are few others locations in msdn that might help: import/export, static libraries, hpp vs h

How are project interdependencies managed in MS Visual C++?

Probably a pretty fundamental question. When developing a single-project-solution in MSVC++ everything makes a lot of sense, every file is visible to the compiler. When moving to a multiple project solution, none of the interface elements governing project dependence seem to make sense (coming from a .net background.)
For starters it appears setting up project dependencies with that terminology seems to only imply what order the projects are compiled in. There is no more function attached to the definition and addressing objects or methods of one project from another will not work. #including the headers of the dependency doesn't seem to work either, so the dependent project cannot see the files of its dependency. Copying a link of a header from one project to another doesn't work either, where for two projects under the 'Header Files' section, the same file is referenced in both locations. Even with this header references do not work and the files are unconnected. The only way of creating a functional dependency is to add the dependency's paths to the linker/compiler search path of the dependent or worse, simply copying the files of one project to another.
Either I'm missing something or the .NET Visual Studio IDEs have succeeded at what the VC++ IDE has badly failed at.
Edit:
For the sake of asking a specific question, take the following steps for creating a solution in VC++ and I ask if the missing step(s) can be filled in:
Create empty DLL project inside new solution.
Create method in DLL project and compile.
Create new empty executable project.
Create main method in new project.
...
Have main method call function in DLL project.
Preferably fill in the missing step(s) with the most most modern/industry standard/best practice method that best maintains project modularity as intended.
From this I would expect to independently be able to extrapolate and create classes, enumerations etc. in the DLL class and access them all in the executable project, so long as I can find out how this is intended to be done.
In step 2, as per the usual C++ rules, declare the method in the header. Read up on __declspec(DllExport) since the default is that methods are internal to the DLL.
In step 5, as per the usual C++ rules, include the header. Visual C++ needs to know where the header is coming from, so you need to reference the source project. Details vary between Visual Studio versions.
In step 6, you call the method in the normal way. Since it's now declared as __declspec(DllImport), the compiler will leave it to the linker, and the linker will get it from the correct DLL.

How to specify the generated jar path in m2e

I use m2e. I have dynamic web project A, java project B and project A is dependent on project B. I want the JAR file that is generated in the target folder of project B to be moved to the WebContent/lib of project A. What is the simplest way to achieve this?
1) Enter Project B as dependency in the POM of project A. That ist the prerequiste for maven to resolve the dependency from A to B.
2) In the Eclipse project preferences of project A make sure the in the section "maven" the option "Resolve dependencies form Workspace projects" option is enables (should be by default.
Usually, this should do it

Visual C++ link generated objs from referenced project

I have multiple native C++ projects, one of them is a dll project, and I want to test it.
The problem is that the generated .lib file only contains the definitions for the public interface of the dll, but I would like to test the projects internals.
Since referencing the project does not work (it only works for static libraries) is there a way to add the the generated objs directly in my testing project ?
Also I know that I could include all the source code files in the referenced project. But is there a way to do this considering that the referenced project might change. I would like a method that does not force me to mange each file manually.
I have done some research and I found some answers like in this question:
Reusing object files in Visual Studio 2005
but since I have many small classes exposing all the classes is a bit to tedious.
I found that I can set a Pre Link Event in the Build Event menu.
This allows me to use the following command:
lib -out:"../Debug/tempAllDllObjects.lib" "../MyDLLProject/Debug/*.obj"
now, even if my project is a DLL project I have an additional .lib file that contains all the objects in my project. All I have to do is reference the newly created lib file. This way I can link with all the objects in my DLL project even if they are not in the public interface.
As a note the command can also be set on the DLL project as a Postbuild Event this will increase the efficiency since now the lib file is only generated when changes occur.

Share source code between projects [VS2008,C++]

How can I share source code between 2 projects in MS Visual Studio 2008 (I'm programming in C++)?
In my case, I have the code for the main game project and now I want to make a simple model editor that uses the game's code, so that whenever I change/add some code in one project it will be updated in the second one.
A common method for doing this, (you'll see it everywhere in open-source packages), is to bundle all the headers into an 'include' folder and all the source into a 'source' folder.
Now in whatever project needs the code, you go to, 'Project Properties->c/c++->General->Additional Include Directories'. Then add the path to the 'include' directory. Finally, add the source/headers to your project, now both projects reference the exact same files, which are in a nice tidy shared location.
You can also build the shared code as a static library or better yet (IMO) a DLL. This involves creating a new project, and learning a little bit about the linker in VS 2008, but really nothing too complicated. This also has the advantage (in the case of a DLL) that the two projects don't re-compile the same code, but rather it is compiled once and used twice.
You can move the required classes into a separate library project and then references this from the second project. Any changes will be automatically picked up.
(I'm not a C++ developer, however the above works for C# projects, I would assume it works for C++ projects too)
You basically have two options:
Create a static library. In this, all the code in the library will be exported and visible to who ever links to this library.
Create a DLL: here, you can define what classes and methods you would like to export and use those.
Lets say you have a class called classA which is defined in classA.h and implemented in classA.cpp and you want to use this same class from two different applications (application B and application C).
Using method 1, you would create a static library by going to file->new win32 project and in the box that pops up, choose application settings and make it a "Static Library". Then in this static library you add both your classA.h and classA.cpp.
To use this static library in application B or C, goto the references and add a reference to the static library project that you just created. then include classA.h in your application (don't forget to set the additional include directories path) and you are good to go.
The approach is very similar for a DLL as well, the difference here would be that you can choose what parts of your code in the DLL are exported (ie visible to outside callers).
From an overall point of view:
With the static library approach, your code will be compiled into both the applications.
With the DLL approach, there will be just one copy of the shared code (in the DLL which will be a separate file) and this will be loaded as required.

Resources