/usr/include/x86_64-linux-gnu/bits/getopt_core.h:91:12: error: declaration of ‘int getopt(int, char* const*, const char*) - build

While I'm building LLVM using the CCR implementation. I'm getting the following error.
/usr/include/x86_64-linux-gnu/bits/getopt_core.h:91:12: error: declaration of ‘int getopt(int, char* const*, const char*) noexcept’ has a different exception specifier
extern int getopt (int ___argc, char *const *___argv, const char *__shortopts)
Below the build.sh code is given.
function compile_binutils {
cd $1
./configure
sudo make -j$2
}
function compile_gold {
cd $1
./configure --enable-gold --enable-plugins=yes
sudo make -j$2
}
echo "D. Compiling the binutils and gold linker..."
echo =============================================
echo
compile_binutils $BINUTILS_DIR $NO_CPUS
# Deploy the shared object for gold
cp $PROTODEF_DIR/$CC_HDR $NEWGOLD_DIR/$CC_HDR
cp $PROTODEF_DIR/$SHUFFLEINFO $NEWGOLD_DIR/lib$SHUFFLEINFO
compile_gold $NEWGOLD_DIR $NO_CPUS

Related

VSCode showing error while running C++ program on g++ compiler

I ran this C++ program (Code on gfg) on VSCode using the run button and it exits with code=1 and shows this message :
[Running] cd "c:\Users\pawar\OneDrive\Desktop\cp\" && g++ 5.cpp -o 5 && "c:\Users\pawar\OneDrive\Desktop\cp\"5
In file included from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\cassert:44:0,
from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\mingw32\bits\stdc++.h:33,
from 5.cpp:44:
c:\mingw\include\assert.h:38:38: error: conflicting declaration of C function 'void _assert(const char*, const char*, long long int)'
_CRTIMP void __cdecl __MINGW_NOTHROW _assert (const char*, const char*, int) __MINGW_ATTRIB_NORETURN;
^~~~~~~
In file included from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\cassert:44:0,
from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\mingw32\bits\stdc++.h:33,
from 5.cpp:6:
c:\mingw\include\assert.h:38:38: note: previous declaration 'void _assert(const char*, const char*, int)'
_CRTIMP void __cdecl __MINGW_NOTHROW _assert (const char*, const char*, int) __MINGW_ATTRIB_NORETURN;
[Done] exited with code=1 in 3.051 seconds
The program ran successfully on Codeforces and Codechef ide,
But did not run on Geeksforgeeks ide(SIGABRT error) and VSCode. Can someone help me how to fix this, so that it runs on VSCode, is it something to de with the compiler used, please guide?
#include<bits/stdc++.h>
This line was included twice, which caused the error.

A problem when compiling a simple C++ program

When I compile a simple C++ program like this:
#include<iostream>
using namespace std;
int main()
{
cout << "hello word" << endl;
return 0;
}
I got some error message,
This is part of the error message:
In file included from e:\mingw\lib\gcc\mingw32\8.2.0\include\c++\cstdlib:75,
from e:\mingw\lib\gcc\mingw32\8.2.0\include\c++\ext\string_conversions.h:41,
from e:\mingw\lib\gcc\mingw32\8.2.0\include\c++\bits\basic_string.h:6391,
from e:\mingw\lib\gcc\mingw32\8.2.0\include\c++\string:52,
from e:\mingw\lib\gcc\mingw32\8.2.0\include\c++\bits\locale_classes.h:40,
from e:\mingw\lib\gcc\mingw32\8.2.0\include\c++\bits\ios_base.h:41,
from e:\mingw\lib\gcc\mingw32\8.2.0\include\c++\ios:42,
from e:\mingw\lib\gcc\mingw32\8.2.0\include\c++\ostream:38,
from e:\mingw\lib\gcc\mingw32\8.2.0\include\c++\iostream:39,
from F:\Desktop\web\web\work_one\test.cpp:1:
e:\mingw\include\stdlib.h:90:1: error: '_BEGIN_C_DECLS' does not name a type
_BEGIN_C_DECLS
^~~~~~~~~~~~~~
e:\mingw\include\stdlib.h:363:1: error: '__CRT_ALIAS' does not name a type
__CRT_ALIAS __cdecl __MINGW_NOTHROW
^~~~~~~~~~~
e:\mingw\include\stdlib.h:367:1: error: '__CRT_ALIAS' does not name a type
__CRT_ALIAS __cdecl __MINGW_NOTHROW
^~~~~~~~~~~
e:\mingw\include\stdlib.h:444:55: error: '_locale_t' has not been declared
__int64 _wcstoi64_l(const wchar_t *, wchar_t **, int, _locale_t);
^~~~~~~~~
e:\mingw\include\stdlib.h:447:65: error: '_locale_t' has not been declared
unsigned __int64 _wcstoui64_l(const wchar_t *, wchar_t **, int, _locale_t);
^~~~~~~~~
e:\mingw\include\stdlib.h:866:1: error: '_END_C_DECLS' does not name a type
_END_C_DECLS
^~~~~~~~~~~~
This seems to be a problem with the header file syntax, but I did not modify the head file.
I use this command to compile:
g++ -g -std=c++11 F:\Desktop\web\web\work_one\test.cpp -o test.exe
My operating system is Win10.
The g++ version is g++ (MinGW.org GCC-8.2.0-3) 8.2.0
G++ I got from http://www.mingw.org/
Possible solution to this already exists here
Just change -std=c++11 with -std=gnu++11
Finally, I fixed the problem. The reason for this problem is that I installed codeblocks.
codeblocks adds environment variables to my computer, like C_INCLUDEDE_PATH, CPLUS_INCLUDE_PATH, and LIBRARY_PATH. When I deleted these environment variables, the problem was fixed.

SWIG: Mapping an array of a typedef

I'm using SWIG to create a Ruby Wrapper for some C++ classes. This is the signature of the C++ method which is giving me trouble:
virtual LogP wordProb(VocabIndex word, const VocabIndex *context);
This is the definition of VocabIndex:
#ifdef USE_SHORT_VOCAB
typedef unsigned short VocabIndex;
#else
typedef unsigned int VocabIndex;
#endif
This is the way I'm calling it from a Ruby script:
index = 8
context = [index]
puts ngram.wordProb(index, context)
This is the error I'm getting when I run my script:
ngram.rb:26:in `wordProb': Expected argument 2 of type VocabIndex const *, but got Array [8] (TypeError)
in SWIG method 'wordProb'
from ngram.rb:26:in `<main>'
My attempted solution:
After reading the docs (yes, I'm using SWIG 2.0), I tried this in my .i file:
%module rubylm
%{
#include "srilm-1.7.1/lm/src/Ngram.h"
%}
%include "srilm-1.7.1/lm/src/Counts.h"
%include "srilm-1.7.1/lm/src/Ngram.h"
%include "typemaps.i"
virtual LogP Ngram::wordProb(VocabIndex word, const VocabIndex *INPUT);
The swig command ran fine, but when I tried to build the wrapper library, I got this:
NgramWrapper_wrap.cxx:148:17: fatal error: tcl.h: No such file or directory
#include <tcl.h>
So I fired up a terminal (this is an Ubuntu box) and ran:
sudo apt-get install tcl-dev
This installed tcl 8.6, which placed its header files in the /usr/include/tcl8.6 directory. So I added that include directory in the Makefile line which builds NgramWrapper_wrap.o:
NgramWrapper_wrap.o: NgramWrapper_wrap.cxx
$(CC) $(CFLAGS) NgramWrapper_wrap.cxx -I $(RUBY_SRC) -I $(MISC_INCLUDE) -I $(DSTRUCT_INCLUDE) -I /usr/include/tcl8.6
However, I'm still getting build errors. And here's where I got stumped:
NgramWrapper_wrap.cxx:10812:34: error: ‘RARRAY_LEN’ was not declared in this scope
int size = RARRAY_LEN(objv[3]);
^
NgramWrapper_wrap.cxx:10816:5: error: ‘VALUE’ was not declared in this scope
VALUE *ptr = RARRAY_PTR(objv[3]);
^
NgramWrapper_wrap.cxx:10816:12: error: ‘ptr’ was not declared in this scope
VALUE *ptr = RARRAY_PTR(objv[3]);
^
NgramWrapper_wrap.cxx:10816:36: error: ‘RARRAY_PTR’ was not declared in this scope
VALUE *ptr = RARRAY_PTR(objv[3]);
^
NgramWrapper_wrap.cxx:10819:35: error: ‘StringValuePtr’ was not declared in this scope
arg3[i]= StringValuePtr(*ptr);
^
NgramWrapper_wrap.cxx: In function ‘int _wrap_NgramCountWrapper_run(ClientData, Tcl_Interp*, int, Tcl_Obj* const*)’:
NgramWrapper_wrap.cxx:10908:34: error: ‘RARRAY_LEN’ was not declared in this scope
int size = RARRAY_LEN(objv[3]);
^
NgramWrapper_wrap.cxx:10912:5: error: ‘VALUE’ was not declared in this scope
VALUE *ptr = RARRAY_PTR(objv[3]);
^
NgramWrapper_wrap.cxx:10912:12: error: ‘ptr’ was not declared in this scope
VALUE *ptr = RARRAY_PTR(objv[3]);
^
NgramWrapper_wrap.cxx:10912:36: error: ‘RARRAY_PTR’ was not declared in this scope
VALUE *ptr = RARRAY_PTR(objv[3]);
^
NgramWrapper_wrap.cxx:10915:35: error: ‘StringValuePtr’ was not declared in this scope
arg3[i]= StringValuePtr(*ptr);
All I can think of is some version mismatch between Ruby, Swig and Tcl. But how can I know which Tcl version to use? I scoured the docs to no avail...
Hmm.
I just did the following
vocal.i
%module rubylm
%{
#include "Ngram.h"
%}
%include "Ngram.h"
%include "typemaps.i"
virtual LogP Ngram::wordProb(VocabIndex word, const VocabIndex *INPUT);
Ngram.h
#pragma once
#ifdef USE_SHORT_VOCAB
typedef unsigned short VocabIndex;
#else
typedef unsigned int VocabIndex;
#endif
typedef int LogP;
class NGram {
public:
LogP wordProb(VocabIndex word, const VocabIndex *context);
};
Command executed
swig2.0 -ruby -c++ vocal.i
followed by
g++ -c vocal_wrap.cxx -I/usr/include/ruby-2.1.0 -I/usr/include/x86_64-linux-gnu/ruby-2.1.0
without any errors. Have you forgot the -c++ option and why do you need tcl.h

Why does GCC accept convertion from 'const char *' to 'char *' on std::strrchr() returned value?

While adding a detailed answer, I noticed that GCC does not warn the following code while Visual C++ complains.
#include <cstring>
int main()
{
const char CONSTSTR[] = "foo/bar/foobar.txt";
char *nonconst = std::strrchr (CONSTSTR, '/');
// cannot convert from 'const char *' to 'char *'
*nonconst++ = 'B';
*nonconst++ = 'A';
*nonconst++ = 'D';
}
I have tested three different GCC versions:
4.1.2 on Red Hat (Linux)
4.5.3 on Cygwin (Windows)
4.7.2 on MinGW (Windows)
But all these three GCC versions compiled this code without any warning/error:
> g++ -Wall -Wextra -pedantic -ansi test.cpp && echo "success"
success
While Microsoft compiler v16 complains:
> cl -c test.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
test.cpp
test.cpp(5) : error C2440: 'initializing' : cannot convert from 'const char *' to 'char *'
Conversion loses qualifiers
(from my office, I do not have access to ideone/codepad/... to test it using other versions)
As this code uses std::strrchr, I do not understand why GCC does not complain.
const char* strrchr( const char* str, int ch ); //the code above uses this declaration
char* strrchr( char* str, int ch );
My question: Why does g++ successfully compile this code without any warning/error? Is it a bug? a feature? a miss-configuration on my side?
Actually your g++ does not accept the conversion from 'const char *' to 'char *', it's just that on your version std::strrchr() returns a char* (incorrectly, instead of a const char*).
To verify the first part of my statement, try to compile the following on your GCC versions, I predict that all will correctly issue an error:
int main()
{
const char* p = "foo";
char* q = p; // error, invalid conversion from 'const char*' to 'char*'
}
Now for the second part, I tried to compile the following minimal code, whose actual aim is to trigger an error in order to list the declared overloads of std::strrchr:
#include <cstring>
void (*p)() = &std::strrchr; // error here, with "candidates are: ..."
int main() {}
Well, with gcc 4.7.2 the message shows the expected "all non-const" and "all const" overloads:
prog.cpp:2:21: error: no matches converting function ‘strrchr’ to type ‘void (*)()’
In file included from /usr/include/c++/4.7/cstring:44:0,
from prog.cpp:1:
/usr/include/string.h:249:1: error: candidates are: char* strrchr(char*, int)
/usr/include/string.h:255:1: error: const char* strrchr(const char*, int)
i.e. the prototypes
char* strrchr( char* , int );
const char* strrchr( const char* , int ); // Question's code will use this one (-> error)
But with gcc 4.3.2 the message was different:
prog.cpp:2: error: no matches converting function 'strrchr' to type 'void (*)()'
/usr/include/string.h:171: error: candidates are: char* strrchr(const char*, int)
/usr/include/c++/4.3/cstring:118: error: char* std::strrchr(char*, int)
i.e. the overloads were
char* strrchr( const char* , int ); // Question's code would use this one (-> no error...)
char* strrchr( char* , int );
(the second one is the C++ non-const overload; but the first one is the old C version, and should instead be the C++ const overload).
This it seems that the headers (<cstring> and/or <string.h>) were incorrect on this version, and I suspect that it's the same on yours.
Edit: I found for example a discussion, a blog post and a bug report (for strchr not strrchr but it's the same story).

undefined reference to function while using static libraries

I'm attempting to write a program using a genetic algorithm which is a particular type of optimization algorithm. I found a free library for this task called "Evolutionary Objects" and implemented a very simple genetic algorithm instance. The program code, the build commands that netbeans implements, and finally the error messages that I receive are posted below in separate blocks. If you allow me your help, you'll see that something is going wrong with the cout function. When I searched the internet for similar difficulties, I found that people had been correcting the problem by simply using g++ rather than gcc yet I am already using g++, as you can see. Any help would be appreciated....
The program code is immediately below:
#include <stdexcept>
#include <iostream>
#include <eo>
#include <ga.h>
typedef eoBit<double> Indi;
double binary_value(const Indi & _indi)
{
double sum = 0;
for (unsigned i = 0; i < _indi.size(); i++)
sum += _indi[i];
return sum;
}
void main_function(int argc, char **argv)
{
const unsigned int SEED = 42; // seed for random number generator
const unsigned int T_SIZE = 3; // size for tournament selection
const unsigned int VEC_SIZE = 16; // Number of bits in genotypes
const unsigned int POP_SIZE = 100; // Size of population
const unsigned int MAX_GEN = 400; // Maximum number of generation before STOP
const float CROSS_RATE = 0.8; // Crossover rate
const double P_MUT_PER_BIT = 0.01; // probability of bit-flip mutation
const float MUT_RATE = 1.0; // mutation rate
rng.reseed(SEED);
eoEvalFuncPtr<Indi> eval( binary_value );
eoPop<Indi> pop;
for (unsigned int igeno=0; igeno<POP_SIZE; igeno++)
{
Indi v; // void individual, to be filled
for (unsigned ivar=0; ivar<VEC_SIZE; ivar++)
{
bool r = rng.flip(); // new value, random in {0,1}
v.push_back(r); // append that random value to v
}
eval(v); // evaluate it
pop.push_back(v); // and put it in the population
}
pop.sort();
cout << "Initial Population" << endl;
cout << pop;
eoDetTournamentSelect<Indi> select(T_SIZE); // T_SIZE in [2,POP_SIZE]
eo1PtBitXover<Indi> xover;
eoBitMutation<Indi> mutation(P_MUT_PER_BIT);
eoGenContinue<Indi> continuator(MAX_GEN);
eoSGA<Indi> gga(select, xover, CROSS_RATE, mutation, MUT_RATE, eval, continuator);
gga(pop);
pop.sort();
cout << "FINAL Population\n" << pop << endl;
}
int main(int argc, char **argv)
{
main_function(argc, argv);
return 1;
}
}
Netbeans shows me that it is doing this when attempting build:
make[1]: Entering directory `/home/gregemerson/EO_GA/EO_GA'
rm -f -r build/Debug
rm -f dist/Debug/GNU-Linux-x86/eo_ga
make[1]: Leaving directory `/home/gregemerson/EO_GA/EO_GA'
CLEAN SUCCESSFUL (total time: 94ms)
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/gregemerson/EO_GA/EO_GA'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/eo_ga
make[2]: Entering directory `/home/gregemerson/EO_GA/EO_GA'
mkdir -p build/Debug/GNU-Linux-x86
rm -f build/Debug/GNU-Linux-x86/main.o.d
g++ -c -g -I../../EO/EO/eo/src -MMD -MP -MF build/Debug/GNU-Linux-x86/main.o.d -o build/Debug/GNU-Linux-x86/main.o main.cpp
mkdir -p dist/Debug/GNU-Linux-x86
g++ -o dist/Debug/GNU-Linux-x86/eo_ga build/Debug/GNU-Linux-x86/main.o -L../../EO/EO/eo/build/lib /home/gregemerson/EO/EO/eo/build/lib/libcma.a /home/gregemerson/EO/EO/eo/build/lib/libeoutils.a /home/gregemerson/EO/EO/eo/build/lib/libes.a /home/gregemerson/EO/EO/eo/build/lib/libga.a
The error messages are immediately below:
/home/gregemerson/EO_GA/EO_GA/main.cpp:94: undefined reference to `operator<<(std::basic_ostream<char, std::char_traits<char> >&, eoPrintable const&)'
/home/gregemerson/EO_GA/EO_GA/main.cpp:99: undefined reference to `operator<<(std::basic_ostream<char, std::char_traits<char> >&, eoPrintable const&)'
/home/gregemerson/EO_GA/EO_GA/main.cpp:149: undefined reference to `operator<<(std::basic_ostream<char, std::char_traits<char> >&, eoPrintable const&)'
build/Debug/GNU-Linux-x86/main.o: In function `eoPop<eoBit<double> >::sortedPrintOn(std::basic_ostream<char, std::char_traits<char> >&) const':
/home/gregemerson/EO_GA/EO_GA/../../EO/EO/eo/src/eoPop.h:294: undefined reference to `operator<<(std::basic_ostream<char, std::char_traits<char> >&, eoPrintable const&)'
build/Debug/GNU-Linux-x86/main.o: In function `std::ostream_iterator<eoBit<double>, char, std::char_traits<char> >::operator=(eoBit<double> const&)':
/usr/include/c++/4.6/bits/stream_iterator.h:198: undefined reference to `operator<<(std::basic_ostream<char, std::char_traits<char> >&, eoPrintable const&)'
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-Linux-x86/eo_ga] Error 1
make[2]: Leaving directory `/home/gregemerson/EO_GA/EO_GA'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/home/gregemerson/EO_GA/EO_GA'
make: *** [.build-impl] Error 2
Your response did correct for my cout(pop) problem. However, I'm now seeing similar errors in a headers for one of the static libraries that I'm using along with what looks to be related to one of the basic c++ libraries. I get the following. Does this make sense to you?
build/Debug/GNU-Linux-x86/main.o: In function `std::ostream_iterator<eoBit<double>, char, std::char_traits<char> >::operator=(eoBit<double> const&)':
/usr/include/c++/4.6/bits/stream_iterator.h:198: undefined reference to `operator<<(std::basic_ostream<char, std::char_traits<char> >&, eoPrintable const&)'
build/Debug/GNU-Linux-x86/main.o: In function `eoPop<eoBit<double> >::sortedPrintOn(std::basic_ostream<char, std::char_traits<char> >&) const':
/home/gregemerson/EO_GA/EO_GA/../../EO/EO/eo/src/eoPop.h:294: undefined reference to `operator<<(std::basic_ostream<char, std::char_traits<char> >&, eoPrintable const&)'
The issue is (for example) here:
cout << pop;
The error,
/home/gregemerson/EO_GA/EO_GA/main.cpp:94: undefined reference to
`operator<<(std::basic_ostream<char, std::char_traits<char> >&, eoPrintable const&)'
Means that there is no basic function that knows how to push an eoPrintable object into an ostream.
Based on the link provided in the comments, this eoPop class has defined a few methods for printing: sortedPrintOn and printOn.
In order to use one of them to print to cout, you would do the following:
pop.printOn(cout); //or pop.printOn(std::cout) if you remove using namespace std;
pop.printSortedOn(cout);
Many peoples are experiencing this problem when they try to use EO C++ lib for first time. I also faced this problem and were able to find the solution. The problem is that the linker does not find the static libraries that have to be linked while building the EO programs. I am now able to successfully compile and use the first tutorial i.e. FirstBitGA.cpp & FirstRealGA.cpp with EO-1.3.1 on Ubunut 10.04 (LTS).
Note: I am writing the complete steps starting from installation, so be patient. Also replace the word 'username' with your user account.
<< Solution >>
Download EO Lib from http://sourceforge.net/projects/eodev/files/latest/download?source=files
Create a directory named EO; I create it in /home/username/ .
Copy the EO Zip file to /home/username/EO and uncompressed it. This will create another directory named 'eo' under /home/username/EO.
Now build the installation files by running the build script in /home/username/EO/eo/build_gcc_linux_release in terminal.
The build script in step-4 will create a directory named 'release' under /home/username/EO/eo. In the release directory the 'lib' folder contains the libraries that have to be linked while compiling any EO program.
Now two paths have to be provided to the compiler for successful compilation:
6.1. The path to include files as a command line argument to g++ i.e. -I /home/username/EO/eo/src < OR > If you are using Qt creator IDE then enter the line ' INCLUDEPATH += /home/username/EO/eo/src' in the .pro file of the probject.
6.2. The path to all link libraries with -L argument to g++ i.e.
-L/home/username/EO/eo/release/lib/libcma.a /home/username/EO/eo/release/lib/libeo.a /home/username/EO/eo/release/lib/libeoserial/home/username/EO/eo/release/lib/libeoutils.a /home/username/EO/eo/release/lib/libes.a /home/username/EO/eo/release/lib/libga.a
For Qt Creator users, enter the following lines into .pro file,
LIBS += -L/home/username/EO/eo/release/lib/libcma.a /home/username/EO/eo/release/lib/libeo.a /home/username/EO/eo/release/lib/libeoserial.a /home/username/EO/eo/release/lib/libeoutils.a /home/username/EO/eo/release/lib/libes.a /home/username/EO/eo/release/lib/libga.a
Enjoy