Building/Running Google Test - c++

I am trying to build and run Google Test but encountered some issues.
Any help greatly appreciated.
I used CMake 2.8 (with UI) to create .sln and .vcproj files in the D:/MyBuild
directory (as mentioned in the README file of google test).
However, when I try to run the .sln file in the MyBuild directory,
here is what I get (image):
Also, here is a screenshot of the CMake which I used to
create .sln files and .vcproj files in the D:/MyBuild directory.
ps. One thing I noticed is that README was giving instructions how
to use non graphical version of CMake (e.g., 2.6) to install
google test, however I used one with user interface - maybe
I did something wrong there?

You appear to have successfully built gtest's libs in Debug mode. However, by default the .sln doesn't contain any executables, so you can't actually run anything.
If you select the checkboxes in the CMake GUI for gtest_build_samples and/or gtest_build_tests and hit "Generate", then the Visual Studio solution should contain some executables.
From memory, these don't build cleanly, but I don't have MSVC 2010 to hand, so I can't be sure.

Related

Missing libgcc_s_seh-1.dll starting the .exe on Windows

Intro
I have a CMake-based C++ project. Until now I build and ran the project via CLion. Everything worked fine until I tried to run the .exe-file directly (not via CLion).
Problem
When I navigate to the cmake build directory in order to start my program via the executable file, it fails with the following message in the popup: Cannot continue the code execution because libgcc_s so-1.dll was not found. Reinstalling the program may resolve the issue.
I have the following questions
If I interpret the error message correctly, then this dll is missing on my computer. So I ask myself, why does my program still work when I start it via the development environment (CLion), although the error message expressly states that the source code requires this dll?
Is it the fault of my application/source code that the error appears or rather the current state of my computer? If the former, how can I prevent this error from appearing for other users?
What is the best way to fix this error? It's obvious that I need to download this dll, but where is the best place to put it (which directory and environment variable to use on Window)?
Which source is trustworthy to download this dll? I don't want to download any malware under this dll-name.
Optional: What kind of library is that? What functionalities does it offer?
Additional information
I use CMake as my build tool, CLion as the IDE and MinGW as the compiler.
What I have did so far?
I made sure it still works through the IDE.
I found this dll does not exist in the MinGW installation folder.
I searched the web for more information. Unfortunately, there are only pages unknown to me that only offer the download of this dll. That doesn't satisfy me.
I found the cause of my problem: I had two MingGW installations on my machine. Once the installation that comes with CLion and a separate one. The latter did not have the required dll. However, CLion used its own installation, which in turn owns the DLL. So the solution was to remove the separate installation and include the path to the CLion installation's bin/ directory in the PATH environment variable.
This file is part of MinGW-w64 when using SEH as exception model (as opposed to Dwarf or SJLJ). You need to distribute the .dll files your .exe file(s) depend on in the same folder as the .exe file(s).
If you don't have that file, then you probably have been using libraries compiled with different versions of GCC/MinGW(-w64). I recommend building everything with the same compiler to ensure stable binaries.
Tools like Dependency Walker can help you figure out which .dll files your .exe file depends on.
Or use the command line tool copypedeps -r from https://github.com/brechtsanders/pedeps to copy the .exe files along with it's dependencies.

Building a Qt executable in Visual Studio 2017

I made a Qt Application in Visual Studio and it works when I run it in the program. However then I build the solution and try to run the executable errors pop up that certain .dll files are not found(QtWidgets.dll, QtCore.dll,QtCored.dll etc.). How can I fix this?
To make your application ready for deployment, you can use windeployqt.
It is a commandline program that comes with Qt and collects all the required dependencies of your executable. Go to your QTDIR/bin/ folder and run this command
windeployqt <path-to-app-binary.exe>
It will scan your binary and copy everything that is needed next to it. For further details, have a look at the documentation.
Well, you have two options:
If you want to distribute your application, you have to copy the required DLLs to the folder where your executable is. You can do this either by copying them manually or you write a script for this. The DLLs are in the binary folder of your Qt installation, e.g.
Qt\5.12.2\mingw73_64\bin
Add the above mentioned folder to your system PATH variable, then the DLLs should be found by your application.

Compiling Qt projects in Qt/MsBuild format without Qt VS Tools installed

I have many Qt projects in Visual Studio, using the new Qt/MsBuild format provided by the Qt VS Tools. When compiling in my development environment, where I have the Qt VS Tools installed, everything works flawlessly (compiling from IDE and from command line).
We have a computer dedicated to nightly builds, where only the compiler and msbuild are available (no IDE nor Qt VS Tools are installed).
When compiling the projects in such computer we get an error:
QtMsBuild: could not locate qt.targets, qt.props; project may not build correctly.
Followed by several lines such as
e:********\Preferences.h(4): fatal error C1083: Cannot open include file: 'ui_Preferences.h': No such file or directory
(Project contains Preferences.ui).
How can I solve such errors when Qt VS Tools are not installed?
One solution provided by the Tools' creators is to copy %LOCALAPPDATA%\QtMsBuild into each project directory. But we are talking about hundred of projects. Doing manually, and more on, pushing them as part of the project itself doesn't sound very elegant.
One option would be to add a pre-build step that copies it from a common place into each project (and adding a **/QtMsBuild line to each .gitignore file). Again, looks like too much work.
When looking at the .vcxproj file for the Qt project you find this fragment (the reason for the solution provided by creators):
<PropertyGroup Condition="'$(QtMsBuild)'=='' or !Exists('$(QtMsBuild)\qt.targets')">
<QtMsBuild>$(MSBuildProjectDirectory)\QtMsBuild</QtMsBuild>
</PropertyGroup>
So, the simplest solution (without being able to install the tools), is to copy the %LOCALAPPDATA\QtMsBuild directory (from a system with the Tools installed) into the night computer (in any common place, but I decided to keep the location used by the tools) and then setting an environment variable:
set QtMsBuild=%LOCALAPPDATA%\QtMsBuild
PS: do not add double quotes to the variable (at least I had problems with them, so VS couldn't find the files).
Update 9-14-2020
I'm not sure on which version it started, but Qt projects created with (at least) the v2.5.2 Qt VS Tools fails to compile indicating that the Qt version has not been set. To solve so, you can
Copy the Registry entries from a computer with tools installed, located at HKCU\SOFTWARE\Digia\Versions.
If you will rely on a single Qt version (but that may be update globally for all projects), you can skip the Registry and just set the Qt version of all projects to $(DefaultQtVersion) (the same used in past project formats) and define an environment variable pointing to the directory of the version: set DefaultQtVersion=c:\Qt\Qt_5_15_0\Win32, for example.
I had problems in my case setting up $Env:QtToolsPath="$Env:QT_PATH\bin" fixed the problem. (It was not finding qmake for some checks). This, I think, is required when using QtMsBuild v3.3
Not sure if this info is 100% correct but may help someone.
For me to use MsBuild with Qt using QtMsBuild (not installing Visual Studio and/or VS plugins), I need to set up:
Example (PowerShell):
- $Env:PATH="$Env:MSBUILD_PATH;$Env:PATH"
- $Env:QT_PATH="D:\BuildTools\Qt\5.15.1\msvc2019_64"
- $Env:QtMsBuild="D:\BuildTools\Qt\QtMsBuild303" #303 Against visual studio project version
- $Env:QtToolsPath="$Env:QT_PATH\bin" #Support QtMSBuild , At desktop is done by the plug in
- $Env:PATH="$Env:QtMsBuild;$Env:PATH"
- $Env:PATH="$Env:QT_PATH\bin;$Env:PATH"
I hit this and got it working.
I followed #cbuchart 's advice; but needed to do a little more/different.
So here is what I did. I copied %LOCALAPPDATA%\QtMsBuild to my repo. I then edited my .vcxproj with a text editor. I adjusted the line that looks like:
<QtMsBuild Condition="'$(QtMsBuild)'=='' OR !Exists('$(QtMsBuild)\qt.targets')">$(MSBuildProjectDirectory)\QtMsBuild</QtMsBuild>
To be:
<QtMsBuild Condition="'$(QtMsBuild)'=='' OR !Exists('$(QtMsBuild)\qt.targets')">$(MSBuildProjectDirectory)\..\QtMsBuild</QtMsBuild>
Depending on the relative location of where your project(s) are to the copied QtMsBuild directory you might want to adjust this. In my case the .vcxproj was in a directory one level from the directory that contains the QtMsBuild directory I copied.
Next in the QtMsBuild/Qt.props file I added the following:
<PropertyGroup>
<DefaultQtVersion>$(MSBuildThisFileDirectory)\..\Qt5.15.0\msvc2019_64</DefaultQtVersion>
<QtToolsPath>$(DefaultQtVersion)\bin</QtToolsPath>
</PropertyGroup>
That was added right after the opening Project tag in that file.
This was as #cbuchart mentioned something might have changed. I didn't do the Registry idea; but added those lines instead. I think it is possible to add them to a different file that gets imported before Qt.props if desired.
Now as for what this "Qt5.15.0\msvc2019_64" is; you'll need the tools, includes, libraries from a computer with Qt installed in order to build (also DLLs if your build needs to run the executable (i.e. tests)). This might be a lot of files so you can reduce it some if you know what you are doing. It might make sense to have these be put into it's own submodule or something.
After that it should uic/moc files and ultimately build (and run).
I got too. Maybe you need update your visual studio and then restart your computer ...
problem solved. reason: install 'qt vs tools' latest version but the visual studio
not support of it.

How can I use Visual Studio to work with large non-VS codebase?

I'm a fairly experienced C# dev, but have very little C++ knowledge. I have set my self a project to get a custom Firefox build running, and be able to control it from C# code.
I have got so far as getting and building the Firefox source, and creating a Visual Studio solution for the exe. This means I can now run via F5 in Visual studio. If I open a source file, I can set break points and have them hit.
What I'm not sure how to do, is load the entire source, as if I were working with a C# .NET solution. As I understand it, there are no project files with the Firefox source, as it is not windows specific source. I have followed an online example that suggests creating using 'project from existing code' option in VS, which resulted in VS grinding to a halt as there were so many files.
What are the steps to getting the code into an environment (preferably Visual Studio) that makes it simple(ish) to edit, debug and navigate the source code.
Note: Instructions I have been working through so far are here: https://cs.senecac.on.ca/~david.humphrey/writing/debugging-firefox.html
From you question, I beleive you are almost there. You have a working build ? That means you have :
A Solution File (*.sln)
A Project file (*.vcxproj or *.vcproj depending on yoru visual studio version)
With that in hand, what works best for me is this layout (adapted to your needs) :
Starting from a root folder of you liking, say MyProject
Create a new Empty solution there
Move the folder with your working build in a subdirectory, like MyProject\MyCustomFirefox
In Visual Studio "Add an existing project" and find your vcxproj file
In the same solution, create a C# project like you always do, in a directory at the same level as your FF build, like MyProject\MyFirefoxController
In short the solution file is pretty much alone in the root directory, and each project is in its own directory.
You will also need to adjust build options so that the output files (a DLL or an EXE) is seen by your C# project. While your are at it, make the C# project dependent on your Firefox build : it will instruct the msbuild to rebuild one if you change the other.
This will not work with the Express edition, I beleive. They are single language.
If you have a command line build path, which is creating a VS-debuggable executable, you could try adding all the source files to the project, but marking them 'exclude from build'. Then add a 'post-build step' to call the command line tools.
You may have to do a little more tweaking in the project properties to get the command line output recognized as the output to debug, but theoretically this could work.

How to build wxmathPlot for win32?

I downloaded the latest wxmathplot but the readme is a bit sparse with instructions on how to build on win32 platform.
Has anyone used this library for win32? Can someone point me to the docs or give some hints/advice on how to build for win32 targets.
We'll eventually use this for cross platform stuff, for now it is just win32 until we port our other code.
I presume I have to use CMake, but have not used it before and it is not obvious to me how to build this all - I have already installed CMake, but I am apparently too stupid to figure out how to build this library/samples.
Well, I managed to make an SLN file, but it was not obvious.
I use wxMathPlot. I simply add mathplot.cpp and mathplot.h to the MSVS2008 C++ projects that need to use it. This compiles and links without my having to do anything special.
Here is a partial answer - to get
CMake to build an sln file:
Well, unfortunately there is no good
documentation on how to build
wxMathPlot on Windows, but it is very
simple. Just use CMake:
http://www.cmake.org/
Download and install it, then open
CMake gui, selecting the directory
where you uncompressed wxMathPlot and
a target build directory. click
Configure twice and then click
Generate. CMake does all its magic and
you'll get project files to build
wxMathPlot depending on your compiler.
For example, if you use Visual Studio,
a solution sln file is generated: open
it and build.
That works for building an sln file