cppcheck on linux setup issue - linux

I downloaded the zip file from https://github.com/danmar/cppcheck/tree/1.77, unzipped it and gave a make command which generated cppcheck binary.
Next when I run the cppcheck on a test code no error is generated.
sles12-box:/home/test/cppchecker_test/cppcheck-1.77 # cppcheck /home/demo_code/test_code.c
Checking /home/demo_code/test_code.c ...
The source code is
sles12-box:/home/test/cppchecker_test/cppcheck-1.77 # vi /home/demo_code/test_code.c
main(int argc, char* argv[])
{
char cobj[7] = "yahoo";
char *cobjPtr = cobj;
int iobj = 4;
printf("########################### CPPCHECK TEST ############################\n");
yahoo
}
When I tried to compile using the other build command specified in the above mentioned page I get below error
sles12-box:/home/test/cppchecker_test/cppcheck-1.77 # make SRCDIR=build CFGDIR=cfg HAVE_RULES=yes CXXFLAGS="-O2 -DNDEBUG -Wall -Wno-sign-compare -Wno-unused-function"
make: pcre-config: Command not found
g++ -Ilib -Iexternals/simplecpp -Iexternals/tinyxml -DCFGDIR=\"cfg\" -O2 -DNDEBUG -Wall -Wno-sign-compare -Wno-unused-function -std=c++0x -DHAVE_RULES -DTIXML_USE_STL -c -o build/analyzerinfo.o build/analyzerinfo.cpp
make: pcre-config: Command not found
g++ -Ilib -Iexternals/simplecpp -Iexternals/tinyxml -DCFGDIR=\"cfg\" -O2 -DNDEBUG -Wall -Wno-sign-compare -Wno-unused-function -std=c++0x -DHAVE_RULES -DTIXML_USE_STL -c -o build/astutils.o build/astutils.cpp
make: pcre-config: Command not found
g++ -Ilib -Iexternals/simplecpp -Iexternals/tinyxml -DCFGDIR=\"cfg\" -O2 -DNDEBUG -Wall -Wno-sign-compare -Wno-unused-function -std=c++0x -DHAVE_RULES -DTIXML_USE_STL -c -o build/check.o build/check.cpp
make: pcre-config: Command not found
.
.
.
I tried building the cppcheck 1.76 version but I get different error there:
sles12-box:/home/test/cppchecker_test/1.76/cppcheck-1.76.1 # sudo make install
Makefile:88: Extraneous text after `else' directive
Makefile:90: Extraneous text after `else' directive
Makefile:90: *** only one `else' per conditional. Stop.
How to get the cppcheck setup ready and functional?

Did you try to install the binary package? https://software.opensuse.org/package/cppcheck
re 1.77: pcre-config is part of the pcre package (most likely the development package

Related

How does make use variables when expanding and compiling before linking?

Info:
Linux watvde0453 3.10.0-1062.1.1.el7.x86_64 #1 SMP Fri Sep 13 22:55:44 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
GNU Make 4.2.1
Built for x86_64-pc-linux-gnu
Hi
I have been playing around with a make file to allow builds of shared, static libraries and an exe (and also to get some sort of understanding about how it works) and came across some behavior I do not understand.
I was trying to separate out the flags used for lib / exe into separate variables, but when using a line to compile and link all in one it looks like only the CFLAGS variable is being included for the compile step.
When using the following makefile:
LIBCFLAGS := -fPIC
CFLAGS := -O3 -g -Wall -Werror
CC := gcc
SRCS=hashfunction.c hashtable.c hashtablelinkedlist.c
OBJS=hashfunction.o hashtable.o hashtablelinkedlist.o
LIBSO = lib$(NAME).so
libso: $(OBJS)
$(CC) $(LIBCFLAGS) $(CFLAGS) -shared -o $(LIBSO) $(OBJS)
I get the following output when running the make command for libso:
$ make libso
gcc -O3 -g -Wall -Werror -c -o hashfunction.o hashfunction.c
gcc -O3 -g -Wall -Werror -c -o hashtable.o hashtable.c
gcc -O3 -g -Wall -Werror -c -o hashtablelinkedlist.o hashtablelinkedlist.c
gcc -fPIC -O3 -g -Wall -Werror -shared -o lib.so hashfunction.o hashtable.o hashtablelinkedlist.o
/tools/oss/packages/x86_64-centos7/binutils/default/bin/ld: hashtable.o: relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC
hashtable.o: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
make: *** [Makefile:12: libso] Error 1
I can get it all working by sticking all the flags in CFLAGS, but I was wondering if anyone could explain what make is doing underneath ?
It looks like the $(LIBCFLAGS) is being ignored for the implicit compile lines, but $(CFLAGS) is not. Is CFALGS used implicitly by make for all compilations ?
You can see all the built-in rules make knows about by running make -p -f/dev/null. There you'll see:
%.o: %.c
# recipe to execute (built-in):
$(COMPILE.c) $(OUTPUT_OPTION) $<
which is the built-in rule make uses to create a .o file from a .c file. Looking elsewhere in the output you'll see:
COMPILE.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
so these are the variables make uses to compile .c files into .o files.

c++ makfile error: makefile:5: *** missing separator. Stop

I'm trying to run my c++ (written in clion) program in linux. When I try to compile it in the terminal using "make" command, I get this error:
"makefile:5: *** missing separator. Stop."
I already checked that there tabs and not 4 spaces in my makefile.
Anyone has an idea?
Thanks!
This is my makefile:
CFLAGS := -c -Wall -Weffc++ -g -std=c++11 -Iinclude
LDFLAGS := -lboost_system
all: StompBookClubClient
g++ -pthread -o bin/StompBookClubClient bin/ConnectionHandler.o bin/Book.o bin/keyboardInputSend.o bin/socketReader.o bin/User.o $(LDFLAGS)
StompBookClubClient: bin/StompBookClubClient bin/ConnectionHandler.o bin/Book.o bin/keyboardInputSend.o bin/socketReader.o bin/User.o
bin/Book.o: src/Stomp/Book.cpp
g++ -pthread $(CFLAGS) -o bin/Book.o src/Book.cpp
bin/ConnectionHandler.o: src/Stomp/ConnectionHandler.cpp
g++ -pthread $(CFLAGS) -o bin/ConnectionHandler.o src/ConnectionHandler.cpp
bin/keyboardInputSend.o: src/Stomp/keyboardInputSend.cpp
g++ -pthread $(CFLAGS) -o bin/keyboardInputSend.o src/keyboardInputSend.cpp
bin/socketReader.o: src/Stomp/socketReader.cpp
g++ -pthread $(CFLAGS) -o bin/socketReader.o src/socketReader.cpp
bin/StompBookClubClient.o: src/Stomp/StompBookClubClient.cpp
g++ -pthread $(CFLAGS) -o bin/StompBookClubClient.o src/StompBookClubClient.cpp
bin/User.o: src/Stomp/User.cpp
g++ -pthread $(CFLAGS) -o bin/User.o src/User.cpp
.PHONY: clean
clean:
rm -f bin/*
I already checked that there tabs and not 4 spaces in my makefile.
Check it a bit harder. The Makefile you pasted here has 4 spaces on line 5 and produces exactly the error you are seeing. If I replace them by a tab, the next error occurs on line 10, and so on.
This is not an answer but I do not have sufficient points to comment and hence answering.
Apart from 'tab' issue ,you get a similar error if ':'(colon) is missed after the rule name.
Ex makefile:
helloworld.o
g++ helloworld.cc -o helloworld.o;
Error:
Makefile:1: *** missing separator. Stop.
Solution:
Colon after helloworld.o like below
helloworld.o:
g++ helloworld.cc -o helloworld.o;

GCC cross compiler for i686 using cygwin (windows) - fail in building GCC

I am trying to cross compile the gcc for linux - i686-elf platform from windows PC (cygwin). As per the toolchain steps, I have successfully compiled:
binutils using
/binutils-x.y.z/configure --target=$TARGET --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror
basic gcc 1st step using
gcc-x.y.z/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c,c++ --without-headers
linux headers using
make headers_install ARCH=i386 CROSS_COMPILE=i386-linux- INDTALL_HDR_PATH=my/path/
glibc using
CC=${TARGET}-gcc ../glibc-2.29/configure --target=$TARGET --host=i686-pc-linux-gnu --prefix=$PREFIX --with-headers=my/path/
and then, make install-headers
Now, while building 2nd part og GCC using:../gcc-7.4.0/configure --target=$TARGET --prefix=$PREFIX --with-sysroot=$HOME/opt/cross --disable-libssp --disable-libgomp --disable-libmudflap --enable-languages=c,c++ --disable-multilib
I am getting the follwing errors:
make[2]: Entering directory '/home/MyPcUserName/src/build-gcc/i686-elf/libgcc
- If this is the top-level multilib, build all the other multilibs.
ln -s ../../../gcc-7.4.0/libgcc/enable-execute-stack-empty.c enable-execute-stack.c
ln -s ../../../gcc-7.4.0/libgcc/unwind-generic.h unwind.h
ln -s ../../../gcc-7.4.0/libgcc/config/no-unwind.h md-unwind-support.h
ln -s ../../../gcc-7.4.0/libgcc/config/i386/sfp-machine.h sfp-machine.h
ln -s ../../../gcc-7.4.0/libgcc/gthr-single.h gthr-default.h
DEFINES='' HEADERS='' \
../../../gcc-7.4.0/libgcc/mkheader.sh > tmp-libgcc_tm.h
/bin/sh ../../../gcc-7.4.0/libgcc/../move-if-change tmp-libgcc_tm.h libgcc_tm.h
echo timestamp > libgcc_tm.stamp
/home/MyPcUserName/src/build-gcc/./gcc/xgcc -B/home/MyPcUserName/src/build-gcc/./gcc/ -B/home/MyPcUserName/opt/cross/i686-elf/bin/ -B/home/MyPcUserName/opt/cross/i686-elf/lib/ -isystem /home/MyPcUserName/opt/cross/i686-elf/include -isystem /home/MyPcUserName/opt/cross/i686-elf/sys-include -g -O2 -O2 -g -O2 -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -isystem ./include -fpic -g -DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-protector -fpic -I. -I. -I../.././gcc -I../../../gcc-7.4.0/libgcc -I../../../gcc-7.4.0/libgcc/. -I../../../gcc-7.4.0/libgcc/../gcc -I../../../gcc-7.4.0/libgcc/../include -DHAVE_CC_TLS -o _muldi3.o -MT _muldi3.o -MD -MP -MF _muldi3.dep -DL_muldi3 -c ../../../gcc-7.4.0/libgcc/libgcc2.c -fvisibility=hidden -DHIDE_EXPORTS
In file included from /home/MyPcUserName/opt/cross/usr/include/bits/libc-header-start.h:33:0,
from /home/MyPcUserName/opt/cross/usr/include/stdio.h:27,
from ../../../gcc-7.4.0/libgcc/../gcc/tsystem.h:87,
from ../../../gcc-7.4.0/libgcc/libgcc2.c:27:
/home/MyPcUserName/opt/cross/usr/include/features.h:474:10: fatal error: gnu/stubs.h: No such file or directory
#include <gnu/stubs.h>
^~~~~~~~~~~~~
compilation terminated.
make[2]: *** [Makefile:491: _muldi3.o] Error 1
make[2]: Leaving directory '/home/MyPcUserName/src/build-gcc/i686-elf/libgcc'
make[1]: *** [Makefile:11875: all-target-libgcc] Error 2
make[1]: Leaving directory '/home/MyPcUserName/src/build-gcc'
make: *** [Makefile:893: all] Error 2
I have tried --disable-multilib to disable the mulilib so as to ignore this gnu issue on 64-bit PC.
I tried to rebuilt all of it again, but still I am facing this issue.
Please let me know if anyone can help. Thanks a lot for your time
After building the glibc, we shouldn't directly start building 2nd part of GCC. Rather, few more steps should be followed for glibc as indicated below:
$ CC=${TARGET}-gcc ../glibc-2.29/configure --target=$TARGET --host=i686-pc-linux-gnu --prefix=$PREFIX --with-headers=my/path/
$ make install-bootstrap-headers=yes install-headers
$ make -j4 csu/subdir_lib
$ install csu/crt1.o csu/crti.o csu/crtn.o /opt/cross/$TARGET/lib
$ $TARGET-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o /opt/cross/$TARGET/lib/libc.so
$ touch /opt/cross/$TARGET/include/gnu/stubs.h
Then, we can start building the 2nd part of GCC.

unrecognised command line option '-m64' in NVIDIA Jetson TX2

I am using an NVIDIA Jetson TX2. I am trying to generate an ".so" file using "make" for the DynamixelSDK. But I am getting this Error:
mkdir -p ./.objects/
gcc -O2 -O3 -DLINUX -D_GNU_SOURCE -Wall -c -I../../include/dynamixel_sdk -m64 -fPIC -g -c ../../src/dynamixel_sdk/group_bulk_read.c -o .objects/group_bulk_read.o
gcc: error: unrecognized command line option ‘-m64’
Makefile:114: recipe for target '.objects/group_bulk_read.o' failed
make: *** [.objects/group_bulk_read.o] Error 1
You can access the make file at- https://pastebin.com/zz9MNnqp
Here's a part of the MakeFile :
#---------------------------------------------------------------------
# C COMPILER, COMPILER FLAGS, AND TARGET PROGRAM NAME
#---------------------------------------------------------------------
DIR_DXL = ../..
DIR_OBJS = ./.objects
INSTALL_ROOT = /usr/local
MAJ_VERSION = 2
MIN_VERSION = 0
REV_VERSION = 0
TARGET = libdxl_x64_c.so
TARGET1 = $(TARGET).$(MAJ_VERSION)
TARGET2 = $(TARGET).$(MAJ_VERSION).$(MIN_VERSION)
TARGET3 = $(TARGET).$(MAJ_VERSION).$(MIN_VERSION).$(REV_VERSION)
CHK_DIR_EXISTS = test -d
PRINT = echo
STRIP = strip
AR = ar
ARFLAGS = cr
LD = g++
LDFLAGS = -shared -fPIC $(FORMAT)#-Wl,-soname,dxl
LD_CONFIG = ldconfig
CP = cp
CP_ALL = cp -r
RM = rm
RM_ALL = rm -rf
SYMLINK = ln -s
MKDIR = mkdir
CC = gcc
CX = g++
CCFLAGS = -O2 -O3 -DLINUX -D_GNU_SOURCE -Wall -c $(INCLUDES) $(FORMAT) -fPIC -g
CXFLAGS = -O2 -O3 -DLINUX -D_GNU_SOURCE -Wall -c $(INCLUDES) $(FORMAT) -fPIC -g
FORMAT = -m64
INCLUDES += -I$(DIR_DXL)/include/dynamixel_sdk
#---------------------------------------------------------------------
Tried Both the 32 and 64 bit Versions of the MakeFile (for linux).
I don't know hoe to solve this error. Any help would be appreciated.
The makefile assumes that the target is the x86-64 architecture. As a first step, you can simply remove the -m64 option from the FORMAT line in order to get further in the build. However, if the project has never been ported to another architecture, there could well be other target dependencies.
This error usually arises when the march, that is, the architecture of the target machine is not defined correctly. The -m64 line represents that it is being compiled for a 64bit architecture. If you see the Makefile for 32bit, it would be -m32.
Try changing the makefile such that it reads something like :
...
FORMAT = -march=armv8-a+crypto -mcpu=cortex-a57+crypto
....
This is march is usually used for Jetson TX2.
Also, for TX2, GCC options to keep in mind are :
Use latest GCC toolchain 7.2
Use CLANG llvm front end an alternative to GCC
-march=armv8.a+crypto+simd, this enables SIMD, crypto and floating point instruction set and may help.

Cross compiling portAudio for Intel Edison

I am using the cross compile environemt from the Intel Site and have successfully compiled several other libraries using it (libsndfile, alsa, fftw) but when I try to compile portaudio it refuses to link to the proper directories. Here is the error I get:
if test -n " bindings/cpp" ; then for dir in " bindings/cpp"; do make -C $dir all; done ; fi
make[1]: Entering directory '/home/theslat/Downloads/portaudio/bindings/cpp'
Making all in lib
make[2]: Entering directory '/home/theslat/Downloads/portaudio/bindings/cpp/lib'
/bin/sh ../libtool --tag=CXX --mode=link i586-poky-linux-g++ -m32 -march=core2 -mtune=core2 -msse3 -mfpmath=sse -mstackrealign -fno-omit-frame-pointer --sysroot=/usr/edison/sysroots/core2-32-poky-linux -O2 -pipe -g -feliminate-unused-debug-types -version-info 0:12:0 -no-undefined -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -o libportaudiocpp.la -rpath /usr/local/lib BlockingStream.lo CallbackInterface.lo CallbackStream.lo CFunCallbackStream.lo CppFunCallbackStream.lo Device.lo DirectionSpecificStreamParameters.lo Exception.lo HostApi.lo InterfaceCallbackStream.lo MemFunCallbackStream.lo Stream.lo StreamParameters.lo System.lo SystemDeviceIterator.lo SystemHostApiIterator.lo ../../../lib/libportaudio.la
libtool: link: i586-poky-linux-g++ -m32 -march=core2 -mtune=core2 -msse3 -mfpmath=sse -mstackrealign -fno-omit-frame-pointer --sysroot=/usr/edison/sysroots/core2-32-poky-linux -fPIC -DPIC -shared -nostdlib /usr/edison/sysroots/core2-32-poky-linux/usr/lib/crti.o /usr/edison/sysroots/core2-32-poky-linux/usr/lib/i586-poky-linux/4.9.1/crtbeginS.o .libs/BlockingStream.o .libs/CallbackInterface.o .libs/CallbackStream.o .libs/CFunCallbackStream.o .libs/CppFunCallbackStream.o .libs/Device.o .libs/DirectionSpecificStreamParameters.o .libs/Exception.o .libs/HostApi.o .libs/InterfaceCallbackStream.o .libs/MemFunCallbackStream.o .libs/Stream.o .libs/StreamParameters.o .libs/System.o .libs/SystemDeviceIterator.o .libs/SystemHostApiIterator.o -Wl,-rpath -Wl,/home/theslat/Downloads/portaudio/lib/.libs -Wl,-rpath -Wl,/usr/local/lib ../../../lib/.libs/libportaudio.so -L/usr/edison/sysroots/x86_64-pokysdk-linux/usr/bin/i586-poky-linux/../../lib/i586-poky-linux/gcc/i586-poky-linux/4.9.1 -L/usr/edison/sysroots/x86_64-pokysdk-linux/usr/bin/i586-poky-linux/../../lib/i586-poky-linux/gcc -L/usr/edison/sysroots/core2-32-poky-linux/lib -L/usr/edison/sysroots/core2-32-poky-linux/usr/lib/i586-poky-linux/4.9.1 -L/usr/edison/sysroots/core2-32-poky-linux/usr/lib /usr/lib/libstdc++.so -lm -lc -lgcc_s /usr/edison/sysroots/core2-32-poky-linux/usr/lib/i586-poky-linux/4.9.1/crtendS.o /usr/edison/sysroots/core2-32-poky-linux/usr/lib/crtn.o -m32 -march=core2 -mtune=core2 -msse3 -mfpmath=sse -mstackrealign --sysroot=/usr/edison/sysroots/core2-32-poky-linux -O2 -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -Wl,-soname -Wl,libportaudiocpp.so.0 -o .libs/libportaudiocpp.so.0.0.12
/usr/lib/libstdc++.so: error adding symbols: File in wrong format
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:311: libportaudiocpp.la] Error 1
make[2]: Leaving directory '/home/theslat/Downloads/portaudio/bindings/cpp/lib'
make[1]: *** [Makefile:333: all-recursive] Error 1
make[1]: Leaving directory '/home/theslat/Downloads/portaudio/bindings/cpp'
make: *** [Makefile:251: all-recursive] Error 2
It seems like it is trying to link against my computers normal libstdc++ and I don't know why. I have tried feedin configure a variaty of LDFLAG with the right directories and have reinstalled the toolchain and all my multilibs but no luck.
I also ran into this issue and the easiest way is to source the environment file again after doing a sudo su on the same command line and then do a make install.
Here are the steps I followed to cross compile portaudio for intel edison:
Download the cross compiler edison-toolchain-20150120-linux64.tar.bz2 and the script toolchain-20140724-linux64.sh from this link
Extract the toolchain, run the script (you can put it in your home directory somewhere if you wish) and set up the cross-compile environment
$ tar -xvf edison-toolchain-20150120-linux64.tar.bz2
$ chmod +x toolchain-20140724-linux64.sh
$ ./toolchain-20140724-linux64.sh
$ source /opt/poky-edison/1.6/environment-setup-core2-32-poky-linux
Check the environment on your shell:
$ echo $CC
$ i586-poky-linux-gcc -m32 -march=core2 -mtune=core2 -msse3 -mfpmath=sse -mstackrealign -fno-omit-frame-pointer --sysroot=/opt/poky-edison/1.6/sysroots/core2-32-poky-linux
Configure, compile and install portaudio:
$ ./configure
$ make
$ sudo su
# source /opt/poky-edison/1.6/environment-setup-core2-32-poky-linux
# make install
I am suprised that nobody grabbed this but also that it was difficult to find the proper answer anywhere else despite seeing many other people with similar (unresolved issues). The answer is frankly so simple I am embarrased that I overlooked it, but here it is so maybe someone else can find it.
make install required root privilages if the cross-compile SDK is in /opt or somewhere else you do not own. But... sudo does not preserve the environmental variable I had set up for the toolchain! Very simple, also su -m does not work the way I thought it did. Working solutions as follows:
Just install the SDK somewhere in your home directory. you now have write permissions, problem solved.
Run a single command as root while preserving the environment: su -m <yourUserName> -c '$CC main.cpp -lfoo -lbar ...'
The key in numer 2 is the username after -m, at least on my system leaving out the username there produced no errors but failed to preserve my environment.

Resources