can't compile code from Bjarne Stroustrup's Programming C++ book - c++

code is like:
// #include "..\std_lib_facilities.h"
#include "Simple_window.h"
#include "Graph.h"
using namespace Graph_lib;
int main()
{
Point t1 {100, 100};
Simple_window win {t1, 600, 400, "Canvas"};
win.wait_for_button();
}
Simple_window.h and Graph.h is headers Stroustrup made himself. download from www.stroustrup.com
I installed fltk (mingw64/mingw-w64-x86_64-fltk 1.3.5-1) using msys in Windows10.
As I tried, fltk-config doesn't work in windows10 cmd, so I'm using msys to use fltk.
error is like:
hendr#DESKTOP-DC4NCDT MSYS /d/home/prog/cpp/gui
$ fltk-config --compile First.cpp
x86_64-w64-mingw32-g++ -I/mingw64/include -mwindows -DWIN32 -DUSE_OPENGL32 -march=x86-64 -mtune=generic -O2 -pipe -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -o 'First' 'First.cpp' -mwindows -pipe -Wl,--enable-auto-import -Wl,--enable-runtime-pseudo-reloc /mingw64/lib/libfltk.a -lole32 -luuid -lcomctl32
In file included from PPP2code\GUI.h:7,
from PPP2code\Simple_window.h:2,
from First.cpp:2:
PPP2code\Graph.h:159:24: warning: narrowing conversion of 'fl_color()' from 'Fl_Color' {aka 'unsigned int'} to 'int' [-Wnarrowing]
159 | Color lcolor {fl_color()};
| ~~~~~~~~^~
In file included from First.cpp:2:
PPP2code\Simple_window.h:9:24: error: reference to 'Window' is ambiguous
9 | struct Simple_window : Window {
| ^~~~~~
In file included from PPP2code\GUI.h:6,
from PPP2code\Simple_window.h:2,
from First.cpp:2:
PPP2code\Window.h:16:7: note: candidates are: 'class Graph_lib::Window'
16 | class Window : public Fl_Window {
| ^~~~~~
In file included from D:/msys64/mingw64/include/FL/x.H:30,
from D:/msys64/mingw64/include/FL/fl_draw.H:27,
from PPP2code\fltk.h:10,
from PPP2code\GUI.h:5,
from PPP2code\Simple_window.h:2,
from First.cpp:2:
D:/msys64/mingw64/include/FL/win32.H:30:14: note: 'typedef struct HWND__* Window'
30 | typedef HWND Window;
| ^~~~~~
In file included from First.cpp:2:
PPP2code\Simple_window.h: In constructor 'Simple_window::Simple_window(Graph_lib::Point, int, int, const string&)':
PPP2code\Simple_window.h:11:4: error: class 'Simple_window' does not have any field named 'Window'
11 | : Window(xy,w,h,title),
| ^~~~~~
PPP2code\Simple_window.h:13:34: error: no matching function for call to 'Graph_lib::Point::Point(int, int)'
13 | next_button(Point(x_max()-70,0), 70, 20, "Next", cb_next) { attach(next_button); }
| ^
In file included from PPP2code\GUI.h:4,
from PPP2code\Simple_window.h:2,
from First.cpp:2:
PPP2code\Point.h:9:8: note: candidate: 'Graph_lib::Point::Point()'
9 | struct Point {
| ^~~~~
PPP2code\Point.h:9:8: note: candidate expects 0 arguments, 2 provided
PPP2code\Point.h:9:8: note: candidate: 'constexpr Graph_lib::Point::Point(const Graph_lib::Point&)'
PPP2code\Point.h:9:8: note: candidate expects 1 argument, 2 provided
PPP2code\Point.h:9:8: note: candidate: 'constexpr Graph_lib::Point::Point(Graph_lib::Point&&)'
PPP2code\Point.h:9:8: note: candidate expects 1 argument, 2 provided
In file included from First.cpp:2:
PPP2code\Simple_window.h:13:64: error: 'attach' was not declared in this scope; did you mean 'atanh'?
13 | next_button(Point(x_max()-70,0), 70, 20, "Next", cb_next) { attach(next_button); }
| ^~~~~~
| atanh
Is this error due to Simple_window.h, Graph.h or fltk or I'm trying this in Windows10 than linux?
I'm barely newby to c++ so fixing headers from book is impossible job for me..
Is anyone who tried this?

Related

SDL_Vertex and SDL_RenderGeometry not found

I made a project with SDL2 under Windows.
When I try to compile it on Linux, these errors occur:
reilbas#reilbas:~/C/a/Labyrinthe-3D-main$ g++ -o test -I include src/*.cpp $(sdl2-config --cflags --libs)
src/Affichage.cpp: In member function ‘void Affichage::drawRect(float, float, float, float, SDL_Color&)’:
src/Affichage.cpp:110:17: error: ‘SDL_Vertex’ was not declared in this scope; did you mean ‘SDL_mutex’?
110 | std::vector<SDL_Vertex> triUi1 = {
| ^~~~~~~~~~
| SDL_mutex
src/Affichage.cpp:110:27: error: template argument 1 is invalid
110 | std::vector<SDL_Vertex> triUi1 = {
| ^
src/Affichage.cpp:110:27: error: template argument 2 is invalid
src/Affichage.cpp:110:29: error: scalar object ‘triUi1’ requires one element in initializer
110 | std::vector<SDL_Vertex> triUi1 = {
| ^~~~~~
src/Affichage.cpp:115:27: error: template argument 2 is invalid
115 | std::vector<SDL_Vertex> triUi2 = {
| ^
src/Affichage.cpp:115:29: error: scalar object ‘triUi2’ requires one element in initializer
115 | std::vector<SDL_Vertex> triUi2 = {
| ^~~~~~
src/Affichage.cpp:120:5: error: ‘SDL_RenderGeometry’ was not declared in this scope; did you mean ‘SDL_RenderCopy’?
120 | SDL_RenderGeometry(renderer, nullptr, triUi1.data(), triUi1.size(), nullptr, 0);
| ^~~~~~~~~~~~~~~~~~
| SDL_RenderCopy
src/Affichage.cpp: In member function ‘void Affichage::displayTri(std::vector<triangle>)’:
src/Affichage.cpp:146:21: error: ‘SDL_Vertex’ was not declared in this scope; did you mean ‘SDL_mutex’?
146 | std::vector<SDL_Vertex> verts = {
| ^~~~~~~~~~
| SDL_mutex
src/Affichage.cpp:146:31: error: template argument 1 is invalid
146 | std::vector<SDL_Vertex> verts = {
| ^
src/Affichage.cpp:146:31: error: template argument 2 is invalid
src/Affichage.cpp:146:33: error: scalar object ‘verts’ requires one element in initializer
146 | std::vector<SDL_Vertex> verts = {
| ^~~~~
src/Affichage.cpp:151:9: error: ‘SDL_RenderGeometry’ was not declared in this scope; did you mean ‘SDL_RenderCopy’?
151 | SDL_RenderGeometry( renderer, nullptr, verts.data(), verts.size(), nullptr, 0);
| ^~~~~~~~~~~~~~~~~~
| SDL_RenderCopy
src/AllMath.cpp: In static member function ‘static int AllMath::triangleClipAgainstPlane(vec3d, vec3d, triangle&, triangle&, triangle&)’:
src/AllMath.cpp:254:1: warning: control reaches end of non-void function [-Wreturn-type]
254 | }
| ^
I installed SDL2 with apt:
$ sudo apt-get install libsdl2
SDL_RenderGeometry() & friends were introduced in SDL 2.0.18:
Added SDL_RenderGeometry() and SDL_RenderGeometryRaw() to allow rendering of arbitrary shapes using the SDL 2D render API
...so make sure you're using that version or higher.
SDL 2.0.18 was released in late 2021 so distros like Ubuntu 20.04 that ship older versions of SDL won't have those newer functions.

g++ std=c++98 doesn't compile in MinGW

Here's my code:
main.cpp
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
cout << pow(4, 3);
cin.get();
}
So basically I try to compile with command g++ main.cpp -std=c++98
Here's what I get:
C:\Users\NullPointerException\Desktop\cpp>g++ main.cpp -std=c++98
In file included from c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\postypes.h:40,
from c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\iosfwd:40,
from c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\ios:38,
from c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\iostream:39,
from main.cpp:1:
c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\cwchar:166:11: error: '::vfwscanf' has not been declared
166 | using ::vfwscanf;
| ^~~~~~~~
c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\cwchar:172:11: error: '::vswscanf' has not been declared
172 | using ::vswscanf;
| ^~~~~~~~
c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\cwchar:176:11: error: '::vwscanf' has not been declared
176 | using ::vwscanf;
| ^~~~~~~
c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\cwchar:193:11: error: '::wcstof' has not been declared
193 | using ::wcstof;
| ^~~~~~
In file included from c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\locale_facets.h:39,
from c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\basic_ios.h:37,
from c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\ios:44,
from c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\iostream:39,
from main.cpp:1:
c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\cwctype:89:11: error: '::iswblank' has not been declared
89 | using ::iswblank;
| ^~~~~~~~
Basically I wanted to test if c++ can deduce type for pow. But I get these errors. What's the problem and how do I fix it?
g++ version: 9.2.0
I can compile this without problems using g++ 9.3 on ubuntu. Seems you have run into a bug specific to the mingw32 variant of g++.
You might try adding include <cstdio> and perhaps also include <cstdarg> before the other includes.
I cannot test this since I'm not using mingw32.
pow is a C function, not C++, so use the alternative C header for the math library.

make error: recipe for target 'all-recursive' failed

Hello and thank you for your help in advance (I'm a bit of a newbie). I am on ubuntu 18.
I am trying to install an older version of some software called HepMC (need older version for project) and I had no problem installing the slightly newer version. When I try to build from source I get an error on the make command. I've seen this "all-recurive failed" error all over the web, but the solutions I've seen for other people have seemed to be very software specific and have not helped me.
I am not really sure how to interpret this error and I haven't been able to find a good answer. Any tips or suspicions on what might be going on here would be greatly appreciated. Been bashing my head against this for awhile
Before running make I did
autoreconf -i configure.ac
./configure
and this ran with no errors or warnings.
Here's the snippet where the error seems to begin, I'll attach the full printout from "make" down below.
In file included from ../HepMC/CommonIO.h:15:0,
from CommonIO.cc:11:
../HepMC/GenEvent.h:408:80: error: template argument 3 is invalid
public std::iterator<std::forward_iterator_tag,HepMC::GenParticle*,ptrdiff_t>{
^
../HepMC/GenEvent.h:459:71: error: ‘ptrdiff_t’ was not declared in this scope
public std::iterator<std::forward_iterator_tag,HepMC::GenParticle*,ptrdiff_t>{
^~~~~~~~~
../HepMC/GenEvent.h:459:71: note: suggested alternatives:
In file included from /usr/include/c++/7/string:38:0,
from CommonIO.cc:8:
/usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:232:28: note: ‘std::ptrdiff_t’
typedef __PTRDIFF_TYPE__ ptrdiff_t;
^~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:232:28: note: ‘std::ptrdiff_t’
In file included from ../HepMC/CommonIO.h:15:0,
from CommonIO.cc:11:
../HepMC/GenEvent.h:459:80: error: template argument 3 is invalid
public std::iterator<std::forward_iterator_tag,HepMC::GenParticle*,ptrdiff_t>{
^
CommonIO.cc: In member function ‘HepMC::HeavyIon* HepMC::CommonIO::read_heavy_ion(std::istream*)’:
CommonIO.cc:318:9: warning: converting ‘false’ to pointer type ‘HepMC::HeavyIon*’ [-Wconversion-null]
return false;
^~~~~
CommonIO.cc:328:26: warning: converting ‘false’ to pointer type ‘HepMC::HeavyIon*’ [-Wconversion-null]
if( nh == 0 ) return false;
^~~~~
CommonIO.cc: In member function ‘HepMC::PdfInfo* HepMC::CommonIO::read_pdf_info(std::istream*)’:
CommonIO.cc:344:9: warning: converting ‘false’ to pointer type ‘HepMC::PdfInfo*’ [-Wconversion-null]
return false;
^~~~~
CommonIO.cc:356:27: warning: converting ‘false’ to pointer type ‘HepMC::PdfInfo*’ [-Wconversion-null]
if( id1 == 0 ) return false;
^~~~~
CommonIO.cc: In member function ‘HepMC::GenVertex* HepMC::CommonIO::read_vertex(std::istream*, HepMC::TempParticleMap&)’:
CommonIO.cc:374:9: warning: converting ‘false’ to pointer type ‘HepMC::GenVertex*’ [-Wconversion-null]
return false;
^~~~~
CommonIO.cc: In member function ‘HepMC::GenParticle* HepMC::CommonIO::read_particle(std::istream*, HepMC::TempParticleMap&)’:
CommonIO.cc:411:9: warning: converting ‘false’ to pointer type ‘HepMC::GenParticle*’ [-Wconversion-null]
return false;
^~~~~
Makefile:478: recipe for target 'CommonIO.lo' failed
make[1]: *** [CommonIO.lo] Error 1
make[1]: Leaving directory '/home/maxfieg/Desktop/FelixResearch/junk/hep_build2/HepMC2.04/src'
Makefile:397: recipe for target 'all-recursive' failed
make: *** [all-recursive] Error 1
and here's the full return of make
make
Making all in HepMC
make[1]: Entering directory '/home/maxfieg/Desktop/FelixResearch/junk/hep_build2/HepMC2.04/HepMC'
make all-am
make[2]: Entering directory '/home/maxfieg/Desktop/FelixResearch/junk/hep_build2/HepMC2.04/HepMC'
make[2]: Leaving directory '/home/maxfieg/Desktop/FelixResearch/junk/hep_build2/HepMC2.04/HepMC'
make[1]: Leaving directory '/home/maxfieg/Desktop/FelixResearch/junk/hep_build2/HepMC2.04/HepMC'
Making all in src
make[1]: Entering directory '/home/maxfieg/Desktop/FelixResearch/junk/hep_build2/HepMC2.04/src'
/bin/bash ../libtool --tag=CXX --mode=compile g++ -DHAVE_CONFIG_H -I. -I../HepMC -I.. -I.. -ansi -pedantic -Wall -g -O2 -MT CommonIO.lo -MD -MP -MF .deps/CommonIO.Tpo -c -o CommonIO.lo CommonIO.cc
libtool: compile: g++ -DHAVE_CONFIG_H -I. -I../HepMC -I.. -I.. -ansi -pedantic -Wall -g -O2 -MT CommonIO.lo -MD -MP -MF .deps/CommonIO.Tpo -c CommonIO.cc -fPIC -DPIC -o .libs/CommonIO.o
In file included from ../HepMC/GenEvent.h:123:0,
from ../HepMC/CommonIO.h:15,
from CommonIO.cc:11:
../HepMC/GenVertex.h:173:71: error: ‘ptrdiff_t’ was not declared in this scope
public std::iterator<std::forward_iterator_tag,HepMC::GenParticle*,ptrdiff_t>{
^~~~~~~~~
../HepMC/GenVertex.h:173:71: note: suggested alternatives:
In file included from /usr/include/c++/7/string:38:0,
from CommonIO.cc:8:
/usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:232:28: note: ‘std::ptrdiff_t’
typedef __PTRDIFF_TYPE__ ptrdiff_t;
^~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:232:28: note: ‘std::ptrdiff_t’
In file included from ../HepMC/GenEvent.h:123:0,
from ../HepMC/CommonIO.h:15,
from CommonIO.cc:11:
../HepMC/GenVertex.h:173:80: error: template argument 3 is invalid
public std::iterator<std::forward_iterator_tag,HepMC::GenParticle*,ptrdiff_t>{
^
../HepMC/GenVertex.h:237:69: error: ‘ptrdiff_t’ was not declared in this scope
public std::iterator<std::forward_iterator_tag,HepMC::GenVertex*,ptrdiff_t>{
^~~~~~~~~
../HepMC/GenVertex.h:237:69: note: suggested alternatives:
In file included from /usr/include/c++/7/string:38:0,
from CommonIO.cc:8:
/usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:232:28: note: ‘std::ptrdiff_t’
typedef __PTRDIFF_TYPE__ ptrdiff_t;
^~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:232:28: note: ‘std::ptrdiff_t’
In file included from ../HepMC/GenEvent.h:123:0,
from ../HepMC/CommonIO.h:15,
from CommonIO.cc:11:
../HepMC/GenVertex.h:237:78: error: template argument 3 is invalid
public std::iterator<std::forward_iterator_tag,HepMC::GenVertex*,ptrdiff_t>{
^
../HepMC/GenVertex.h:307:64: error: ‘ptrdiff_t’ was not declared in this scope
public std::iterator<std::forward_iterator_tag,GenParticle*,ptrdiff_t>{
^~~~~~~~~
../HepMC/GenVertex.h:307:64: note: suggested alternatives:
In file included from /usr/include/c++/7/string:38:0,
from CommonIO.cc:8:
/usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:232:28: note: ‘std::ptrdiff_t’
typedef __PTRDIFF_TYPE__ ptrdiff_t;
^~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:232:28: note: ‘std::ptrdiff_t’
In file included from ../HepMC/GenEvent.h:123:0,
from ../HepMC/CommonIO.h:15,
from CommonIO.cc:11:
../HepMC/GenVertex.h:307:73: error: template argument 3 is invalid
public std::iterator<std::forward_iterator_tag,GenParticle*,ptrdiff_t>{
^
In file included from ../HepMC/CommonIO.h:15:0,
from CommonIO.cc:11:
../HepMC/GenEvent.h:289:69: error: ‘ptrdiff_t’ was not declared in this scope
public std::iterator<std::forward_iterator_tag,HepMC::GenVertex*,ptrdiff_t>{
^~~~~~~~~
../HepMC/GenEvent.h:289:69: note: suggested alternatives:
In file included from /usr/include/c++/7/string:38:0,
from CommonIO.cc:8:
/usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:232:28: note: ‘std::ptrdiff_t’
typedef __PTRDIFF_TYPE__ ptrdiff_t;
^~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:232:28: note: ‘std::ptrdiff_t’
In file included from ../HepMC/CommonIO.h:15:0,
from CommonIO.cc:11:
../HepMC/GenEvent.h:289:78: error: template argument 3 is invalid
public std::iterator<std::forward_iterator_tag,HepMC::GenVertex*,ptrdiff_t>{
^
../HepMC/GenEvent.h:341:69: error: ‘ptrdiff_t’ was not declared in this scope
public std::iterator<std::forward_iterator_tag,HepMC::GenVertex*,ptrdiff_t>{
^~~~~~~~~
../HepMC/GenEvent.h:341:69: note: suggested alternatives:
In file included from /usr/include/c++/7/string:38:0,
from CommonIO.cc:8:
/usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:232:28: note: ‘std::ptrdiff_t’
typedef __PTRDIFF_TYPE__ ptrdiff_t;
^~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:232:28: note: ‘std::ptrdiff_t’
In file included from ../HepMC/CommonIO.h:15:0,
from CommonIO.cc:11:
../HepMC/GenEvent.h:341:78: error: template argument 3 is invalid
public std::iterator<std::forward_iterator_tag,HepMC::GenVertex*,ptrdiff_t>{
^
../HepMC/GenEvent.h:408:71: error: ‘ptrdiff_t’ was not declared in this scope
public std::iterator<std::forward_iterator_tag,HepMC::GenParticle*,ptrdiff_t>{
^~~~~~~~~
../HepMC/GenEvent.h:408:71: note: suggested alternatives:
In file included from /usr/include/c++/7/string:38:0,
from CommonIO.cc:8:
/usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:232:28: note: ‘std::ptrdiff_t’
typedef __PTRDIFF_TYPE__ ptrdiff_t;
^~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:232:28: note: ‘std::ptrdiff_t’
In file included from ../HepMC/CommonIO.h:15:0,
from CommonIO.cc:11:
../HepMC/GenEvent.h:408:80: error: template argument 3 is invalid
public std::iterator<std::forward_iterator_tag,HepMC::GenParticle*,ptrdiff_t>{
^
../HepMC/GenEvent.h:459:71: error: ‘ptrdiff_t’ was not declared in this scope
public std::iterator<std::forward_iterator_tag,HepMC::GenParticle*,ptrdiff_t>{
^~~~~~~~~
../HepMC/GenEvent.h:459:71: note: suggested alternatives:
In file included from /usr/include/c++/7/string:38:0,
from CommonIO.cc:8:
/usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:232:28: note: ‘std::ptrdiff_t’
typedef __PTRDIFF_TYPE__ ptrdiff_t;
^~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:232:28: note: ‘std::ptrdiff_t’
In file included from ../HepMC/CommonIO.h:15:0,
from CommonIO.cc:11:
../HepMC/GenEvent.h:459:80: error: template argument 3 is invalid
public std::iterator<std::forward_iterator_tag,HepMC::GenParticle*,ptrdiff_t>{
^
CommonIO.cc: In member function ‘HepMC::HeavyIon* HepMC::CommonIO::read_heavy_ion(std::istream*)’:
CommonIO.cc:318:9: warning: converting ‘false’ to pointer type ‘HepMC::HeavyIon*’ [-Wconversion-null]
return false;
^~~~~
CommonIO.cc:328:26: warning: converting ‘false’ to pointer type ‘HepMC::HeavyIon*’ [-Wconversion-null]
if( nh == 0 ) return false;
^~~~~
CommonIO.cc: In member function ‘HepMC::PdfInfo* HepMC::CommonIO::read_pdf_info(std::istream*)’:
CommonIO.cc:344:9: warning: converting ‘false’ to pointer type ‘HepMC::PdfInfo*’ [-Wconversion-null]
return false;
^~~~~
CommonIO.cc:356:27: warning: converting ‘false’ to pointer type ‘HepMC::PdfInfo*’ [-Wconversion-null]
if( id1 == 0 ) return false;
^~~~~
CommonIO.cc: In member function ‘HepMC::GenVertex* HepMC::CommonIO::read_vertex(std::istream*, HepMC::TempParticleMap&)’:
CommonIO.cc:374:9: warning: converting ‘false’ to pointer type ‘HepMC::GenVertex*’ [-Wconversion-null]
return false;
^~~~~
CommonIO.cc: In member function ‘HepMC::GenParticle* HepMC::CommonIO::read_particle(std::istream*, HepMC::TempParticleMap&)’:
CommonIO.cc:411:9: warning: converting ‘false’ to pointer type ‘HepMC::GenParticle*’ [-Wconversion-null]
return false;
^~~~~
Makefile:478: recipe for target 'CommonIO.lo' failed
make[1]: *** [CommonIO.lo] Error 1
make[1]: Leaving directory '/home/maxfieg/Desktop/FelixResearch/junk/hep_build2/HepMC2.04/src'
Makefile:397: recipe for target 'all-recursive' failed
make: *** [all-recursive] Error 1

cross-compilation with GCC fails under CYGWIN when <iostream> is included

I've built the cross toolchain for Linux under CYGWIN environment using the article at https://preshing.com/20141119/how-to-build-a-gcc-cross-compiler/ as a source.
Compilation and installation finished with success.
Used components are:
binutils-2.35
cloog-0.18.1
gcc-10.2.0
glibc-2.32
gmp-6.1.2
isl-0.20
linux-5.9.3
mpc-1.1.0
mpfr-4.0.2
GCC is configured as:
$ x86_64-unknown-linux-gnu-g++ --verbose
Using built-in specs.
COLLECT_GCC=x86_64-unknown-linux-gnu-g++
COLLECT_LTO_WRAPPER=/opt/cross/x86_64-unknown-linux-gnu/libexec/gcc/x86_64-unknown-linux-
gnu/10.2.0/lto-wrapper.exe
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-10.2.0/configure --prefix=/opt/cross/x86_64-unknown-linux-gnu --
target=x86_64-unknown-linux-gnu --enable-languages=c,c++ --disable-nls --disable-multilib --with-
headers=/opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/linux
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.2.0 (GCC)
But when I'm trying to compile the simple Hello World application that includes I'm getting a lot of different errors:
$ x86_64-unknown-linux-gnu-g++ main.cpp
In file included from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/x86_64-unknown-linux-gnu/bits/gthr-default.h:35,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/x86_64-unknown-linux-gnu/bits/gthr.h:148,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/ext/atomicity.h:35,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/bits/ios_base.h:39,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/ios:42,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/ostream:38,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/iostream:39,
from main.cpp:1:
/opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/pthread.h:240:34: error: 'clockid_t' has not been declared
240 | clockid_t __clockid,
| ^~~~~~~~~
/opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/pthread.h:375:12: error: 'cpu_set_t' does not name a type
375 | const cpu_set_t *__cpuset)
| ^~~~~~~~~
/opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/pthread.h:382:6: error: 'cpu_set_t' has not been declared
382 | cpu_set_t *__cpuset)
| ^~~~~~~~~
/opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/pthread.h:466:14: error: 'cpu_set_t' does not name a type
466 | const cpu_set_t *__cpuset)
| ^~~~~~~~~
/opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/pthread.h:471:8: error: 'cpu_set_t' has not been declared
471 | cpu_set_t *__cpuset)
| ^~~~~~~~~
/opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/pthread.h:765:9: error: 'clockid_t' has not been declared
765 | clockid_t __clockid,
| ^~~~~~~~~
/opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/pthread.h:911:12: error: 'clockid_t' has not been declared
911 | clockid_t __clockid,
| ^~~~~~~~~
/opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/pthread.h:933:12: error: 'clockid_t' has not been declared
933 | clockid_t __clockid,
| ^~~~~~~~~
In file included from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/x86_64-unknown-linux-gnu/bits/gthr.h:148,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/ext/atomicity.h:35,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/bits/ios_base.h:39,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/ios:42,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/ostream:38,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/iostream:39,
from main.cpp:1:
/opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/x86_64-unknown-linux-gnu/bits/gthr-default.h:114:1: error: 'sched_yield' was not declared in this scope; did you mean 'pthread_yield'?
114 | __gthrw(sched_yield)
| ^~~~~~~
/opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/x86_64-unknown-linux-gnu/bits/gthr-default.h:114:1: error: 'sched_yield' was not declared in this scope; did you mean 'pthread_yield'?
114 | __gthrw(sched_yield)
| ^~~~~~~
/opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/x86_64-unknown-linux-gnu/bits/gthr-default.h: In function 'int __gthread_yield()':
/opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/x86_64-unknown-linux-gnu/bits/gthr-default.h:693:33: error: '__gthrw_sched_yield' cannot be used as a function
693 | return __gthrw_(sched_yield) ();
| ^
In file included from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/sys/select.h:37,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/sys/types.h:179,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/stdlib.h:394,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/cstdlib:75,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/ext/string_conversions.h:41,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/bits/basic_string.h:6535,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/string:55,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/bits/locale_classes.h:40,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/bits/ios_base.h:41,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/ios:42,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/ostream:38,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/iostream:39,
from main.cpp:1:
/opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/bits/types/struct_timeval.h: At global scope:
/opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/bits/types/struct_timeval.h:8:8: error: redefinition of 'struct timeval'
8 | struct timeval
| ^~~~~~~
In file included from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/pthread.h:23,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/x86_64-unknown-linux-gnu/bits/gthr-default.h:35,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/x86_64-unknown-linux-gnu/bits/gthr.h:148,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/ext/atomicity.h:35,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/bits/ios_base.h:39,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/ios:42,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/ostream:38,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/iostream:39,
from main.cpp:1:
/opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/sys-include/time.h:16:8: note: previous definition of 'struct timeval'
16 | struct timeval {
| ^~~~~~~
In file included from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/ext/string_conversions.h:44,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/bits/basic_string.h:6535,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/string:55,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/bits/locale_classes.h:40,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/bits/ios_base.h:41,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/ios:42,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/ostream:38,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/iostream:39,
from main.cpp:1:
/opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/ext/string_conversions.h: In constructor '__gnu_cxx::__stoa(_TRet (*)(const _CharT*, _CharT**, _Base ...), const char*, const _CharT*, std::size_t*, _Base ...)::_Save_errno::_Save_errno()':
/opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/ext/string_conversions.h:63:27: error: 'errno' was not declared in this scope
63 | _Save_errno() : _M_errno(errno) { errno = 0; }
| ^~~~~
In file included from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/bits/basic_string.h:6535,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/string:55,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/bits/locale_classes.h:40,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/bits/ios_base.h:41,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/ios:42,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/ostream:38,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/iostream:39,
from main.cpp:1:
/opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/ext/string_conversions.h:45:1: note: 'errno' is defined in header '<cerrno>'; did you forget to '#include <cerrno>'?
44 | #include <cerrno>
+++ |+#include <cerrno>
45 |
In file included from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/ext/string_conversions.h:44,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/bits/basic_string.h:6535,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/string:55,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/bits/locale_classes.h:40,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/bits/ios_base.h:41,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/ios:42,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/ostream:38,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/iostream:39,
from main.cpp:1:
/opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/ext/string_conversions.h: In destructor '__gnu_cxx::__stoa(_TRet (*)(const _CharT*, _CharT**, _Base ...), const char*, const _CharT*, std::size_t*, _Base ...)::_Save_errno::~_Save_errno()':
/opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/ext/string_conversions.h:64:23: error: 'errno' was not declared in this scope
64 | ~_Save_errno() { if (errno == 0) errno = _M_errno; }
| ^~~~~
/opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/ext/string_conversions.h:64:23: note: 'errno' is defined in header '<cerrno>'; did you forget to '#include <cerrno>'?
/opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/ext/string_conversions.h: In function '_Ret __gnu_cxx::__stoa(_TRet (*)(const _CharT*, _CharT**, _Base ...), const char*, const _CharT*, std::size_t*, _Base ...)':
/opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/ext/string_conversions.h:84:16: error: 'errno' was not declared in this scope
84 | else if (errno == ERANGE
| ^~~~~
/opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/ext/string_conversions.h:84:16: note: 'errno' is defined in header '<cerrno>'; did you forget to '#include <cerrno>'?
In file included from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/system_error:39,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/bits/ios_base.h:46,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/ios:42,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/ostream:38,
from /opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/iostream:39,
from main.cpp:1:
/opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/x86_64-unknown-linux-gnu/bits/error_constants.h: At global scope:
/opt/cross/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/include/c++/10.2.0/x86_64-unknown-linux-gnu/bits/error_constants.h:122:27: error: 'ENOTSUP' was not declared in this scope
122 | not_supported = ENOTSUP,
|
UPD: WSL and virtual machines are not an option in my case
I've managed to solve the issue.
The problem was in the sys-include directory
opt/cross/x86_64-unknown-linux-gnu/sys-include
This directory has include files with the same names as the ones from
opt/cross/x86_64-unknown-linux-gnu/include
but with different content.
The sys-include directory was searched by the compiler before the regular include.
Renaming or removing sys-include solves the issue and code can be compiled.
I don't know the purpose of the sys-include directory, when it was created and why the duplicated files in this directory have another content.
Accepting my own post as answer to indicate that the issue can be solved.

C++ API for LLVM library generates too many warnings

I am not sure if I am the only person or this is the problem of so many other people.
What I suffer from is that for an even simple code that includes LLVM headers regardless of what ever I write in my main function, I get too many warnings when I compile my codes with extra warnings:
#include <llvm/IR/IRBuilder.h>
#include <llvm/IR/Verifier.h>
#include <llvm/Support/TargetSelect.h>
#include <llvm/ExecutionEngine/ExecutionEngine.h>
#include <llvm/IR/Instructions.h>
int main()
{
return 0;
}
I cat get these warnings by using either gcc or clang:
g++-9 -std=c++17 main.cpp -Wall -Wextra -I/usr/lib/llvm-9/include -c -o main.o
clang++-9 -std=c++17 main.cpp -Wall -Wextra -I/usr/lib/llvm-9/include -c -o main.o
They are mainly unused parameters:
In file included from /usr/lib/llvm-9/include/llvm/IR/ConstantFolder.h:20,
from /usr/lib/llvm-9/include/llvm/IR/IRBuilder.h:24,
from main.cpp:1:
/usr/lib/llvm-9/include/llvm/IR/Constants.h: In member function ‘llvm::Value* llvm::ConstantData::handleOperandChangeImpl(llvm::Value*, llvm::Value*)’:
/usr/lib/llvm-9/include/llvm/IR/Constants.h:60:41: warning: unused parameter ‘From’ [-Wunused-parameter]
60 | Value *handleOperandChangeImpl(Value *From, Value *To) {
| ~~~~~~~^~~~
/usr/lib/llvm-9/include/llvm/IR/Constants.h:60:54: warning: unused parameter ‘To’ [-Wunused-parameter]
60 | Value *handleOperandChangeImpl(Value *From, Value *To) {
| ~~~~~~~^~
In file included from /usr/lib/llvm-9/include/llvm/IR/ConstantFolder.h:21,
from /usr/lib/llvm-9/include/llvm/IR/IRBuilder.h:24,
from main.cpp:1:
/usr/lib/llvm-9/include/llvm/IR/InstrTypes.h: In member function ‘bool llvm::CallBase::isFnAttrDisallowedByOpBundle(llvm::StringRef) const’:
/usr/lib/llvm-9/include/llvm/IR/InstrTypes.h:1913:47: warning: unused parameter ‘S’ [-Wunused-parameter]
1913 | bool isFnAttrDisallowedByOpBundle(StringRef S) const {
| ~~~~~~~~~~^
In file included from /usr/lib/llvm-9/include/llvm/IR/IRBuilder.h:33,
from main.cpp:1:
/usr/lib/llvm-9/include/llvm/IR/Instructions.h: In member function ‘llvm::BasicBlock* llvm::ReturnInst::getSuccessor(unsigned int) const’:
/usr/lib/llvm-9/include/llvm/IR/Instructions.h:2943:37: warning: unused parameter ‘idx’ [-Wunused-parameter]
2943 | BasicBlock *getSuccessor(unsigned idx) const {
| ~~~~~~~~~^~~
...
I just truncate these warnings. They are too many.
When I turn on the -Wconversion the problem becomes even worse:
In file included from /usr/lib/llvm-9/include/llvm/Support/MathExtras.h:17,
from /usr/lib/llvm-9/include/llvm/ADT/SmallVector.h:19,
from /usr/lib/llvm-9/include/llvm/ADT/STLExtras.h:20,
from /usr/lib/llvm-9/include/llvm/ADT/StringRef.h:12,
from /usr/lib/llvm-9/include/llvm/ADT/StringMap.h:16,
from /usr/lib/llvm-9/include/llvm/Support/Host.h:16,
from /usr/lib/llvm-9/include/llvm/ADT/Hashing.h:48,
from /usr/lib/llvm-9/include/llvm/ADT/ArrayRef.h:12,
from /usr/lib/llvm-9/include/llvm/IR/IRBuilder.h:18,
from main.cpp:1:
/usr/lib/llvm-9/include/llvm/Support/SwapByteOrder.h: In function ‘uint16_t llvm::sys::SwapByteOrder_16(uint16_t)’:
/usr/lib/llvm-9/include/llvm/Support/SwapByteOrder.h:36:23: warning: conversion from ‘int’ to ‘uint16_t’ {aka ‘short unsigned int’} may change value [-Wconversion]
36 | uint16_t Hi = value << 8;
| ~~~~~~^~~~
/usr/lib/llvm-9/include/llvm/Support/SwapByteOrder.h:37:23: warning: conversion from ‘int’ to ‘uint16_t’ {aka ‘short unsigned int’} may change value [-Wconversion]
37 | uint16_t Lo = value >> 8;
| ~~~~~~^~~~
In file included from /usr/lib/llvm-9/include/llvm/ADT/STLExtras.h:20,
from /usr/lib/llvm-9/include/llvm/ADT/StringRef.h:12,
from /usr/lib/llvm-9/include/llvm/ADT/StringMap.h:16,
from /usr/lib/llvm-9/include/llvm/Support/Host.h:16,
from /usr/lib/llvm-9/include/llvm/ADT/Hashing.h:48,
from /usr/lib/llvm-9/include/llvm/ADT/ArrayRef.h:12,
from /usr/lib/llvm-9/include/llvm/IR/IRBuilder.h:18,
from main.cpp:1:
/usr/lib/llvm-9/include/llvm/ADT/SmallVector.h: In constructor ‘llvm::SmallVectorBase::SmallVectorBase(void*, size_t)’:
/usr/lib/llvm-9/include/llvm/ADT/SmallVector.h:45:35: warning: conversion from ‘size_t’ {aka ‘long unsigned int’} to ‘unsigned int’ may change value [-Wconversion]
45 | : BeginX(FirstEl), Capacity(TotalCapacity) {}
| ^~~~~~~~~~~~~
...
I get these warnings by clang too:
...
In file included from main.cpp:1:
In file included from /usr/lib/llvm-9/include/llvm/IR/IRBuilder.h:18:
In file included from /usr/lib/llvm-9/include/llvm/ADT/ArrayRef.h:12:
/usr/lib/llvm-9/include/llvm/ADT/Hashing.h:190:15: warning: implicit conversion changes signedness: 'const char' to 'uint8_t' (aka 'unsigned char') [-Wsign-conversion]
uint8_t a = s[0];
~ ^~~~
/usr/lib/llvm-9/include/llvm/ADT/Hashing.h:191:15: warning: implicit conversion changes signedness: 'const char' to 'uint8_t' (aka 'unsigned char') [-Wsign-conversion]
uint8_t b = s[len >> 1];
~ ^~~~~~~~~~~
/usr/lib/llvm-9/include/llvm/ADT/Hashing.h:192:15: warning: implicit conversion changes signedness: 'const char' to 'uint8_t' (aka 'unsigned char') [-Wsign-conversion]
uint8_t c = s[len - 1];
~ ^~~~~~~~~~
...
This is just a MWE. Adding more headers, I can get other types of warnings such as
/usr/lib/llvm-9/include/llvm/ADT/Twine.h:232:16: warning: ‘<anonymous>.llvm::Twine::RHS.llvm::Twine::Child::twine’ may be used uninitialized in this function [-Wmaybe-uninitialized]
!RHS.twine->isBinary())
~~~~^~~~~
Now, I am wondering whether LLVM is written carelessly? I always turn on all warnings and make sure my application compiles with 0 warnings. When I do this while using LLVM all warnings of my code are burried under LLVM ones. I cannot easily see them. Usually the first advise from people is to turn off those warnings switches. I strictly resist that. I want to find them for my application. The alternative solution comes to my mind is to turn off these warnings only for LLVM but not for my application. Is this possible especially when using CMake?
The issue of system header files causing warnings is a common one. It is not really for me to judge whether the authors of those headers were "careless" or not, but there is a relatively simple way to disable specific warnings before including the 'offending' headers, then restore your 'full' warnings once they have been included.
For clang you can do this with various #pragma diagnostic ... lines, as shown in the following code snippet:
#if defined (__clang__)
#pragma clang diagnostic push // Saves current diagnostic settings
#pragma clang diagnostic ignored "-Wsign-conversion" // Ignore this warning
#pragma clang diagnostic ignored "-Wunused-parameter" // and this one...
// ... Add similar lines for other warnings you wish to disable
#endif
// Now include the 'offending' headers ...
#include <llvm/IR/IRBuilder.h>
#include <llvm/IR/Verifier.h>
#include <llvm/Support/TargetSelect.h>
#include <llvm/ExecutionEngine/ExecutionEngine.h>
#include <llvm/IR/Instructions.h>
#if defined(__clang__)
#pragma clang diagnostic pop // Restores the saved settings
#endif
I don't have access to a GCC compiler but I believe very similar directives can be used: just substitute GCC for clang in the lines where that occurs. More information on such #pragma directives (for the GCC versions) can be found here.
It is dependent on your GCC/clang/OS installation. On Fedora 32 it works as expected out of the box with system gcc-10.2.1-1.fc32.x86_64 + system clang-10.0.0-2.fc32.x86_64:
#include <llvm/IR/IRBuilder.h>
#include <llvm/IR/Verifier.h>
#include <llvm/Support/TargetSelect.h>
#include <llvm/ExecutionEngine/ExecutionEngine.h>
#include <llvm/IR/Instructions.h>
static void func(int val) {}
int main()
{
func(42);
return 0;
}
For GCC:
$ g++ -o stackoverflowllvmwarnings stackoverflowllvmwarnings.C $(llvm-config --cflags --libs) -std=c++17 -Wall -Wextra
stackoverflowllvmwarnings.C: In function ‘void func(int)’:
stackoverflowllvmwarnings.C:7:22: warning: unused parameter ‘val’ [-Wunused-parameter]
7 | static void func(int val) {}
| ~~~~^~~
$ _
For clang:
$ clang++ -o stackoverflowllvmwarnings stackoverflowllvmwarnings.C $(llvm-config --cflags --libs) -std=c++17 -Wall -Wextra
stackoverflowllvmwarnings.C:7:22: warning: unused parameter 'val' [-Wunused-parameter]
static void func(int val) {}
^
1 warning generated.
$ _
If you really want (you do not) the warnings even for system headers use Wsystem-headers (it works similar way both for gcc and clang):
$ clang++ -o stackoverflowllvmwarnings stackoverflowllvmwarnings.C $(llvm-config --cflags --libs) -std=c++17 -Wall -Wextra -Wsystem-headers
In file included from stackoverflowllvmwarnings.C:1:
In file included from /usr/include/llvm/IR/IRBuilder.h:17:
In file included from /usr/include/llvm-c/Types.h:17:
In file included from /usr/include/llvm-c/DataTypes.h:28:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/cmath:42:
/usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/bits/cpp_type_traits.h:110:12: warning: keyword '__is_void' will be made available as an identifier for the remainder of the translation unit [-Wkeyword-compat]
struct __is_void
^
...