How do I build Google Crashpad into Shared (Dynamic) Libraries? - ninja

Problem Summary
I'm trying to integrate Google Crashpad, (successor of Google Breakpad) a crash reporting system, into a software suite that links to all of its external libraries dynamically. My problem is that the default of Crashpad is to build as a static library - I need to build it dynamically.
After cloning Crashpad, GN is used to generate the .ninja files for the build. The build commands are as follows:
$ gn gen out/Default
The above command generates all of the .ninja files.
(Aside) To generate Visual Studio solution files (.sln), the following generation command can be used instead:
$ gn gen out/Default --ide=vs
To compile:
$ ninja -C out/Default
What I've Tried
This StackOverflow Question answers the same question, suggesting that you can simply modify the outputted .ninja files' link flags (/MT changed to /MD). However, grepping over all of the outputted files shows that no such flags exist.
Backtrace Integration Guide has a link to pre-built dynamically (shared) libraries of crashpad here. However, they appear to have built those libraries with Visual Studio 2017, using a newer toolset (v141) than I can use. I need to re-build Crashpad for dynamic linking, and using Visual Studio 2015 (v140).

The output of:
$ gn gen out/Default
will create a file called toolchain.ninja, which contains lines that tell your specified compiler how to compile your projects. In the case of Crashpad, they look like this:
rule cc
command = ninja -t msvc -e environment.amd64 -- cl.exe /nologo /showIncludes ${defines} ${include_dirs} ${cflags} ${cflags_c} /c ${in} /Fo${out} /Fd"${target_out_dir}/${label_name}_c.pdb"
description = CC ${out}
deps = msvc
rule cxx
command = ninja -t msvc -e environment.amd64 -- cl.exe /nologo /showIncludes ${defines} ${include_dirs} ${cflags} ${cflags_c} /c ${in} /Fo${out} /Fd"${target_out_dir}/${label_name}_cc.pdb"
description = CXX ${out}
deps = msvc
For the Visual Studio MSVC 2015 / 2017 compiler, you can add the /MD flag to each command line above. This will compile the library dynamically. For example:
command = ninja -t msvc -e environment.amd64 -- cl.exe /MD /nologo /showIncludes ${defines} ${include_dirs} ${cflags} ${cflags_c} /c ${in} /Fo${out} /Fd"${target_out_dir}/${label_name}_cc.pdb"

Related

How to build Qmake for Visual studio project? specifically for QGLViewer for octomap library

I need to build an octomap on visual studio 2017. According to website they have asked to do the following
open a windows shell (e.g., from the START-Menu -> QT)
cd octovis/src/extern/QGLViewer
qmake -t vclib QGLViewer.pro -spec win32-msvc2010 (ignore any warnings)
So I did the same but in windows command prompt terminal and when I feed the above commands it throws the following error:
#qmake -t vclib QGLViewer.pro -spec win32-msvc2010
Could not find qmake spec 'win32-msvc2010'.
Error processing project file: QGLViewer.pro
#qmake -t vclib QGLViewer.pro -spec win32-msvc2017
Could not find qmake spec 'win32-msvc2017'.
Error processing project file: QGLViewer.pro
What should I do in order to configure and generate a QGLViewer.vcxproj?
Additional details:
Project location : "C:\software\octomap-1.9.0\octomap-1.9.0\octovis\src\extern\QGLViewer"
qmake location : C:\vcpkg\packages\qt5-base_x64-windows\tools\qt5
Visual studio : 2017 ( Version 15.9.8)
Any help in regards to this would be much appreciated as I have a very limited understanding on qmake.
You can build QGLViewer with Qt Creator instead, and then it just works - I was bashing my head against the same issue as you for a while, but then just tried that and it solved my problems. For what it's worth, I used Qt Creator 4.12.4 and did a build all.
I had a few other issues building Octovis on Windows that you might run up against as well. See here for the changes I had to make: https://github.com/OctoMap/octomap/compare/devel...sgolodetz:winchanges

Qt 5.1 with VS2012 compiler - code 128 error

I am trying to set up Qt 5.1 with MS Visual Studio 2012 compiler. I have downloaded and installed the VS Express (it works and compiles C++ code just fine) and then installed Qt.
Here is the console output from whenever I try to build anything:
09:07:14: Running steps for project cube...
09:07:14: Starting: "C:\Qt\Qt5.1.0\5.1.0\msvc2012_64\bin\qmake.exe" C:\Qt\Qt5.0.2\5.0.2\msvc2012_64\examples\opengl\cube\cube.pro -r -spec win32-msvc2012 "CONFIG+=debug" "CONFIG+=declarative_debug" "CONFIG+=qml_debug"
09:07:15: The process "C:\Qt\Qt5.1.0\5.1.0\msvc2012_64\bin\qmake.exe" exited normally.
09:07:15: Starting: "C:\Qt\Qt5.1.0\Tools\QtCreator\bin\jom.exe"
Usage: jom #commandfile
jom [options] [/f makefile] [macro definitions] [targets]
nmake compatible options:
/A build all targets
/D display build information
/E override environment variable macros
/F <filename> use the specified makefile
/G display included makefiles
/H show help
/I ignore all exit codes
/K keep going - build unrelated targets on error
/N dry run - just print commands
/NOLOGO do not print logo
/P print makefile info
/R ignore predefined rules and macros
/S silent mode
/U print content of inline files
/L same as /NOLOGO
/W print the working directory before and after other processing
/X <filename> write stderr to file.
/Y disable batch mode inference rules
jom only options:
/DUMPGRAPH show the generated dependency graph
/DUMPGRAPHDOT dump dependency graph in dot format
/J <n> use up to n processes in parallel
/KEEPTEMPFILES keep all temporary files
/VERSION print version and exit
Error: unknown command line option '-' in arguments: '/L-IC:/QNX650/target/qnx6/usr/include'
09:07:15: The process "C:\Qt\Qt5.1.0\Tools\QtCreator\bin\jom.exe" exited with code 128.
Error while building/deploying project cube (kit: Desktop Qt 5.1.0 MSVC2012 64bit)
When executing step 'Make'
09:07:15: Elapsed time: 00:01.
Earlier I had the same problem with 5.0.2 (basically that's why I killed it and installed 5.1).
I couldn't Google anything reasonable regarding this kind of error. Looks like 128 propagates from somewhere within Visual Studio, but I can't figure out what it is.
Could anybody suggest how can I debug and fix this?
Thanks
... And there's nothing that helps you figure out the problem better than writing it down and then starting at the post.
The "/L-IC:/QNX650/target/qnx6/usr/include" actually tells me that QNX SDK installed on my machine is messing with my environment variables. Luckily, Qt has a way of dealing with that. I need to go to Projects tab, expand the "build environment" section and unset the "MAKEFLAGS" environment variable. This fixes it.

How to use bullseye with Qt( MinGW )?

I have a project in Qt which consists of the set of projects. Projects is building via MinGW and it does not create any .cov file.
I installed bullseye and enabled coverage build but it still does not create *.con file if I try to set path variable like
C:\Program Files\BullseyeCoverage\bin;%PATH%
the build is constantly failing I always get
gcc: CreateProcess: No such file or directory
The file to build whole project is following :
d:\QtSDK\Desktop\Qt\4.7.4\mingw\bin\qmake.exe Simulator.pro -r -spec win32-g++ "CONFIG+=release"
PATH=D:\QtSDK\mingw\bin\;%PATH%
D:\QtSDK\mingw\bin\mingw32-make -f ./Makefile
How can I measure code coverage? Please help.
If somebody interested in this question - I already figured it out.
Here is a solution -
To set bullseye interceptors before your gcc compiler just replace variables
QMAKE_CC = %Bullseye gcc path%
QMAKE_CXX = %Bullseye g++ path%
This variable should be defined in *.pro file or in gcc config file, which is located in
%QTSDKPath%\Desktop\Qt\4.7.4\mingw\mkspecs\win32-g++\ // if you are using gcc from win32
You also need to set environment variable:
BULLSEYE_PATH=%PATH TO REAL COMPILER%

Linking Matlab shared library into Qt (Windows)

I want to use Matlab's C API within QT (http://www.mathworks.com/help/techdoc/matlab_external/f39876.html#bsfvqhp-1) under Windows for opening a .mat file. In my .pro file I have included
INCLUDEPATH += "C:\Program Files\MATLAB\R2010b\extern\include"
which works fine (the code compiles). But when trying to link the libmat.lib file (I have read the .dll files cannot be linked directly) using
LIBS += -L"C:\Program Files\MATLAB\R2010b\extern\lib\win32\microsoft" -llibmat
the application crashes on execution. The error given says [file].exe exited with code -1073741515
I'm neither a QT nor a Windows expert but for this project I am forced to use both (I guess it would be easier to fix this in GNU/Linux) so any help would be appreciated. Using Windows XP, QT version 4.7.0 with Qt Creator 2.0.1, and Matlab R2010b.
The last output from the compiler just in case it is useful:
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -o debug/MainUI.exe debug/main.o debug/maingui.o debug/matparser.o debug/matutils.o debug/moc_maingui.o -L'c:/Qt/2010.05/qt/lib' -lmingw32 -lqtmaind "-LC:\Program Files\MATLAB\R2010b\extern\lib\win32\microsoft" -llibmat -lQtGuid4 -lQtCored4
I just tested building a simple C program that uses the MAT-File Interface Library with no problems. The example file is located in: matlabroot/examples/eng_mat/matcreat.c. I am compiling using MinGW on a Windows XP 32-bit machine. Here is the Makefile I used:
# root directory of MATLAB installation
MATLABROOT="/c/Program Files/MATLAB/R2010b"
.PHONY : all clean run
all: matcreat
matcreat:
gcc ${MATLABROOT}/extern/examples/eng_mat/matcreat.c -o matcreat \
-I${MATLABROOT}/extern/include \
-L${MATLABROOT}/extern/lib/win32/microsoft -llibmat -llibmx
clean:
rm -rf matcreat *.exe *.mat
run:
# UNIX uses LD_LIBRARY_PATH to find libs at runtime, Windows/MinGW uses PATH
#PATH=${MATLABROOT}/bin/win32:"${PATH}" ./matcreat
I suspect that the Matlab library will have been compiled with MSVC and since you say you are compiling your own code with MingW I would imagine the two are incompatible.
Have a look at the MingW page on mixing compilers for more information.

How to use Dcmtk in Qt?

I am working on a project where I have to read a dicom image.
I am unable to install dcmtk. I am using win7 64-bit and vs2010.
Please explain the procedure to include dcmtk in my program.
To use the Windows + DCMTK + QT, you need to execute these follow steps:
Compile the DCMTK (Step 1.A)
Create your sample application (Step 2)
Create your QT project file referring the compiled/installed DCMTK Libs (Step 3.B)
Compile your application in your IDE (Step 4.B)
If you are reading this and don't want to use the Qt, I am answering a version without Qt as well.
Windows+VisualStudio+DCMTK: Steps 1.A, 2, 3.A and 4.A
Linux+GCC+DCMTK: Steps 1.B, 2, N/A, 4.C
1) Compile the DCMTK
First of all, to use the DCMTK library in your application, you should compile the DCMTK source code to generate the libraries:
While I am writing this, the last available version is 3.6.0. So, we should download it:
ftp://dicom.offis.de/pub/dicom/offis/software/dcmtk/dcmtk360/dcmtk-3.6.0.zip
After the download is finished, you need to unzip the folder. The DCMTK source doesn't have a project file, but it is not a problem, there is a CMakelist file responsible for generating a project file in your desirable Operational System/Compiler. If you are not familiar with CMake tool, you can read more here (https://cmake.org/)
1.A) Compiling on Windows/Visual Studio 2012
1.A.1) You need to have an installed compiler, in my case, it was the Visual Studio 2012
1.A.2) Run the CMake tool to generate a project file to Visual Studio 2012. You need be able to fill the source DCMTK directory.
1.A.3) Now, execute the VisualStudio 2012, open the file sln created in the previous step (2) and compile the target ALL_BUILD
1.A.4) Re-Execute VisualStudio in Admin mode (because of permission C:\Program Files) to compile the target INSTALL (it will copy and install the DCMTK to default path: C:/Program Files/DCMTK/, we can reference it such PATH_WHERE_DCMTK_WAS_INSTALLED)
(1.B) Compiling on GNU/Linux GCC
I have tested at Ubuntu/CentOS. The first, you should go to DCMTK Source and run these following three commands:
$ ./configure --prefix=path_to_dcmtk
$ make all
$ sudo make install
example: path_to_dcmtk = /home/user/dcmtk
2) Creating your sample application
Create a file called your_sample/testapp.cxx with the following content. This a demonstration found in DCMTK Forum to open a DICOM file and print the patient's name.
#include "dcmtk/dcmdata/dctk.h"
#include <iostream>
using namespace std;
int main()
{
DcmFileFormat fileformat;
OFCondition status = fileformat.loadFile("test.dcm");
if (status.good())
{
OFString patientsName;
if (fileformat.getDataset()->findAndGetOFString(DCM_PatientName, patientsName).good())
{
cout << "Patient's Name: " << patientsName << endl;
}else{
cerr << "Error: cannot access Patient's Name!" << endl;
}
}else{
cerr << "Error: cannot read DICOM file (" << status.text() << ")" << endl;
}
return 0;
}
3) Creating the Application Project using the VisuaStudio as Compiler
The created file at the previous step needs to be placed in a project. You can choose between the option Windows VisualStudio (3.1) and Windows Qt (3.2). If you are using Linux, you can skip this step.
3.A) Windows with Visual Studio 2012 IDE
To create a Visual Studio project, you can use the Wizard and set the necessary settings such: Linker, Libraries, etc. However, to make easier on this answer, I will use the CMakeList.txt to create a Project for Visual Studio 2012. So, please, create a file called your_sample/CmakeList.txt with the following content:
PROJECT(testapp)
SET(DCMTK_DIR ABSOLUTE_PATH_WHERE_DCMTK_WAS_INSTALLED)
#an example: SET(DCMTK_DIR "C:\\Users\\test\\test_dcmtk\\DCMTK")
# settings for Microsoft Visual C++ 6
SET(CMAKE_C_FLAGS "/nologo /W3 /GX /Gy /YX")
SET(CMAKE_C_FLAGS_DEBUG "/MTd /Z7 /Od")
SET(CMAKE_C_FLAGS_RELEASE "/MT /O2")
SET(CMAKE_CXX_FLAGS "/nologo /W3 /GX /Gy /YX")
SET(CMAKE_CXX_FLAGS_DEBUG "/MTd /Z7 /Od")
SET(CMAKE_CXX_FLAGS_RELEASE "/MT /O2")
ADD_DEFINITIONS(-D_REENTRANT)
INCLUDE_DIRECTORIES(${DCMTK_DIR}/include)
LINK_DIRECTORIES(${DCMTK_DIR}/lib)
ADD_EXECUTABLE(testapp testapp)
TARGET_LINK_LIBRARIES(testapp netapi32 wsock32 ofstd dcmdata)
3.B) Windows QtCreator IDE using the VisuaStudio as Compiler
To create a project file for QtCreator IDE. You need to create a file called your_sample/my_project.pro with the following content:
SOURCES += testapp.cxx
CONFIG += debug console
DEFINES += _REENTRANT
QMAKE_CFLAGS_RELEASE -= -MD
QMAKE_CFLAGS_RELEASE = -MT
QMAKE_CFLAGS_DEBUG -= -MDd
QMAKE_CFLAGS_DEBUG = -MTd
QMAKE_CXXFLAGS_RELEASE -= -MD
QMAKE_CXXFLAGS_RELEASE += -MT
QMAKE_CXXFLAGS_DEBUG -= -MDd
QMAKE_CXXFLAGS_DEBUG += -MTd
INCLUDEPATH += (RELATIVE_PATH_WHERE_DCMTK_WAS_INSTALLED)/include
#an example: INCLUDEPATH += ../../../test_dcmtk/DCMTK/include
LIBS += -L"(RELATIVE_PATH_WHERE_YOU_INSTALLED_DCMTK)/lib" \
-ladvapi32 \
-ldcmdata \
-loflog \
-lofstd \
-lws2_32 \
-lnetapi32 \
-lwsock32
#an example: LIBS += -L"../../../test_dcmtk/DCMTK/lib" \
4.A) Windows with Visual Studio 2012 IDE
Open the project file at VisualStudio and click on Build.
4.B) Windows with QtCreator IDE using the VisuaStudio as Compiler
Open the project file at QT and click on Build.
4.C) GNU/Linux - Command Line with GCC
g++ testapp.cxx -DHAVE_CONFIG_H -I/path_to_dcmtk/include -L/path_to_dcmtk/lib -pthread -ldcmdata -lz -loflog -lofstd -o main
Please, note that whether you have compiled the libraries in DEBUG mode, your application should be compiled in DEBUG mode as well.
References
How Install
http://support.dcmtk.org/docs/file_install.html
DCMTK Docs
http://support.dcmtk.org/docs/
FAQ #40: How do I use the DCMTK libraries in my own application? [MSVC]
http://forum.dcmtk.org/viewtopic.php?f=4&t=652
CMake Configuration
http://support.dcmtk.org/wiki/dcmtk/howto/cmakeconfiguration360
Try to follow the instructions for the Dcmtk installation. If you don't know how to include the library in your project, study the qmake manual.
The Common Toolkit guys have addressed some of these issues. You could also use the Insight Toolkit
http://www.commontk.org/index.php/Main_Page
http://itk.org
In fact there is a bit of documentation on the ITK wiki, but ITK uses gdcm instead of dcmtk.
http://www.itk.org/Wiki/ITK_FAQ#How_to_read_a_volume_from_a_DICOM_series
We have a project that is an implementation of DCMTk in Qt -- we call it QtDICOM, and it forms the foundation of many of our products (http://fluxinc.ca/medical)/. Worth a look (https://bitbucket.org/fluxinc/qt-dicom). We haven't documented the configuration particularly well, but you can probably figure it out if you have a look.
Note: It does depend on DCMTk being built and included in the various paths.

Resources