Coverity: command line build script for basic c++ code - c++

I am working on a requirement to do instrumented build for c++ code on coverity(static code analysis tool, version 7.5.1) build server via command line. Need to execute a basic c++ code via command line, I tried using the cov-build command cov-build –-dir cov-int cl /c test.cpp and various other permutations on the directory where coverity is actually installed in the build machine. But there is some problem. System can understand only the cov-buld --dir and if i use only this command along with /c, this file opens in visual studio rather than giving the% of compilation units.
Please help me if anyone have done this before.

First be clear with your requirements. Which system you are working on?(windows or Mac or Unix or Solaris). Before starting cov-build, configure the compiler which will execute the source file. As you said you are working on C++ source code, use GCC compiler to configure with Coverity Static Analyzer. Coverity Directly supports for 3 Compilers(Gcc and 2 more). To configure this GCC use cov-configure command followed by gcc.
Then use cov-build command to analyze.
Sample command is:
path_to_cov_bin/cov-build --dir path_to_output_folder gcc hi.cpp
It will create emit folder with emit-db in path_to_output_folder. Then cov-analyze command will be analyze that emit folder and create Output Directory in given path.
To compile N number of source files use makefile. If you have any query about makefile You can put a post here or refer in this site.

Related

how compile opus-codel with g++

Hello I've got my first program using opus-codec library and I wonder if there is another way to compile it without passing by cmake. Such as the g++ command for example. Which flags should I use ?
cmake is not a compiler, it is a tool for managing the build process. To compile your files, you are already using a compiler (g++ may be) which is called by the build files created by cmake.
For example when you run cmake command on a linux, you will generate a Makefile. The when you run your make command it will call gcc or g++. To see the compilation commands, you can add VERBOSE=1 to your make command.

How to link GLEW and GLFW and OpenGL to MingW's g++

I am doing a course on OpenGL.
So I have run my project in Visual Studio 2019 and it works.
What I needed to do in Visual Studio was:
Add GLEW's and GLFW's additional include directories. (when you download the libraries it is simply the location of the include file)
Add GLEW's and GLFW's additional library directories. (lib folder locations)
Add the additional dependencies. (opengl32.lib, glew32.lib, glfw3.lib)
Copy and paste GLEW.dll into the project files, next to main.cpp.
And I run my code and it works.
But I don't want to use Visual Studio 2019, I would much rather work in Notepad++ or VSCode, what I really want is to just make a project out of pure notepad and compile it with the new Windows Terminal.
My question:
How can I do all of the things I did in visual studio 2019 from Power Shell?
I heard that MingW comes with its own power shell or command prompt, I imagine I need to find it and give it some commands to link everything up before I start coding.
Where do I find MingW's power shell equivalent and what commands do I need to type?
I have been stuck on this for ages now and could not find any information about it online. (except for what -L and -l does, but these are not power shell commands)
The MingGW and mingw-w64
compilers are Windows commandline tools. They are Windows ports of (some of)
the GCC compilers. tdm-gcc is yet another choice.
Commandine tools for any operating
system don't need their own shell. You can run them in any shell you've got
on that operating system. On Windows today
you have a choice of at least PowerShell and the old CMD shell.
The MinGW project provides, as well as its GCC toolchain, a minimal unix-like
environment for Windows called MSYS, which includes a shell. You don't need
MSYS to run the compiler.
As long as the GCC tools can be located in
the value of the PATH environment variable that is operative in
the shell at compiletime, then you run the compiler at the shell prompt:
>gcc [options...]
>g++ [options...]
the same way it is run on any operating system. If you want to work with a GCC toolchain then the question:
How can I do all of the things I did in visual studio 2019 from Power Shell?
is simply the question, How do you run GCC? That's a question of
sweeping generality. You need to study relevant books
and documentation
Very sketchily, if you want to compile and link a C++ program that has source files main.cpp and other.cpp and depends on libraries
foo and bar that have their C++ APIs defined in header files and are implemented in DLLs,
you will do it with commands of the following form:
To compile the source files to object files:
>g++ -c -o main.obj main.cpp -I/path/to/foo/header/files -I/path/to/bar/header/files [any other compilation options....]
>g++ -c -o other.obj other.cpp -I/path/to/foo/header/files -I/path/to/bar/header/files [any other compilation options....]
To link the object files and libraries to make an excutable program:
>g++ -o prog main.obj other.obj -L/path/to/foo_dll -L/maybe/a/different/path/to/bar_dll -lfoo -lbar [any other linkage options...]
And if all that is successful then the program will be prog.exe and you can run it:
>prog
just like you ran g++, provided that foo.dll and bar.dll can be found at runtime by the OS loader's DLL search protocol
As I think you appreciate, in real life nobody builds programs by typing the all the
commands in a shell except for instructional purposes. They use a build system or an IDE to automate it. But it is true that building programs though the medium of a build system or IDE presents fewer difficulties if you do it with a basic grasp of how the tools behind it work.

OpenCV C++ Linux g++ compiling

I just installed OpenCV-3.4.1 on Ubuntu 18.04. I am able to compile my C++ files only when I run the g++ command with pkg-config --cflags --libs opencv
Is it possible for me to compile the c++ file without using these additional flags
How can I tell g++ to automatically look at /usr/include/opencv for the .h files everytime
For adding to the include path see this question: How to add a default include path for GCC in Linux?
A better solution however is to write a shell script to compile your code rather than having to type in the command line every time.
The best solution is to use a proper build system which will save you a lot of pain in the future, just a few of the many available options:
GNU make
cmake
google gyp
google gn
ninja

Where do I get the qm executable from?

I am working on an Ubuntu 16.04 system and tried to compile an application with the qm command as per the readme file in the source directory. When I try to run the command I get the repose:
$ qm
qm: command not found
This suggests that my Ubuntu PC does not have a repository with a package that supplies a qm executable setup. I guess the source code for the tool may be available somewhere and be usable for multiple GNU Linux operating systems.
How do I source and install the qm executable?
The readme file for the code I am trying to compile states that qm stands for quick-make or QMake but I cannot find any reference to these in a google search. I only find references to Qt's qmake which is not the tool I am looking for based on the errors I get back.
This qm tool uses a defs.mk file as its instruction set.
The program I am trying to install uses the RAVL Library. The README file for that library also mentions qm command.
I found a source for the qm or QMake or Quick Make tool. In the Recognition And Vision Library (RAVL) Installation Instructions the installation of QMake is mentioned.
Building the RAVL library requires the use of an ANSI C++ compiler
along with the GNU make utility (or another compatible version of
make). The RAVL build process is actually managed by the QMake
utility. QMake is a flexible compilation aid, designed to provide a
simpler interface to the GNU make program. As part of the RAVL
installation process, a copy of QMake will be configured and
installed.
The instructions go on to explain that by; obtaining a copy of the RAVL source code, configuring, making and installing it you get both the RAVL libary and the quick-make tool set. This includes the qm command.
After preforming the following steps:
git clone -b tested_nightly git://git.code.sf.net/p/ravl/ravl ravl
cd ravl
./configure
make
sudo make install
I am able to use the qm command.

GDB not a recognized command - Windows command prompt

I am trying to use GDB to debug a C++ program, but my system is not recognizing gdb as a command. I installed it, along with many other tools, via MinGW. I have not had any problem with the other features I have used (gcc, g++), so the issue doesn't seem to be with my general set up. I have added the MinGW\bin directory to my PATH. The gdb.exe is in that folder. But it will not run when invoked from my project directory, it simply errors: "'gdb' is not recognized as an internal or external command, operable program, or batch file." Is there some step in setup or invocation that I missed for using GDB?
EDIT: Alright, I think I found the problem: there are two MinGW directories in my PATH, one at C:\MinGW, and another in folder that got installed with some Haskell compilers I used a while ago. It appears to be defaulting to the Haskell folder, perhaps because this directory is listed first. However, this folder contains gcc and g++, but NOT gdb. I was able to get the gdb command working by creating the fstab file in the msys directory, a step I apparently forgot when setting up MinGW. I added my C:\MinGW directory to it, and now the gdb command is working properly! Out of curiosity, what does this file do?
Also, ideally I would like it to look in the C:\MinGW directory first, since this is the folder I plan to keep updated, and the one that contains ALL of the various applications. However, the Haskell directory is specified via the system PATH variable, which I've read it's not a good idea to touch. Would switching the order that they appear even fix my problem?
EDIT 2: Not 100% sure what happened, but the gdb command appears to be working now. I have always been using the Windows cmd prompt to run these tools, so per the answer below (that I should not need to mess with msys) I deleted the fstab file, and lo, it still works! However, my second question above still stands: What is the best way to get the compilers to run out of C:\MinGW\bin instead of C:\Program Files (x86)\Haskell Platform\2013.2.0.0\bin? Is moving the Haskell location out of the system PATH and to the end of the user PATH a viable option?
I had to run pacman -S mingw-w64-x86_64-gdb separately and then gdb showed up in the bin.
You do not have to run gdb (or gcc and all other MinGW tools for that matter) within msys - it is not like Cygwin in that respect. Had you run it from the Windows cmd console, it should work.
The msys shell is useful for running configure scripts generated by Autoconf used by many Linux originated open source projects, but its environment is independent of the Windows environment.