Can Visual Studio build Solutions without a Compile step? I have a Pre-Build event that builds a .obj library and I just want the Visual Studio .sln to link against it. If I put a dummy Main.cpp file in the Solution, it will Compile that, then link against my Prebuild Event output. Without this dummy file though, the Linking never occurs.
I could put a Post-Build event Link in there, but the default Linking step has a lot of (Macro?) values that expand to directories that I would not want to try and mimic. I just want this VS Solution so it's easier as a link-only build script. The Pre-build event assembles some fasmg assembly sources.
Much appreciated..!
(This may be a duplicate question, but I could not find the duplicate. Will remove if so.)
Related
Does executable file get created if Build Solution fails with some error in Visual Studio for c#?
Does Build Solution has to succeed in order to create executable file for the application in Visual Studio?
Thanks,
Ilya
This is actually a good question. The answer is: it depends.
There is a difference between "build" and "compile".
The "build" does a lot of work, like finding all the source files, resolving any references to assemblies and NuGet packages, and so forth.
The "compile" takes all those as inputs and produces an output assembly.
If the "compile" fails, then no output is produced (e.g. no .dll or .exe file).
However the "build" may fail after a successful "compile" (for example, if a post-build step fails) in which case the output file is created even though the build fails.
In 99.9999% of cases, a failed build means no output was produced, but it is not always the case.
I have a C++ project in Visual Studio 2019. How do I find all cpp files with compiler errors? When I build solution, the compiler hits a file with error, then VS will declare the project build failed, and proceed to other projects. So I get only one of the errors.
When I use makefile to build, I could attempt to compile all modified files, then mark all the failed one. Can't Visual Studio do the same?
========
What I mean is that, I have a large project that has files a.cpp, b.cpp, c.cpp, in which I know b.cpp and c.cpp have errors. When VS builds the project, it detects error in b.cpp, then VS will not try to compile c.cpp. The build output is:
------ Build started:
a.cpp
b.cpp
"xx\xx\xx\b.cpp": error xxx: xxx
Done building project "project1.vcxproj" -- FAILED.
Building stops before compiler touches c.cpp.
And I found that this only happens in my large projects. In my small project VS will invoke compiler on all cpp files. The usual scenario is when I refactor some headers, I need to build the project again and again, fixing one cpp file at a time.
Build the solution "F6", then look at your error list Menu View -> Error List (alternatively, Ctrl + W, E). Then make sure under your error list tab, make sure "Entire Solution" is selected. This will list all of the compiler known errors and warnings within your project. As far as using makefile, you would have to debug within your Makefile specifically.
To answer your second question, unfortunately, there is no such
thing as a makefile debugger to examine how a particular rule is being evaluated or a
variable expanded, etc. Instead, most debugging is performed with simple print statements and by inspection of the makefile itself. This isn't handled by VS.
I have an F# solution in Visual Studio 2015 (Enterprise) with several projects in which control various pieces of hardware. In each project there are .fsx script files which demonstrate how the API is used to do basic tasks on the hardware. If I make changes to the API and rebuild, then I correctly get the Error List populated with all the errors from the compiled .fs files, but since the .fsx aren't required to make the .dlls, then I don't get errors from them when I change the underlying API.
If I open each .fsx file individually in the editor, then I get the Error List populated for as long as the file is open, but I'd like to have them block the build and all appear, rather than having to go through each in turn, which takes quite a while. Is there any way to do this?
Thanks in advance.
The suggestion from Fyodor would certainly work - but I guess building a custom step for the build system might not be the easiest thing to do!
A simple alternative would be to add a separate F# project that contains the fsx files and compiles them - then you can just ignore the result of the building the project.
When you add fsx file to project, it is not compiled as part of the project build, but you can change that by choosing Compile as an "Action" in the properties window in Visual Studio. Alternatively, you can just edit the fsproj file:
<Compile Include="some.fsx" />
When editing the file by hand, you can also make it point into another folder:
<Compile Include="..\OtherProject\some.fsx" />
Is it possible that I can just compile all CPP files under a project and without linking etc. the project?
The only way I know to do this is by specify the /c switch when you compile the code. Unfortunately, this option is not available from within the Visual Studio development environment, so you'll need to build your code on the command line by calling cl.exe directly. To make things easy on yourself, use the Visual Studio Command Prompt to do so.
Not sure if it's possible to get MSBuild to do this, the documentation is unclear whether the limitation is Visual Studio itself or if it's a limitation of MSBuild. I haven't actually tried for myself.
Alternatively, you can build individual source files from within the IDE by pressing Ctrl+F7 (at least, assuming the default C++ development settings). If that fails, it's also available as the "Compile" option located in the "Build" menu.
I'm not sure whether this will do what you need, but may be worth a try: create a project for an executable (rather than a library) and include all cpp files in it. Add a main() function that just returns zero. Set the C++ optimisation option to 'optimise references' (/OPT:REF). This may just compile all the cpp files but effectively ignore them during the link stage since none of them are referenced by the application.
You don't say why you need to do this - is it because linking takes a huge amount of time?
I'm using visual studio 2010, Qt add-in etc all ok, then create new project using Qt add-in... when doubleclicking *.ui (the actual form) file in VS it opens Qtdesigner, then I put some controls on, but that does not change my code at all :/
Qt form is changed it contains those controls but source files are the same as before even after building my project.
I'm I missing something?
I think Qtdesinger shoult put some code for objects which I created using Qtdesigner.
cos without that we must write all the code as if there were no Qtdesigner so Qtdesinger is useles in Visual studio, the same thing we could just do by hand-coding a form interface.
thanks alot.
EDIT:
OK
I've copied this from Qt site:
You are referencing objects from a .ui file...
The Visual Studio code model parser only parses C++ sources, meaning
that widgets or objects defined in .ui files will not be accessible.
To workaround the problem, the Qt Visual Studio Add-in automatically
generates C++ code from the .ui file by saving the file and running
uic on it. This step is done everytime the project is built. If the
code completion does not work, try to rebuild the project. It is
possible that you have to wait some time, before code completion fully
works after updating an .ui file. For more information, you can refer
to the Modifying Project Properties section. It still does not work...
You should refresh the code model, Intellisense. This is done by
opening the solution explorer, invoking the context menu of the
project and activating the item Update Intellisense.
now it looks that I'm having such problems but this does not help at all, update intelisece. I can't see such option in visual studio,
it looks my visual studio add-in isn't working.
it says "You should refresh the code model" Woot? can someone explain me how to do that please.
here are some output warnings when building my project:
Warning 1 warning : No resources in 'C:\Users\Admin\documents\visual
studio
2010\Projects\VisualStudio\test\test.qrc'. C:\Users\Admin\documents\visual
studio 2010\Projects\VisualStudio\test\RCC Warning 2 warning LNK4099:
PDB 'vc100.pdb' was not found with 'qtmaind.lib(qtmain_win.obj)' or at
'C:\Users\Admin\documents\visual studio
2010\Projects\VisualStudio\vc100.pdb'; linking object as if no debug
info C:\Users\Admin\documents\visual studio
2010\Projects\VisualStudio\test\qtmaind.lib(qtmain_win.obj)
I'm going to explain a little bit how things work and the relationships between the files, and hopefully this will solve your problem.
When you edit the ui file using the designer all changes are made to the ui file itself. Then when you build a couple of things will happen.
First... a custom build step will be run on the ui file. This build step runs "uic" as Macke said, and will generate a file called "ui_thenameofyouruifile.h". Where this file is located depends on your project settings, but if you look in your project you should see a folder called Generated Files in your project.
If you look in there you should see the newly generated file. This is the code that is "changed" when you make changes to your form. Now if this file is not updated, or does not exist at all, then somehow your project settings got messed up. In this case I would remove your .ui file from the project and re-add it. The add-in should do it's magic and add all the stuff you need. Build again and it should work. (I assume that is probably your problem)
The second thing that should happen when you build, is that the class that uses your ui file should recompile. Generally when you create a ui file, you also create an accompanying .h and .cpp file. This is where we do any of the fun logic that we might need in our window. The Qt designer will never ever change this class.
In the header file we refer to the ui file by doing this:
namespace Ui {
class thenameofyouruifile;
}
#include "ui_thenameofyouruifile.h"
and then we add a member variable
Ui::thenameofyouruifile UI;
There are a couple of ways to do this, but basically that's the idea. The add-in is supposed to configure your project so that the directory where the generate files go is included in the "additional include directories" in your project settings, but that is another place to check to make sure that your code is really linking with the correct generated file.
If Qt Add-In installed properly, it should generate the custom build step for Qt related files (.ui or moc file). I have not tried Qt Add-in with VS 2010, but with VS 2008 it's okay.
The work-around for your problem, you need to add manually the custom build step for each ui file you have in the project. To do this, the step is:
Right clicked the ui file, and click the properties (I'm using VS-2008 to do this step, and expect this may not be much different in VS 2010).
Under custom build step, add this in the command line: "$(QTDIR)\bin\uic.exe" -o ".\GeneratedFiles\ui_$(InputName).h" "$(InputPath)"
And add this under output: ".\GeneratedFiles\ui_$(InputName).h"
And this under additional dependencies: $(QTDIR)\bin\uic.exe. Then click apply / ok.
If this is done, the ui file is compilable, (when you right click it, it can be compiled), so when the ui file content change, the new ui code (.h) file is regenerated.
Alternatively, to reset the VS project file (vcprojx) you can create Qt project in Qt creator, (or if you have already one), and then convert the Qt creator project (.pro) into vcproj using this command line:
qmake -spec win32-msvc2010 -tp vc
This will create the vcproj with the proper custom build step for you (in case you have many ui files, then you don't need to do the first approach).
If you've created a Qt widget using the new class wizard, stuff should work as expected.
I.e. your .ui files are compiled by Qt's uic to .cpp files, i.e. you need to build your project to get these changes into the ui-class.
So, the .ui files should be added to the project, and have some special build rules that invoke 'uic' on them. If that's not the case, try and re-add them to your project (that way, the Qt add-in should configure the build rules)
Normally, you have a class that inherits QWidget which then includes the compiled cpp-class, by one way or another, usually as a member variable (but inheritance is an option too).
Adding an .ui-file straight up should work too (if you're in a Qt project, which you are..), but obviously something is wrong.
Does the example projects work as expected?