pcre error "undefined symbol: _ZN7pcrecpp2RE6no_argE" - c++

I'm getting the following error:
./pcrecpp: symbol lookup error: ./pcrecpp: undefined symbol: _ZN7pcrecpp2RE6no_argE
when run my program on CentOS 5.4. But it works well on CentOS 6.2. The version of pcre is 8.31, and the version of pcre++ is 0.9.5. Below is the source code. Thanks for any guidance.
#include <iostream>
#include <pcrecpp.h>
int main(int argc, char ** argv)
{
if (argc != 3)
{
std::cerr << "Usage: " << argv[0] << " pattern text\n";
return 1;
}
pcrecpp::RE oPattern(argv[1]);
if (oPattern.FullMatch(argv[2]))
{
std::cout << argv[2] << " fully matches " << argv[1] << "\n";
}
else if (oPattern.PartialMatch(argv[2]))
{
std::cout << argv[2] << " partially matches " << argv[1] << "\n";
}
else
{
std::cout << argv[2] << " dose not match " << argv[1] << "\n";
}
}

Related

Fstream closes after write attempt without errors

I am writing a config for my program. This config is stored in json format using nlohman json. I am using std::fstream to write json object to file. All was fine, but after some moment my program stopped writing to file.
Here is a minimal reproducible example:
#include <iostream>
#include <nlohmann/json.hpp>
#include <fstream>
#include <iomanip>
bool load(std::fstream &config_fs) {
if (config_fs) {
try {
nlohmann::json json;
config_fs >> json;
std::cout << json << std::endl;
return true;
} catch (std::exception &e) {
std::cout << "54 " << (bool)config_fs << std::endl; // 1
std::cout << "Cannot load config: " << e.what() << std::endl;
return false;
}
}
std::cout << "Cannot load config because file is not open" << std::endl;
return false;
}
bool save(std::fstream &config_fs) {
std::cout << "37 " << (bool)config_fs << std::endl;
if (config_fs) {
nlohmann::json json{{"test", 42}};
std::cout << "39 " << (bool)config_fs << " " << config_fs.is_open() << " " << strerror(errno) << std::endl;
config_fs << std::setw(4) << json << std::endl;
std::cout << "41 " << (bool)config_fs << " " << config_fs.is_open() << " " << strerror(errno) << std::endl;
return true;
}
std::cout << "Cannot save config because file is not open" << std::endl;
return false;
}
int main() {
std::string config_file = "../config_test.json";
std::fstream config_fs(config_file, std::ios::in | std::ios::out);
if (!config_fs) {
std::cout << "Cannot open configuration file " << config_file << ", creating it" << std::endl;
config_fs.open(config_file, std::ios::out);
if (!config_fs) {
std::cout << "Cannot create config file " << config_file << std::endl;
} else {
config_fs.close();
config_fs.open(config_file, std::ios::in | std::ios::out);
}
}
if(!load(config_fs)) {
std::cout << "Cannot load config from " << config_file << ", putting default values" << std::endl;
std::cout << "21 " << (bool)config_fs << std::endl;
save(config_fs);
}
return 0;
}
And here is output of the programm:
54 1
Cannot load config: [json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal
Cannot load config from ../config_test.json, putting default values
21 1
37 1
39 1 1 Success
41 0 1 Success
It means that fstream closes after my write attempt with Success errno and file stays empty!
I do not know what may cause such a behavior. I also could not find any similar questions and i really confused about that.
Please point me, what can be reason for this problem.
Thank you!
UPD: Exception 'std::ios_base::failure[abi:cxx11]'
what(): basic_ios::clear: iostream error was thrown in output_stream_adapter::write_characters(const CharType* s, std::size_t length) after enabling exceptions for fstream with config_fs.exceptions(std::ios::badbit | std::ios::failbit);

std::ifstream::seekg not failing with absurd offset

Apparently, on Linux (Centos 7, g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-4)) you can seek to absurd offsets in files opened for reading. I can get the file length and check the offset myself, but shouldn't the seekg fail?
This program illustrates. No error conditions are detected, but the file is much less than 999999 bytes long.
#include <iostream>
#include <fstream>
int main(int argc, char **argv) {
std::ifstream f("./tstseek.cpp",std::ios::in);
if(!f.seekg(9999999)) {
std::cerr << "SEEK FAILED" << std::endl;
}
long int pos = f.tellg();
if(f.bad() || f.fail()) {
std::cerr << "SEEK FAILED" << std::endl;
}
if(f.eof()) {
std::cerr << "EOF AFTER SEEK" << std::endl;
}
std::string s;
std::getline(f,s);
if(f.bad() || f.fail()) {
std::cerr << "getline failed" << std::endl;
}
if(f.eof()) {
std::cerr << "EOF after getline" << std::endl;
}
std::streamsize bytesread = f.gcount();
std::cerr << "Position after seekg(9999999) = " << pos << std::endl
<< "bytes read = " << bytesread << std::endl
<< "string=[" << s << "]" << std::endl;
}

g++ template error Small_size

I am working on the latest revision of the C++ programming language (think it's 5) and run into a problem with g++ version 5.2.
My code is a variation of Small_size template from chap 24.
#include <iostream>
template<int N>
bool is_small ()
{
std::cerr << sizeof(N) << std::endl;
std::cerr << N << std::endl;
return N <= 255;
}
bool ism (int i_n)
{
return i_n <= 255;
}
int main ()
{
std::cout << "hallo welt" << std::endl;
std::cout << 0 << " " << is_small<0> << std::endl;
std::cout << 255 << " " <<is_small<255> << std::endl;
std::cout << -4100000000 << " " << is_small<-4100000000> << std::endl;
std::cout << 256 << " " << is_small<256> << std::endl;
std::cout << 256 << " " << ism(256) << std::endl;
std::cout << 256 << " " << (256 <= 255) << std::endl;
}
When I compile it, it's ok. But when I run the thing, it simply seems to be broken.
[cpp11#hydra src]$ cat ~/bin/g14
#!/bin/bash
g++-52 -std=c++14 "${1}.C" -L$LIBPATH -o "$1"
[cpp11#hydra src]$ g14 konzept_small
[cpp11#hydra src]$ ./konzept_small
hallo welt
0 1
255 1
-4100000000 1
256 1 //1
256 0
256 0
[cpp11#hydra src]$
My problem is that:
the result for 256 and higher is wrong. See comment //1
there is no output of the template code on cerr
I started with a version without the cerr, but got only the wrong template result.
I removed a constexpr from the template, but no change.
So I added as last step the cerr to see whats wrong.
Any ideas?
You are not calling is_small<N>, but just printing out its address. You need to change your code to
std::cout << 0 << " " << is_small<0>() << std::endl;
std::cout << 255 << " " <<is_small<255>() << std::endl;
std::cout << -4100000000 << " " << is_small<-4100000000>() << std::endl;
std::cout << 256 << " " << is_small<256>() << std::endl;
Note the added (). Not sure why you are getting the output you are though, are you sure you are running the same code you posted?
is_small is a function you should add the parenthesis :
change
std::cout << 0 << " " << is_small<0> << std::endl;
to this
std::cout << 0 << " " << is_small<0>() << std::endl;
It worked fine for me with this change

list not displaying from txt file

void main() {
nodLista* LS=NULL;
FILE* F=fopen("asaceva.txt","r");
if(F!=NULL) {
char buffer[100]; int id;float pret;
fscanf(F,"d",&id);
while(!feof(F)) {
fscanf(F,"f",&pret);
fscanf(F,"s",buffer);
Produs* p= creareProdus(id,pret,buffer);
LS=inserareSfarsit(LS,*p);
fscanf(F,"%d",&id);
}
afisareLista(LS);
}
_getch();
}
afisareLista: displays the list
inserareSfarsit: inserts at the end
I don't understand why it doesn't get the data from the txt file. Can you explain why?
There are a couple of issues in your code:
main not returning integer.
not using fscanf consistently and correctly with placeholders.
you are not checking the return value of fscanf for failure.
NULL should be replaced with nullptr if you have C++11 support available.
The correct code should be like this:
int main() {
nodLista* LS=NULL;
FILE* F=fopen("asaceva.txt","r");
if(F!=NULL) {
char buffer[100]; int id;float pret;
if (!fscanf(F,"%d",&id))
cout << "Error happened: " << ferror(F) << ", error string: " << strerror(errno) << endl;
while(!feof(F)) {
if (!fscanf(F,"%f",&pret))
cout << "Error happened: " << ferror(F) << ", error string: " << strerror(errno) << endl;
if (!fscanf(F,"%s",buffer))
cout << "Error happened: " << ferror(F) << ", error string: " << strerror(errno) << endl;
Produs* p= creareProdus(id,pret,buffer);
LS=inserareSfarsit(LS,*p);
if (!fscanf(F,"%d",&id))
cout << "Error happened: " << ferror(F) << ", error string: " << strerror(errno) << endl;
}
afisareLista(LS);
}
_getch();
return 0;
}

trying to get Qt4 example to run on ubuntu 10.10 with Qt Creator 4 installed

#include "framecapture.h"
#include <iostream>
#include <QtWidget>
int main(int argc, char * argv[])
{
if (argc != 3) {
std::cout << "Capture a web page and save its internal frames in different images" << std::endl << std::endl;
std::cout << " framecapture <url> <outputfile>" << std::endl;
std::cout << std::endl;
std::cout << "Notes:" << std::endl;
std::cout << " 'url' is the URL of the web page to be captured" << std::endl;
std::cout << " 'outputfile' is the prefix of the image files to be generated" << std::endl;
std::cout << std::endl;
std::cout << "Example: " << std::endl;
std::cout << " framecapture qt.nokia.com trolltech.png" << std::endl;
std::cout << std::endl;
std::cout << "Result:" << std::endl;
std::cout << " trolltech.png (full page)" << std::endl;
std::cout << " trolltech_frame1.png (...) trolltech_frameN.png ('N' number of internal frames)" << std::endl;
return 0;
}
QUrl url = QUrl::fromUserInput(QString::fromLatin1(argv[1]));
QString fileName = QString::fromLatin1(argv[2]);
QApplication a(argc, argv);
FrameCapture capture;
QObject::connect(&capture, SIGNAL(finished()), QApplication::instance(), SLOT(quit()));
capture.load(url, fileName);
return a.exec();
}
I get QtWidget file or directory not found. When I use QWidget, it will say
/home/me/qtwebkit-examples-and-demos/examples/webkit/framecapture-build-desktop/../framecapture/main.cpp:68:
error: variable ‘QApplication a’ has initializer but incomplete type
/home/me/qtwebkit-examples-and-demos/examples/webkit/framecapture-build-desktop/../framecapture/main.cpp:70:
error: incomplete type ‘QApplication’ used in nested name specifier
I don't know why none of the examples from git://gitorious.org/+qt-developers/qt/qtwebkit-examples-and-demos-staging.git is working. It always seems to complain about the #includes not finding the required components.
You will simply have to include QApplication. That is:
#include <QApplication>
If I'm not mistaken there is no such include file as <QtWidget> anyway. That should be <QWidget>. Given the specific example I would expect a general include of <QtGui> instead.