Meaning of the g++ flags "-Wall", " -W", and "-Werror" - gcc-warning

What are these and what do they do?
-Wall
-W
-Werror
I am using the terminal in Ubuntu to compile programs with this command:
g++ -Wall -W -Werror main.cpp -o exec
What is the explanation?

-Wall: enable a set of warning, but actually not all.
-W: enable extra warnings. It's advised to use -Wextra instead which has the same meaning
-Werror: every warning is treated as an error.
See GCC documentation:
3.8 Options to Request or Suppress Warnings

Related

Compiling psqlODBC on CENTOS 7 gives me errors in connection.c - undeclared identifiers

So i'm stuck again.
What I want to do: access a postgreSQL database via database link from Oracle (12.1 - yes, I know it's old ...).
Oracle is running on Centos 7.
Initially I did a
yum -y install postgresql-odbc
yum -y install unixODBC
and was able to access postgreSQL (running on another machine).
But it didn't work for UTF-8 data. Got a hint that this might be due to an old version of unixODBC so I decided to compile from source (as the centos package is rather old).
Compiling and installing unixODBC worked without a hassle:
wget http://www.unixodbc.org/unixODBC-2.3.11.tar.gz
tar xzf unixODBC-2.3.11.tar.gz
cd unixODBC-2.3.11/
./configure
make
make install
But compiling psqlODBC is where it's at:
yum install postgresql
yum install postgresql-devel
wget https://ftp.postgresql.org/pub/odbc/versions/src/psqlodbc-13.02.0000.tar.gz
cd psqlodbc-13.02.0000/
./configure
make
...
Make gives me the following output:
[root#tukanbox psqlodbc-13.02.0000]# make
make all-am
make[1]: Entering directory `/root/psqlodbc-13.02.0000'
/bin/sh ./libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I/usr/local/include -I/usr/include -I/usr/include/pgsql/internal -DUNICODE_SUPPORT -g -O2 -Wall -MT psqlodbcw_la-connection.lo -MD -MP -MF .deps/psqlodbcw_la-connection.Tpo -c -o psqlodbcw_la-connection.lo `test -f 'connection.c' || echo './'`connection.c
libtool: compile: gcc -DHAVE_CONFIG_H -I. -I/usr/local/include -I/usr/include -I/usr/include/pgsql/internal -DUNICODE_SUPPORT -g -O2 -Wall -MT psqlodbcw_la-connection.lo -MD -MP -MF .deps/psqlodbcw_la-connection.Tpo -c connection.c -fPIC -DPIC -o .libs/psqlodbcw_la-connection.o
connection.c: In function 'handle_pgres_error':
connection.c:900:45: error: 'PG_DIAG_SCHEMA_NAME' undeclared (first use in this function)
errschemaname = PQresultErrorField(pgres, PG_DIAG_SCHEMA_NAME);
^
connection.c:900:45: note: each undeclared identifier is reported only once for each function it appears in
connection.c:901:44: error: 'PG_DIAG_TABLE_NAME' undeclared (first use in this function)
errtablename = PQresultErrorField(pgres, PG_DIAG_TABLE_NAME);
^
connection.c:902:45: error: 'PG_DIAG_COLUMN_NAME' undeclared (first use in this function)
errcolumnname = PQresultErrorField(pgres, PG_DIAG_COLUMN_NAME);
^
connection.c:903:47: error: 'PG_DIAG_DATATYPE_NAME' undeclared (first use in this function)
errdatatypename = PQresultErrorField(pgres, PG_DIAG_DATATYPE_NAME);
^
make[1]: *** [psqlodbcw_la-connection.lo] Fehler 1
make[1]: Leaving directory `/root/psqlodbc-13.02.0000'
make: *** [all] Fehler 2
Wondering where to declare these undeclared idenifiers. What does it want to know here? How to solve it?
No answer to the problem of not being able to compile - but an answer to the original problem that the original packages didn't work for UTF8:
https://www.postgresql.org/message-id/OFA166DBFD.19742AF7-ONC1257B6A.005692E6-C1257B6A.0056F890#lladro.net
This has to be done in the database as sysdba:
select fds_class_name from HS_FDS_CLASS;
select * from hs_class_caps where upper(CAP_DESCRIPTION) like '%NCHAR%' and FDS_CLASS_NAME ='ODBC12.1.0.1.0_0017';
exec DBMS_HS.ALTER_CLASS_CAPS('ODBC12.1.0.1.0_0017' , 564, 'ODBC12.1.0.1.0_0017', 564,131071, NULL, NULL);

Unable to compile / install Orange Data Mining on Raspberry Pi

I have been trying to compile and install Orange 2.7.8 on Raspberry Pi 2 but was unsuccessful. I tried compiling by hand and also used pip install orange as per suggestion from: How can I install python-Orange on ubuntu 12.10
The first warning I got this:
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -I/usr/lib/pymodules/python2.7/numpy/core/include -Isource/include -Isource/orange/liblinear -Isource/orange/ppp -Isource/orange/px -I/usr/include/python2.7 -c source/orange/basstat.cpp -o build/temp.linux-armv7l-2.7/source/orange/basstat.o -fPIC -w -DLINUX -DORANGE_EXPORTS
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for Ada/C/ObjC but not for C++ [enabled by default]
But it kept going without an error. Then when it started compiling with g++, it started getting an error on multiple definition of TOrangeVector. There are many errors like the lines below:
build/temp.linux-armv7l-2.7/source/orange/distance.o:(.data.rel.ro+0x6c): multiple definition of `typeinfo for TOrangeVector<GCPtr<TVariable>, true>'
build/temp.linux-armv7l-2.7/source/orange/basstat.o:(.data.rel.ro+0x6c): first defined here
build/temp.linux-armv7l-2.7/source/orange/distance.o: In function `TExamplesDistance::classDescription() const':
/home/pi/build/orange/source/orange/ppp/distance.ppp:17: multiple definition of `typeinfo for TOrangeVector<bool, false>'
In the end it got kicked out:
/home/pi/build/orange/source/orange/vectortemplates.hpp:1075: multiple definition of `typeinfo name for TOrangeVector<GCPtr<TOrangeVector<GCPtr<TVariable>, true> >, true>'
build/temp.linux-armv7l-2.7/source/orange/basstat.o:/home/pi/build/orange/source/orange/ppp/../basstat.hpp:8: first defined here
collect2: ld returned 1 exit status
error: command 'g++' failed with exit status 1
Any guide on how to tweak this to make it compiled would be appreciated.

Matlab Mex compilation error

I’m using the Random Forest library for Matlab (link). I’m using it for classification. On Windows it works very well out of the box (precombiled mex files) but I also want to run it on a CentOS cluster.
I have tried to compile it on the cluster by executing make mex but I’m getting an error. The output is as follows:
rm twonorm_test -rf
rm tempbuild/*.o *.o -rf
rm *~ -rf
rm *.mexw32 twonorm_test -rf
rm *.mexa64 -rf
rm classRF -rf
rm *.exe -rf
echo 'Compiling classTree.cpp'
Compiling classTree.cpp
g++ -fpic -O2 -funroll-loops -msse3 -c src/classTree.cpp -o tempbuild/classTree.o
echo 'Compiling Cokus (random number generator)'
Compiling Cokus (random number generator)
g++ -fpic -O2 -funroll-loops -msse3 -c src/cokus.cpp -o tempbuild/cokus.o
echo 'Compiling rfsub.f (fortran subroutines)'
Compiling rfsub.f (fortran subroutines)
gfortran -O2 -fpic -c src/rfsub.f -o rfsub.o
echo 'Compiling rfutils.cpp'
Compiling rfutils.cpp
g++ -fpic -O2 -funroll-loops -msse3 -c src/rfutils.cpp -o tempbuild/rfutils.o
echo 'Generating Mex'
Generating Mex
mex src/mex_ClassificationRF_train.cpp src/classRF.cpp tempbuild/classTree.o tempbuild/rfutils.o rfsub.o tempbuild/cokus.o -o mexClassRF_train -lgfortran -lm -DMATLAB -g
Unknown MEX argument '-o'.
make: *** [mex_classRF] Error 255
Does somebody knows how to solve this issue? If you want, you can take RF_MexStandalone-v0.02.zip from the above link and then go to randomforest-matlab/RF_Reg_C/Makefile.
Edit: I have change -o to -output but now the output is the following:
rm twonorm_test -rf
rm tempbuild/*.o *.o -rf
rm *~ -rf
rm *.mexw32 twonorm_test -rf
rm *.mexa64 -rf
rm classRF -rf
rm *.exe -rf
echo 'Compiling classTree.cpp'
Compiling classTree.cpp
g++ -fpic -O2 -funroll-loops -msse3 -c src/classTree.cpp -o tempbuild/classTree.o
echo 'Compiling Cokus (random number generator)'
Compiling Cokus (random number generator)
g++ -fpic -O2 -funroll-loops -msse3 -c src/cokus.cpp -o tempbuild/cokus.o
echo 'Compiling rfsub.f (fortran subroutines)'
Compiling rfsub.f (fortran subroutines)
gfortran -O2 -fpic -c src/rfsub.f -o rfsub.o
echo 'Compiling rfutils.cpp'
Compiling rfutils.cpp
g++ -fpic -O2 -funroll-loops -msse3 -c src/rfutils.cpp -o tempbuild/rfutils.o
echo 'Generating Mex'
Generating Mex
mex src/mex_ClassificationRF_train.cpp src/classRF.cpp tempbuild/classTree.o tempbuild/rfutils.o rfsub.o tempbuild/cokus.o -output mexClassRF_train -lgfortran -lm -DMATLAB -g
Building with 'g++'.
cc1plus: error: unrecognized command line option "-std=c++11"
make: *** [mex_classRF] Error 255
I did not find an option -std=c++11 in the makefile.
The error is quite self-explanatory: the option -o is not recognized. If you type mex -help you see the options mex accepts. Try to replace -o with -output.
EDIT regarding the std=c++11 option, you are probably using an old version of gcc compiler. You can either change it to std=c++0x which is the equivalent option (but note that some features of the c++11 standard may not be present\implemented), or upgrade to an up-to-date version of gcc.
If you need more help, please report the output of g++ --version.

CMAKE separate Linker and Compiler Flags

Right now my toolchain.cmake looks loke this:
CMAKE_FORCE_C_COMPILER(arm-none-eabi-gcc GNU)
CMAKE_FORCE_CXX_COMPILER(arm-none-eabi-gcc GNU)
SET(CMAKE_ASM_COMPILER arm-none-eabi-as)
SET(CMAKE_OBJCOPY arm-none-eabi-objcopy CACHE INTERNAL "objcopy" FORCE)
SET(CMAKE_OBJDUMP arm-none-eabi-objdump CACHE INTERNAL "objdump" FORCE)
# Compiler Flags
SET(MCU_FLAGS "-mcpu=cortex-m3 -mthumb")
SET(CMAKE_BUILD_FLAGS "-O2 -g -mfpu=vfp -mfloat-abi=soft -Wa,-meabi=5 -ffunction-sections -fno-common -pedantic -Wall -Wextra -Wno-missing-field-initializers")
SET(CMAKE_C_FLAGS "${MCU_FLAGS} ${CMAKE_BUILD_FLAGS}" CACHE INTERNAL "c compiler flags")
SET(CMAKE_CXX_FLAGS ${CMAKE_C_FLAGS} CACHE INTERNAL "cxx compiler flags")
SET(CMAKE_ASM_FLAGS "-g -mcpu=cortex-m3 -mthumb -mfpu=vfp -mfloat-abi=soft -meabi=5 -warn" CACHE INTERNAL "asm compiler flags")
SET(CMAKE_EXE_LINKER_FLAGS "-mcpu=cortex-m3 -mthumb -Wall -Wextra -Wno-missing-field-initializers -g -nostartfiles -Wl,-T1.ld,-M=1.map,--gc-sections" CACHE INTERNAL "exe link flags")
The problem is that CMake passes to the Linker additionally the Compiler-flags! Is there any way to separate these two?
Another thing is if I use another compiler-tool-chain (Like Fujitsu Softtune) how can I tell CMake explicitly to take a Linker and not the compiler to Link objects?
Thanks
So i finally solved it. for evryone else with the same problem, i changed CMakelists as follow:
add_executable(${PROJECT_NAME} ${PROJECT_SOURCES})
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE C CXX ASM)
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES LINK_FLAGS "${LD_FLAGS_STR} -m ${PROJECT_NAME}.map")
set(CMAKE_C_LINK_EXECUTABLE "FLNK907S.EXE -o <TARGET> <LINK_FLAGS> <OBJECTS>")
and it works fine...
where ${LD_FLAGS_STR} is just the list of my linker flags (own variable). and LNK907S.EXE is the name of Linker i 'm using (Fujitsu).
Try using SET_TARGET_PROPERTIES to set the link flags, respectively:
SET(MCU_FLAGS "-mcpu=cortex-m3 -mthumb")
SET(CMAKE_BUILD_FLAGS "-O2 -g -mfpu=vfp -mfloat-abi=soft -Wa,-meabi=5 -ffunction-sections -fno-common -pedantic -Wall -Wextra -Wno-missing-field-initializers")
SET(CMAKE_C_FLAGS "${MCU_FLAGS} ${CMAKE_BUILD_FLAGS}")
SET(CMAKE_CXX_FLAGS ${CMAKE_C_FLAGS})
SET(CMAKE_ASM_FLAGS "-g -mcpu=cortex-m3 -mthumb -mfpu=vfp -mfloat-abi=soft -meabi=5 -warn")
SET_TARGET_PROPERTIES(FOO PROPERTIES LINK_FLAGS "-mcpu=cortex-m3 -mthumb -Wall -Wextra -Wno-missing-field-initializers -g -nostartfiles -Wl,-T1.ld,-M=1.map,--gc-sections")
Here, I have assumed your excutable is called "FOO". Note that the link libaries are specified on a per-target basis. If you need special compiler flags for the target only, you can use COMPILE_FLAGS in SET_TARGET_PROPERTIES as well.
With newer versions of cmake, using generator expressions [1] has been my preferred approach.
target_compile_options(${TARGET_NAME}
PRIVATE
$<$<COMPILE_LANGUAGE:C>:${C_DEFS} ${C_FLAGS}>
$<$<COMPILE_LANGUAGE:ASM>:${ASM_FLAGS}>)
[1] https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html

unable to build binutils for my cross compiler

i am trying to build binutils 2.19.1 with mingw/msys using following commands:
export PREFIX=/usr/local/cross
export TARGET=i586-elf
cd /usr/src
mkdir build-binutils
cd /usr/src/build-binutils
../binutils-x.xx/configure --target=$TARGET --prefix=$PREFIX --disable-nls
make all
make install
and im getting following errors:
/bin/sh ./libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I../../binuti
ls-2.19.1/bfd -I. -D__USE_MINGW_FSEEK -I. -I../../binutils-2.19.1/bfd -I../..
/binutils-2.19.1/bfd/../include -W -Wall -Wstrict-prototypes -Wmissing-proto
types -Wno-format -Werror -g -O2 -D__USE_MINGW_ACCESS -c -o archive.lo ../../bin
utils-2.19.1/bfd/archive.c
./libtool: line 2258: cygpath: command not found
libtool: compile: gcc -DHAVE_CONFIG_H -I. -I../../binutils-2.19.1/bfd -I. -D__U
SE_MINGW_FSEEK -I. -I../../binutils-2.19.1/bfd -I../../binutils-2.19.1/bfd/../in
clude -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wno-format -Werror -g -
O2 -D__USE_MINGW_ACCESS -c "" -o archive.o
gcc.exe: error: : No such file or directory
gcc.exe: fatal error: no input files
compilation terminated.
make[3]: *** [archive.lo] Error 1
make[3]: Leaving directory `/usr/src/build-binutils/bfd'
make[2]: *** [install-recursive] Error 1
make[2]: Leaving directory `/usr/src/build-binutils/bfd'
make[1]: *** [install-bfd] Error 2
make[1]: Leaving directory `/usr/src/build-binutils'
make: *** [install] Error 2
/x.sh: line 8: ../gcc-4.5.0/configure: No such file or directory
make: *** No rule to make target `all-gcc'. Stop.
make: *** No rule to make target `install-gcc'. Stop.
i am getting the same error even for the diff binutils version,i have tried binutils-2.19.1, 2.22.0, 2.23.1
so what can be the problem ??
also my mingw's gcc compiler version is 4.6.2
i've also tried the command
make CFLAGS="-Os -w"
bt still the same problem persists
I'm getting a similar error ("cygpath: command not found"), but with newer versions. FWICT there is a line within binutils that assumes that Cygwin is present, although I didn't see any notes in the build instructions saying that Cygwin was required (I might have missed it, though).
I suppose the correct approach would be to install Cygwin, but I'm not sure if that will interfere with Mingw in other ways. It looks like binutils is just trying to use cygpath to convert between O/S path naming conventions, so I got around this problem by creating a little dummy cygpath shell script:
#options described at http://cygwin-lite.sourceforge.net/html/cygpath.html
#echo "MISSING CYGPATH"
if [ "x$1" == "x-w" ]
then
echo $2 #just echo path name back as-is
else
read -p "MISSING CYGPATH. PARAMS WERE: 1=$1 2=$2 3=$3 4=$4 5=$5"
fi
I placed this on the PATH so binutils could find it, instead of getting an error during the build. This script just echoes the path name back as-is (for the path renaming scenario), since Windows seems to be able to understand Unix-style paths anyways these days (and I was running on Windows). For anything else, this script will pause and display the first few command line parameters, to provide some hints as to what further functionality is needed.
HTH someone get a little farther