I am trying to understand glog and therefore trying to run the example code on their github page.
I have installed glog (version - 0.6.0) and its dependency gflags (version - 2.2) on my mac OS (10.15.7)
I compile the example below
#include <glog/logging.h>
int main(int argc, char* argv[]) {
// Initialize Google’s logging library.
google::InitGoogleLogging(argv[0]);
// test with setting a value for num_cookies
int num_cookies = 3;
// ...
LOG(INFO) << "Found " << num_cookies << " cookies";
}
using the following command (and it compiles without any errors or warnings).
g++ glog-test.cpp -I/usr/local/include -L/usr/local/lib -lglog -lgflags -o glog-test.o
When I run the example using the following command,
./glog-test.o --logtostderr=1 --stderrthreshold=0
I expect to see the message Found 3 cookies on my terminal, but I see nothing being printed.
I have also experimented with different values for logtostderr (0, 1) and stderrthreshold (0, 1, 2, 3) and nothing gets written to the directory or gets printed on the terminal.
Any help in understanding what I am doing wrong here would be much appreciated, thank you!
You have to parse the command line flags manually through gflags::ParseCommandLineFlags
#include <glog/logging.h>
#incldue <gflags/gflags.h>
int main(int argc, char* argv[]) {
// Initialize Google’s logging library.
google::InitGoogleLogging(argv[0]);
gflags::ParseCommandLineFlags(&argc, &argv, true);
// test with setting a value for num_cookies
int num_cookies = 3;
// ...
LOG(INFO) << "Found " << num_cookies << " cookies";
}
Just checked, the following works..
GLOG_stderrthreshold=0 GLOG_logtostderr=1 ./glog-test.o
which gives
Found 3 cookies
I do have gflags and installed, as seen by
cd /usr/local/lib
ls -l | grep "libgflags"
which gives
-lrwxr-xr-x 1 sn admin 48 Jun 5 2020 libgflags.2.2.2.dylib -> ../Cellar/gflags/2.2.2/lib/libgflags.2.2.2.dylib
lrwxr-xr-x 1 sn admin 46 Jun 5 2020 libgflags.2.2.dylib -> ../Cellar/gflags/2.2.2/lib/libgflags.2.2.dylib
-rw-r--r-- 1 sn admin 170520 Jun 27 00:35 libgflags.a
lrwxr-xr-x 1 sn admin 42 Jun 5 2020 libgflags.dylib -> ../Cellar/gflags/2.2.2/lib/libgflags.dylib
lrwxr-xr-x 1 sn admin 58 Jun 5 2020 libgflags_nothreads.2.2.2.dylib -> ../Cellar/gflags/2.2.2/lib/libgflags_nothreads.2.2.2.dylib
lrwxr-xr-x 1 sn admin 56 Jun 5 2020 libgflags_nothreads.2.2.dylib -> ../Cellar/gflags/2.2.2/lib/libgflags_nothreads.2.2.dylib
-rw-r--r-- 1 sn admin 168096 Jun 27 00:35 libgflags_nothreads.a
lrwxr-xr-x 1 sn admin 52 Jun 5 2020 libgflags_nothreads.dylib -> ../Cellar/gflags/2.2.2/lib/libgflags_nothreads.dylib
so I am not sure why
./glog-test.o --logtostderr=1 --stderrthreshold=0
didn't work.
Related
This question already has answers here:
Change current process environment's LD_LIBRARY_PATH
(5 answers)
Closed 2 months ago.
int main(int argc, char** argv) {
std::string r = ::file::RLocation("tensor_rt/lib");
setenv("LD_LIBRARY_PATH", r.c_str(), 1);
std::string filename = "libnvinfer.so.8";
CHECK(std::filesystem::exists(r+"/"+filename));
void * handle = dlopen(filename.c_str(), RTLD_NOW | RTLD_LOCAL);
CHECK(handle);
filename = "libnvinfer.so.8.5.1";
CHECK(std::filesystem::exists(r+"/"+filename));
handle = dlopen(filename.c_str(), RTLD_NOW | RTLD_LOCAL);
CHECK(handle) << dlerror();
}
This program fails at the last CHECK
F20221212 15:23:07.725180 2924123 test.cc:24] Check failed: handle libnvinfer.so.8.5.1: cannot open shared object file: No such file or directory
Why does it work with the first dlopen but not with the second one? The two files should be the same.
Edit:
ls -l gives
lrwxrwxrwx 1 shshao shshao 19 Dec 12 15:20 libnvinfer.so -> libnvinfer.so.8.5.1
lrwxrwxrwx 1 shshao shshao 19 Dec 12 15:20 libnvinfer.so.8 -> libnvinfer.so.8.5.1
-rwxr-xr-x 1 shshao shshao 487512744 Oct 27 15:37 libnvinfer.so.8.5.1
It's because unlike other env variables, LD_LIBRARY_PATH can't be modified within a program: https://groups.google.com/g/comp.lang.java.programmer/c/LOu18-OWAVM/m/b0YBJhoKS04J
In boost::filesystem, the path class always tries to dereference symlinks. A lot of the API is catered towards trying to make symlinks seem invisible. I'm guessing a lot of their syscalls underneath are stat related instead of lstat related. This is problematic for me, as I'm trying to get the symlink itself.
For example, doing fs::exists("some_symlink") because, although some_symlink exists, its referent does not exist. I want this to give me back true, and in the older versions of boost it supports it: https://www.boost.org/doc/libs/1_32_0/libs/filesystem/doc/operations.htm#symbolic_link_exists
However, now it doesnt. Is there any good way of doing this?
You can use boost::filesystem::symlink_status to get a file_status, and then check its type().
#include <boost/filesystem.hpp>
#include <iostream>
#include <iomanip>
int main(){
auto a = boost::filesystem::symlink_status("a_symlink");
auto b = boost::filesystem::symlink_status("main.cpp");
auto c = boost::filesystem::symlink_status("not_existing");
auto d = boost::filesystem::symlink_status("a_broken_symlink");
std::cout << std::boolalpha
<< (a.type() == boost::filesystem::file_not_found) << " "
<< (b.type() == boost::filesystem::file_not_found) << " "
<< (c.type() == boost::filesystem::file_not_found) << " "
<< (d.type() == boost::filesystem::file_not_found) << "\n";
}
Execution:
$ touch f
$ ln -s main.cpp a_symlink
$ ln -s f a_broken_symlink
$ rm f
$ ls -l
total 4
lrwxrwxrwx 1 2001 2000 1 Jun 3 23:33 a_broken_symlink -> f
lrwxrwxrwx 1 2001 2000 8 Jun 3 23:33 a_symlink -> main.cpp
-rw-rw-rw- 1 2001 2000 637 Jun 3 23:33 main.cpp
$ g++ -std=c++14 -Wall -Wextra -pedantic -lboost_filesystem -lboost_system main.cpp && ./a.out
false false true false
Live on Coliru
I have two lists with diffrent itemsas follows:
numbers = ['1','2','3','4','5','6','7',]
days = ['mon','tue','wed','thu','fri','sat','sun',]
I want to print from both to look like this:
result = 1
mon
2
tue
3
wed
4
thu.....etc
Is there such as code that does this?
Regards
You can use zip to combine two lists.
The zip() function is probably what you want here.
You can print such output with this.
for n, m in zip(numbers, days):
print(n, m)
Output -
1 mon
2 tue
3 wed
4 thu
5 fri
6 sat
7 sun
Hope it helps.
Update - zip function combines two equal-length collections (e.g. list) together and produces a tuple object.
This can resolve your problem.
<?php
//array 1
$numbers = ['1','2','3','4','5','6','7',];
// array 2
$days = ['mon','tue','wed','thu','fri','sat','sun',];
// use for loop
for($i = 0; $i < 7; $i++) {
echo $numbers[$i].' '.$days[$i].'<br>';
}
?>
Output -
1 mon
2 tue
3 wed
4 thu
5 fri
6 sat
7 sun
I'm running into a problem using RInside vs the console. This is all run on ubuntu 14.04 using R 3.2.4 installed via apt-get from CRAN. Here is the c++ and R code:
#include <RInside.h> // for the embedded R via RInside
int main(int argc, char *argv[]) {
RInside R(argc, argv); // create an embedded R instance
R.parseEval("source('abline.R')");
}
abline.R
bp <- data.frame(
age = c(28, 23, 52, 42, 27, 29, 43, 34, 40, 28),
systolic = c(70, 68, 90, 75, 68, 80, 78, 70, 80, 72))
str(bp)
attach(bp)
bp.lm <- lm(systolic ~ age)
plot(age, systolic)
abline(bp.lm)
lines(lowess(age, systolic, f=0.75), lty=2)
The R code works fine from the console, but errors when the program is run.
mlilback#rc2x:/tmp/abtest$ ./abtest
'data.frame': 10 obs. of 2 variables:
$ age : num 28 23 52 42 27 29 43 34 40 28
$ systolic: num 70 68 90 75 68 80 78 70 80 72
Error in if (noInt) { : argument is of length zero
terminate called after throwing an instance of 'std::runtime_error'
what(): Error evaluating: source('abline.R')
Aborted (core dumped)
The if (noInt) { is from the source of abline (line 18 in my version of R). I'm completely stumped as to why this only happens via RInside.
Any ideas?
Works for me without any issues. Ubuntu 16.04. Running out of the examples directory to get the GNUmakefile-based build for free:
~/git/rinside/inst/examples/standard(master)$ vi soquestion.cpp
~/git/rinside/inst/examples/standard(master)$ make soquestion
ccache g++ -I/usr/share/R/include -I/usr/local/lib/R/site-library/Rcpp/include \
-I/usr/local/lib/R/site-library/RInside/include -g -O3 -Wall -pipe \
-Wno-unused -Wall soquestion.cpp -Wl,--export-dynamic -fopenmp \
-L/usr/lib/R/lib -lR -lpcre -llzma -lbz2 -lz -lrt -ldl -lm -lblas -llapack \
-L/usr/local/lib/R/site-library/RInside/lib -lRInside \
-Wl,-rpath,/usr/local/lib/R/site-library/RInside/lib -o soquestion
~/git/rinside/inst/examples/standard(master)$ vi abline.R
~/git/rinside/inst/examples/standard(master)$ ./soquestion
'data.frame': 10 obs. of 2 variables:
$ age : num 28 23 52 42 27 29 43 34 40 28
$ systolic: num 70 68 90 75 68 80 78 70 80 72
~/git/rinside/inst/examples/standard(master)$
I literally just copied an pasted your two files. Also:
~/git/rinside/inst/examples/standard(master)$ ls -1tr | tail -4
soquestion.cpp
soquestion
abline.R
Rplots.pdf
~/git/rinside/inst/examples/standard(master)$
You probably want to open a device file via pdf() or png() ...
Simple regex search:
> db.lipsum.find({"d.text":{$regex:'cursus'}});
does well, and returns many thousands.
A bit more complex one:
db.lipsum.find({"d.text":{$regex:'cursus((?!turpis massa).)*$'}});
kills the mongod:
Tue Nov 26 11:01:03 DBClientCursor::init call() failed
Tue Nov 26 11:01:03 query failed : lipsum.lipsum { d.text: { $regex: "cursus((?!turpis massa).)*$" } } to: 127.0.0.1:27017
Error: error doing query: failed
Tue Nov 26 11:01:03 trying reconnect to 127.0.0.1:27017
Tue Nov 26 11:01:03 reconnect 127.0.0.1:27017 failed couldn't connect to server 127.0.0.1:27017
There is nothing in mongodb.log. The last lines are:
Tue Nov 26 11:00:17 [conn2] query lipsum.lipsum query: { d.text: { $regex: "cursus" } } cursorid:5200338523215960499 ntoreturn:0 keyUpdates:0 locks(micros) r:1266 nreturned:101 reslen:159838 1ms
Tue Nov 26 11:00:18 [conn2] run command admin.$cmd { replSetGetStatus: 1.0, forShell: 1.0 }
Tue Nov 26 11:00:18 [conn2] command admin.$cmd command: { replSetGetStatus: 1.0, forShell: 1.0 } ntoreturn:1 keyUpdates:0 reslen:76 0ms
So there are 2 questions:
How to get detailed information what happened ?
How to write correct regex to fetch objects that have no "turpis massa" after "cursus"?
Mongodb 2.2.4, Ubuntu 13.04.
My testing db:
load("lorem.js"); // from https://github.com/f/loremjs
var lorem = new Lorem;
lorem.type = Lorem.TEXT;
lorem.query = '2p';
for(var i=0; i < 20000; i++){
db.lipsum.insert({t: $currentDate, d: {text:lorem.createLorem()}})
}