error: "was not declared in this scope", using cygwin - multithreading

I'm trying to build a simple c++ code, that uses threads.
I tried to build it with Eclipse, Code Blocks, and Cygwin shell. All have resulted in the error:
"was not declared in this scope".
I added the -std=c++14 to the compiler options.
$ g++ --version
g++.exe (GCC) 7.4.0
and here's what I get:
$>g++ -std=c++14 main.cpp
main.cpp: In function 'int main()':
main.cpp:10:5: error: 'thread' was not declared in this scope
thread t1(callback, 1, 2);
^~~~~~
any idea how to solve it?

Related

cross-compile error while loading shared library

I have run gcc cross compiler from ubuntu(x86) to arm. this cross compiler works fine on ubuntu 14, and not I try in on ubuntu 18.
I tried to compile simple program
#include <stdio.h>
void main() {
printf("h\n");
}
gcc test.c -o test
When I compile it with gcc (to x86) all works fine, but when I compile it with cross compiler arm gcc I got error ...arm-buildroot-linux-uclibcgnueabu/4.*.*/cc1 : error while loading shared libraries: libmpfr.so.4 cannot open shared object file: No such file or directory
When I serach I can findlibmpfr.so.4 in the cross compiler path under /usr/lib
So even arm-gcc test.c -o test -L "<path_to_compiler>/usr/lib" got same error . and even export LD_LIBRARY_PATH=<path_to_compiler>/usr/lib didn't help

clang++ not finding "iostream"

I followed the guide's steps precisely except for the batch file step because I couldn't find setgcc.bat. I don't care about switching to the 32-bit version anyway.
I then performed clang++ -v and got:
clang version 3.8.0 (branches/release_38)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin
I feel as the error is the target is x86_64-pc-windows-msvc because I don't have VS installed.
I then performed g++ -v and got:
Reading specs from \cygnus\cygwin-b20\H-i586-cygwin32\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\specs
gcc version egcs-2.91.57 19980901 (egcs-1.1 release)
I tried doing g++ -c HelloWorld.cpp and got an error that cygwin1.dll was missing, and then cpp.exe crashed.
How can I have clang++ -c HelloWorld.cpp run and give me an object file by not having the error below occur, and based on my details?
HelloWorld.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
^
1 error generated.

unqlite.h:651:15: error: changes meaning of ‘pgno’ from ‘typedef sxu64 pgno’ [-fpermissive]

Just downloaded the unqlite.c and unqlite.h, created a new project in Eclipse, copied one of the examples from unqlite.org website and I'm getting the following error:
21:37:51 **** Build of configuration Debug for project nosql ****
make all
Building file: ../main.cpp
Invoking: Cross G++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp"
In file included from ../main.cpp:49:0:
../unqlite.h:661:8: error: declaration of ‘pgno unqlite_page::pgno’ [-fpermissive]
pgno pgno; /* Page number for this page */
^
../unqlite.h:651:15: error: changes meaning of ‘pgno’ from ‘typedef sxu64 pgno’ [-fpermissive]
typedef sxu64 pgno;
^
subdir.mk:25: recipe for target 'main.o' failed
make: *** [main.o] Error 1
21:37:51 Build Finished (took 171ms)
It was meant to be as simple, but I have no clue of what is going on... Has anyone tried this unqLite KV store?
I'm using
gcc version 4.9.2 (Debian 4.9.2-10)
Cheers
ttkdroid
This issue appears when including unqlite.h in a C++ file, and compiling it with a g++. You have two solutions to fix it:
You can get the patch produced by the author of the lib as indicated here: https://github.com/symisc/unqlite/issues/24
Or you can edit the unqlite.h file on line 661 replacing:
pgno pgno; /* Page number for this page */
by
::pgno pgno; /* Page number for this page */
Which will work with a g++ compiler as well as other C++ compilers. Of course, you cannot compile unqlite.c with this edited header, with a C compiler.
If you want to learn more about this error, this might be a good link: typedef changes meaning
Have a good day!

How do I install Net::Arping on CentOS 5?

I have tried to install Net::Arping package using cpan and I can't do that because of errors...
CPAN.pm: Going to build R/RI/RIIKI/Net-Arping-0.02.tar.gz
Checking if your kit is complete...
Looks good
Writing Makefile for Net::Arping
cp Arping.pm blib/lib/Net/Arping.pm
/usr/bin/perl /usr/lib/perl5/5.8.8/ExtUtils/xsubpp -typemap /usr/lib/perl5/5.8.8/ExtUtils/typemap Arping.xs > Arping.xsc && mv Arping.xsc Arping.c
Please specify prototyping behavior for Arping.xs (see perlxs manual)
gcc -c -D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -Wdeclaration-after- statement -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 - I/usr/include/gdbm -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack- protector --param=ssp-buffer-size=4 -m64 -mtune=generic -DVERSION=\"0.02\" - DXS_VERSION=\"0.02\" -fPIC "-I/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE" - D_BSD_SOURCE -D__BSD_SOURCE -D__FAVOR_BSD -DHAVE_NET_ETHERNET_H Arping.c
Arping.xs: In function ‘XS_Net__Arping_send_arp’:
Arping.xs:116: warning: implicit declaration of function ‘libnet_name_resolve’
Arping.xs:124: warning: passing argument 1 of ‘libnet_select_device’ from incompatible pointer type
Arping.xs:124: error: too many arguments to function ‘libnet_select_device’
Arping.xs:130: warning: implicit declaration of function ‘libnet_open_link_interface’
Arping.xs:130: warning: assignment makes pointer from integer without a cast
Arping.xs:135: warning: implicit declaration of function ‘libnet_get_ipaddr’
Arping.xs:140: error: ‘LIBNET_IP_H’ undeclared (first use in this function)
Arping.xs:140: error: (Each undeclared identifier is reported only once
Arping.xs:140: error: for each function it appears in.)
Arping.xs:143: warning: implicit declaration of function ‘libnet_init_packet’
Arping.xs:148: warning: passing argument 1 of ‘libnet_get_hwaddr’ from incompatible pointer type
Arping.xs:148: error: too many arguments to function ‘libnet_get_hwaddr’
Arping.xs:148: warning: assignment from incompatible pointer type
Arping.xs:156: warning: passing argument 6 of ‘libnet_build_ethernet’ from incompatible pointer type
Arping.xs:156: error: too few arguments to function ‘libnet_build_ethernet’
Arping.xs:161: warning: passing argument 12 of ‘libnet_build_arp’ from incompatible pointer type
Arping.xs:161: error: too few arguments to function ‘libnet_build_arp’
Arping.xs:166: warning: pointer targets in passing argument 1 of ‘pcap_open_live’ differ in signedness
Arping.xs:185: warning: implicit declaration of function ‘libnet_write_link_layer’
Arping.xs:196: warning: implicit declaration of function ‘libnet_close_link_interface’
Arping.xs:197: warning: implicit declaration of function ‘libnet_destroy_packet’
make: *** [Arping.o] Error 1
/usr/bin/make -- NOT OK
Running make test
Can't test without successful make
Running make install
make had returned bad status, install seems impossible
I need this perl module for check_arping script for Nagios.
Some additional informations:
[root#atlantis build]# uname -a
Linux atlantis 2.6.18-238.9.1.el5xen #1 SMP Tue Apr 12 18:53:56 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux
[root#atlantis build]# rpm -qa | grep libnet
libnet-1.1.2.1-2.rf
[root#atlantis build]# rpm -qa | grep libpcap
libpcap-devel-0.9.4-15.el5
libpcap-0.9.4-15.el5
libpcap-0.9.4-15.el5
libpcap-devel-0.9.4-15.el5
[root#atlantis build]#
As You see I've installed libnet, libpcap and still there are problems ... Is anyone have an idea how to resolve this problem?
You have installed libpcap-devel, but not libnet-devel. The *-devel version of an RPM includes C header files that are often required when building XS-based modules.
Try sudo yum install libnet-devel before trying to build the module again.
Update: The advice above was correct, but insufficient. I've just tested this on an installation of Centos 5.6 and it fails with exactly the same errors.
Looking at the CPAN testers results, it's clear that version 0.02 of Net::Arping hasn't built successfully for anyone for a very long time. This distribution was uploaded to CPAN in 2002 and it appears that its XS code just isn't compatible with modern versions of libnet.
There is, however, on CPAN a version 0.03 of Net::Arping. This builds successfully on my Centos 5.6. I suggest you switch to using that instead. I haven't yet worked out why cpan doesn't recognise version 0.03. I see it's by a different author, so it might be a permissions problem. You should consider reporting this issue to modules#cpan.org.

gcc compile errors

I am getting these errors when I compile sim_routing.cc program by this command
../../bin/cxx sim_routing.cc
g++ -Wall -o sim_routing sim_routing.cxx
following errors are produced:
../../common/priority_q.h : In member function 'bool guardedQueue<ITEM>::Validate(Const char*);
error : there are no argument to 'strcat' that depend on template parameter so a declaration of 'strcat' must be avaible.
error : <if you use -fpermissive g++ will accept your code but allowing use of undeclared name is deprecated>
When I tried to change commom/priority_q.h, it shows it is read only; file changes cannot be accepted.
How these errors can be removed?
#include <cstring> before the header triggering your error.

Resources