Use a "User Macro" in .vcproj RelativePath - c++

Inside .vcproj files There is a list of all source files in your project.
How can we use a macro to specify the path to a source file?
If we do this:
<File
RelativePath="$(Lib3rdParty)\Qt\qtwinmigrate-2.5-commercial\src\qmfcapp.cpp">
</File>
The compiler cannot find the folder:
qmfcapp.cpp
c1xx : fatal error C1083: Cannot open source file: '.\$(lib3rdparty)\qt\qtwinmigrate- 2.5-commercial\src\qmfcapp.cpp': No such file or directory
As you can see, our project compiles in several source files from QT. QT lives inside a folder of external libraries, and we don't want hardcode the path from our project to that folder (we have a very large solution)

The normal solution is to include the 3rd party includes, libs and source in source control with your own source, so you can track changes to your 3rd party dependencies with your source.
If this is the case, you should be able to use a relative path from each project to the 3rd party source files.
However if your solution is big, and it has project complicated settings you should look at CMake, even if you are only building on windows. CMake enables you to describe your build environment with common settings specified in only one place. More complicated cases can be handled with variables and macros. Then it generates your visual studio projects, or makefiles from this description. We introduced it to support a unix port, and now I use it for windows only development too.
VS projects are really clunky to use, opening and closing dialog boxes, setting things for debug and release. Each project with its own copy of the settings, but mostly the same as all the other projects.

If you add an existing file from a different drive, you'll notice an absolute path is used.
At least for v8.00, macros do not seem to be expanded. I tried VC, Ant, and OS macro forms - none worked.
There's always the sysinternals' junction option, a mapped network path, or a .lib with a macro spec set into the project/global source, include, and lib paths. Even with the lib package, you should be able to step into the source.

Try setting an environment variable for 'Lib3rdParty' to the appropriate relative path snippet.

..it should be mentioned that using property sheets gets rid of a lot of the clunkyness though

Related

Build failed with no stated reason on Segger Embedded Studio after adding custom source files

I'm modifying a simple example project (blinky) from the nRF SDK. I added a header file and a .c file in a new folder inside the project directory then added that path ./lib to the common preprocessor user include directories. I then included the header to main.c.
I can compile the new library on its own but when I build the whole project, I get Build failed error with no stated reason to follow up.
Here is an image of that:
Does anyone here know how to beat this?
I haven't used Segger Studio specifically, but it seems to be the CrossWorks IDE underneath.
In CrossWorks, you have to do the following:
Download & install all relevant libs from inside the IDE, under Tools -> Packages -> Install packages. Grab your specific target MCU as well as any specific boards or libraries you'll be using. In case some needed lib is missing here, you will get very weird errors.
In the project, click on the project name itself in "project explorer". Then in the properties window, check settings (this is a bit different in different versions of CrossWorks, might have to right click and pick properties in older versions). Under "user include directories" you should have something like this:
$(DeviceIncludePath)
$(TargetsDir)/NameOfMCU/Include
$(PackagesDir)/CMSIS_4/CMSIS/Include
$(ProjectDir)/NameOfDirectory
Where "NameOfMCU" is the name of the MCU family used, CMSIS should be there in case you are using any ARM, "NameOfDirectory" is the name of your custom directory (you can add several).
Also, get the debug build working first, before switching to release build.

How to link against third-party libraries (.lib) in Team Services build of GitHub repo?

Adding the libs in the source control and adding the correct paths to the Visual Studio solution does absolutely nothing. My local project compiles fine, but the online CI compilation fails every time.
LINK(0,0): Error LNK1104: cannot open file 'xxx.lib'
I've tried any possible combination of relative paths and settings that work in VS2015 at this point. The documentation is really scarce and all I was able to find was some ambiguous advice around TFS project files (which I don't have, because the repo is a remote GitHub repo) and workspaces (which I don't know how to set up). I'm also aware of this "NuGet" package thing, but I'd rather not have to construct an entire dedicated package for a couple of library files that I already have in the directories.
I can't believe there really just isn't a simple setting to include third-party SDKs though. Even including the libs in the source control is bad practice, so I might have missed something pretty big here. Any advice?
Following is my folder structure in local and VSTS:
In my local machine, lib file is placed in "test" folder under "MyCon" project folder:
The folder structure is almost the same after added into source control:
Path in Linker:
Settings if the lib file is in solution folder:

git and visual studio 2010 express

I have used visual studio 2010 express for a while and have played with some extensive projects for quite some time. Since i'm nearing 50-60 files and thousands of lines of code, i've decided to do some source control for everything so that the project is more easily updated and accessible between all my devices, while also being back up.
I have used git before and am comfortable with it, but now when i made the commit and pushed it to a remote repository on bitbucket.org, i found that the .vcxproj files, while still retaining their correct file structure, also retained the include and lib directories for the device it was pushed from, meaning that when pulled down to another computer, those include/lib directories would be looking in the wrong directories, meaning i have to revise all of them every time i pull/push.
My question, Is there anyway i can push files to the repository such that the solution keeps the folder setup, but not the include and lib directory settings?
Edit:
After some research, i went looking into these so called property sheets in visual studio which are files that can be added to your project. The settings you set their take precedence over the settings of the project, but then the snag there is, if you add the individual property file to the project and then push the the .sln file, and the various .vcxproj files without that .props file, and then someone else clones from the repository, it won't open because it apparently requires that props file.
What i would like along these lines is a default .props file in the remote repository that, when cloned over, is no longer tracked, and then that user can just edit it for themselves. I don't know enough about git thought to make this happen. Does anybody have an idea?
I'm not sure what your problem is exactly, but here's my understanding:
Your project files contain absolute paths (e.g. "C:\myproj\include"). Replace these with relative paths (e.g. ".\include"). The "$(SolutionDir)" variable helps: if your solution file is C:\myproj\myproj.sln, then "$(SolutionDir)include" is the same as "C:\myproj\include". You can change the include and library directories in Project Properties > Configuration Properties > C/C++ and Linker, respectively.
Your project requires third party libaries - such as boost - and these are outside your project, say C:\boost. Unfortunately Windows/VS doesn't have a standard location for third party libraries, so you can either:
Include the library in your project. This is perfectly fine for small libraries, but it's not something you'd want to do with something like boost, which is both big and tends to be used widely.
Mandate that all devices set up these libraries in the same location, e.g. C:\sdk
Use an environment variable, like $(SDK_DIR) in the project, and all devices must set this environment variable.
Let me know if this helps.
What you're after are git's smudge and clean filters. You'll have to write a script for the cleaning, but sed'll probably do the job just fine, you won't need real xml parsing.

folder structure in Visual C++ when there are many projects depending on each other

say I have a sln which contains 10 projects(named proj1 to proj10), and proj1 is the default project which generate the EXE file.
My problem is: how to place the 'include' folder?
I mean if proj2 uses proj3(that is including its header file and linking its lib file), how to place the 'include' folder?
there are two approaches:
place all header files and lib files in a different root folder which is in the same level of the project
make every project self-close, and the other projects who want to use this project should take care of the include-path and link-path. Of cause we should give a rule to the layout of every project(e.x. every project MUST have a 'include' folder and 'lib' folder in the root folder)
any suggestion?
thanks
When it comes to Visual Studio, I don't like either of the two approaches you suggested, although mine is most closely related to your Option #2. The way I like to organise it is like this:
<SolutionRoot>
<Project1>
project1.vcxproj
someheader.h
somesource.cpp
<Project2>
<Project3>
<Project4>
<Project5>
application.sln
In case that's not obvious, that's a quasi-directory listing showing some project folders and the base solution file.
All new projects are just added to the solution using Visual Studio's default settings. Trying to go against this and making projects work like Linux projects (lib, include, src etc) just ends up causing you grief, so don't do it.
Now, I set my "additional includes" path on every project to $(SolutionDir). Then if I want to include something from Project1:
#include "Project1/someheader.h"
The advantage of this is you don't clutter up your 'additional includes', so it's easy to see at a glance what external includes a project has.
As for linking to lib files, why not take advantage of Visual Studio's project references feature. Honestly, your life will be easier. Simply hook it up so that Project2 references Project1, etc... Then you don't have to worry about libraries and linker paths. You only do that for toolkits that are outside your solution tree (eg distributions such as libpng or openssl).
Again, you free up that setting so it only shows linkages outside of the solution. The other advantage is that your build order is implicitly defined if you use references.
I would go with the 1st solution. it make the project settings simple. As the C++ projects we worked on, we always put the header files together.

Project files in KDevelop

I am trying to use KDevelop to write a cmake based simple application. KDevelop created two myProject.kdev4 project files: one in the project folder and one in .kdev4 hidden subfolder. Both are non-empty. Which ones should I check in? How can I make kdevelop use just one project file (and preferably not use hidden folders)?
The .kdev4 file is used for kdevelop specific information (It mainly only tells KDevelop to use the CMake project manager). The folder includes user specific configuration (If you are familiar with Visual Studio, it is like the .user files).
Usually only the CMakeLists.txt files are needed as they should have all the relevant generic data. You can throw in the .kdev4 file so that you don't need to 'import' the project through the CMakeLists.txt on another machine. But the .kdev4 folder should stay in your local machine, as you don't want to mix user's configurations.