I have three projects in a visual studio solution in which the code consists of lots of template code. This therefore means I can't compile the code into a DLL or static library because then I can't use the template classes with new types anymore. One of the projects at the moments acts as the 'core' and the other two need to use the headers (by additional include directories) and source files of that core project and use its template classes. I want to find a way to automatically pass the source code files of that core project to the linker in the other projects so they can use the source code. I could copy the files but then im going to be updating the core lots and I do not want to keep copying and adding files to the other two projects. How could I do this? Im not using C-Make, only visual studio and I wish to keep it that way.
Related
I have 2 projects in 1 solution both projects contain cpp/h files I am trying to have a "Base" project where the "Main" project will contain the files from the "Base".
"Base" configured as Utility project hence does not actually compile anything, of course since it does contain cpp files that even if I use the VS reference tool to link the projects together VS still refuses to compile the cpp files from "Base" hence I get linker errors when trying to compile the solution, one would simply suggest that I reconfigure "Base" to be statically linked however since I would prefer to use different config files (header files) on each "Main" project that I use in the future, static linking is not viable.
Another way of asking is can I have 2 projects that behave like a single project?
I would happy to hear suggestions without using CMake.
Solved using a “Shared Items Project” more info here https://devblogs.microsoft.com/cppblog/cross-platform-code-sharing-with-visual-c/
I have a large project and it takes quite a lot of time to compile the whole thing. A small change in a header file will result in building the whole project again even though it doesn't affect most of the other components. Is there a way to use premake5 to build source files in the project to its own library file (preferably .lib files) without creating separate projects for all of them?
Thank You!
No, that is not possible. Premake is designed to generate projects that can work with a variety of different toolsets, and most (no?) IDEs support that workflow.
How do I share a precompiled header across multiple projects in the same solution in Visual Studio 2019?
As a requirement, I do not want to create a project just to compile the precompiled header, which then is included and referenced by other projects.
I know the feature simply didn't exist in the past and you'd have to use a pre-build event to copy the actual output file for it to each other project. Since VS has changed a lot over the years, I figure it's time to reask this question because there's no information immediately available on google.
I was looking at this question but it seems that it isn't viable in a production environment.
Or is there something better using C++20 modules?
As far as I concerned, you should need a SharedPCH, it is building the pch and the static library. When ConsoleApplication projects reference the SharedPCH one, the build will automatically link the SharedPCH’s static lib, but several project properties need to be changed as well. As those properties need to be changed similarly for all projects, I suggest you could create the SharedPCH.props and CustomBuildStep.props files and imported them to your projects using the Property Manager tool window.For more details I suggest you could refer to the Blog
Visual studio doesn't support native projects as it supports .NET projects. In the sense that when for example creating a static(.lib) library. Including of the static library, and the directory containing the headers, has to be done manually.
For one project this isn't some much of a problem. But if you're like me managing several projects. A lot of which are somewhat depenendend. It becomes a huge hassle to manage all of it.
I was wondering if there is any official 'microsoft approved' approach to this. And if not, what is the best way to deal with this situation. Supposing the following conditions occur:
several static libraries(.lib) projects. Which are included in several solutions
several dynamic libraries (.dll) projects. Which are included in several solutions
multiple applications using the same libraries(both dynamic and static), in one solution
My personal solution to the problem is as follows.
Every project generating a binary builds to:
$(SolutionDir)build\$(Configuration)\`
Every project generating a static library builds to:
$(SolutionDir)build\$(Configuration)\Libraries\
The intermediate directory for all projects is:
$(SolutionDir)build\$(ProjectName)\$(Configuration)\
And runs the following pre-build command:
Copy /Y "$(ProjectDir)*.h" + "$(ProjectDir)*.hpp" "$(SolutionDir)build\$(Configuration)\Libraries\"
Advantages of this system include:
All the project directories stay free of builds (useful when using source control). And all the binaries are in one place.
Setting additional include directories is never required when using outputs from other projects in the same solution. A dynamic library doesn't have to be added at all. And all that is required to include a static library is adding it to the Additional Dependencies field under:
Configuration Properties->Linker->Input
Drawbacks of this system include:
Since all the header files are copied, the risk exists of accidentally editing those. Which results in loss of work, when the copying occurs again.
Since the settings are per project, they have to be set for ever project
The libraries are built separately for every solution
I am looking for detailed steps to create a second Static Lib Project in Visual Studio 2010
that my first project will reference.
This project will be in source control and used by others so the referencing needs to be able to work on all folder structures. (if possible)
I have done this before but have had problems recently. I mostly end up adding random references to everything and every folder in my project until it works as I do not know the correct steps to accomplish it.
This will be my projects folder structure
<Whatever Structure>/MyProject/MainProject
<Whatever Structure>/MyProject/SecondProject
<Whatever Structure>/MyProject/MyProject.sln
I need my SecondProject to be built as a Static Lib library.
Inside my FirstProject I would like to reference files from my SecondProject as
#include <SecondProject/<filename or class or namespace>
As I said above Detailed Steps to accomplish this would be greatly appreciated.
I have searched many other posts but most just pertain to Header Files or they are half the steps.
Thank you.
#include is solely used for headers. This is parsed at compile time. Since you want to use headers from <Whatever>/MyProject/SecondProject as just SecondProject/, obviously <Whatever>/MyProject/ must be among the include directories. Probably the best way to specify it would be as just ../, because that means you don't have to hardcode <Whatever>
After compiling, the next step is linking. The easiest solution here is to go the the property pages of MainProject, Common Properties > Frameworks & References, and use [Add New Reference...] button. Linking will make the compiled functions inside the .lib available.