FIND_LIBRARY does not find existing libraries - qt

In the function findQt4.cmake:
FIND_LIBRARY(QT_QTCORE_LIBRARY_RELEASE
NAMES QtCore QtCore4
HINTS ${QT_LIBRARY_DIR_TMP}
)
if I print:
MESSAGE("HINT PATH " ${QT_LIBRARY_DIR_TMP})
I will get:
~/dev/Libraries/Qt4.8.0/lib
In this directory there are: ~/dev/Libraries/Qt4.8.0/lib$ ls -all libQtCore*
I got:
-rw-r--r-- 1 abc abc 950 Nov 30 13:08 libQtCore.la
-rw-r--r-- 1 abc abc 942 Nov 30 13:07 libQtCore.prl
lrwxrwxrwx 1 abc abc 18 Nov 30 13:07 libQtCore.so -> libQtCore.so.4.8.0
lrwxrwxrwx 1 abc abc 18 Nov 30 13:08 libQtCore.so.4 -> libQtCore.so.4.8.0
lrwxrwxrwx 1 abc abc 18 Nov 30 13:08 libQtCore.so.4.8 -> libQtCore.so.4.8.0
-rwxr-xr-x 1 abc abc 2697932 Nov 30 13:08 libQtCore.so.4.8.0
But why the FIND_LIBRARY function return: QT_QTCORE_LIBRARY_RELEASE = NOT FOUND?
Even, there is no result if I do like this:
FIND_LIBRARY(QT_QTCORE_LIBRARY_RELEASE
NAMES libQtCore.so
HINTS ${QT_LIBRARY_DIR_TMP}
)

Instead of find_library() you can use find_package(). This is the common way for Qt with CMake.
# Find Qt package
find_package(Qt4 REQUIRED)
include(${QT_USE_FILE}) # Add and run Qt CMake modules
add_definitions(${QT_DEFINITIONS}) # Add definitions (if required)
# And later put all together
add_executable( ... )
target_link_libraries( ... ${QT_LIBRARIES}) # Link Qt libraries

Related

What is the purpose of --file-type in ls command

I'm trying to understand the purpose of the --file-type argument of the UNIX ls command.
I didn't find any example using ls --file-type on the web – neither was I able to make sense of the --file-type argument by issuing ls --file-type myself.
What's the purpose of ls --file-type? Would anyone please give me a helpful example of ls --file-type making the purpose of this argument more clear to me?
Quoting from info ls:
-F
Append a character to each file name indicating the file type.
Also, for regular files that are executable, append *. The file
type indicators are / for directories, # for symbolic links,
| for FIFOs, = for sockets, > for doors, and nothing for
regular files.
--file-type is just like -F, except that it doesn't append * for executable files:
$ ln -s /etc/passwd foo
$ touch bar; chmod +x bar
$ ls
foo bar
$ ls -F
foo# bar*
$ ls --file-type
foo# bar
...
...
The --file-type option is similar to the -F option.
-F, --classify
append indicator (one of */=>#|) to entries
--file-type
likewise, except do not append `*'
Source.
Here's an example of ls --file-tye /
bin# boot/ dev/ etc/ home/ lib# lib64# lost+found/ media/ mnt/ opt/ proc/ root/ run/ sbin# srv/ sys/ tmp/ usr/ var/
as compared to the output of ls -l /
lrwxrwxrwx 1 root root 7 Jan 19 02:32 bin -> usr/bin
drwxr-xr-x 4 root root 4096 Jan 1 1970 boot
drwxr-xr-x 24 root root 4220 Mar 26 19:56 dev
drwxr-xr-x 88 root root 4096 Mar 26 21:15 etc
drwxr-xr-x 4 root root 4096 Apr 5 2020 home
lrwxrwxrwx 1 root root 7 Jan 19 02:32 lib -> usr/lib
lrwxrwxrwx 1 root root 7 Jan 19 02:32 lib64 -> usr/lib
drwx------ 2 root root 16384 Apr 5 2020 lost+found
drwxr-xr-x 2 root root 4096 Dec 11 20:19 media
drwxr-xr-x 7 root root 4096 Sep 8 2020 mnt
drwxr-xr-x 9 root root 4096 Feb 9 13:58 opt
dr-xr-xr-x 335 root root 0 Mar 26 19:56 proc
drwxr-x--- 9 root root 4096 Feb 11 13:18 root
drwxr-xr-x 28 root root 700 Mar 26 21:15 run
lrwxrwxrwx 1 root root 7 Jan 19 02:32 sbin -> usr/bin
drwxr-xr-x 4 root root 4096 Apr 5 2020 srv
dr-xr-xr-x 13 root root 0 Mar 26 19:56 sys
drwxrwxrwt 12 root root 320 Mar 26 22:11 tmp
drwxr-xr-x 9 root root 4096 Mar 25 11:06 usr
drwxr-xr-x 12 root root 4096 Mar 25 11:07 var
As you see the symbol "#" indicates symbolic-links (l). Directories (d) and regular files (f) are not flagged by the --file-type argument.
Issuing ls --file-type in my home directory is identical to ls ~ since it only contains directories and regular files and hence the output of the former doesn't contain any indicators.
See also the answer of PesaThe for a full list of the indicator symbols.

Rename files based on a list

I would like to rename all files in a folder based on a text file (list.txt) with two columns: oldnam (which represents the current name) and newnam (which contains the required new name).
My text file:
df <- "oldnam newnam
TRTY_3.DOT 124325.DOT
TRTY_4.DOT 123454.DOT
TRTY_5.DOT 124355.DOT"
df <- read.table(text=df, header=T)
write.table(df, "list.txt", col.names=T, row.names=F, quote=F)
It is possible to do it from R or directly in bash (both solutions could help a lot)?
First list the files in your folder
file.list <- list.files(yourfolderpath, pattern="\\.DOT$", full.names=TRUE)
Then use file.rename to rename files based on your list.txt file.
file.rename(from = file.path(dirname(file.list), list.txt$oldnam), to = file.path(dirname(file.list), list.txt$newnam))
initial files in folder
ll
total 8
-rw-r--r-- 1 root root 0 Jan 15 18:01 1.txt
-rw-r--r-- 1 root root 0 Jan 15 18:01 2.txt
-rw-r--r-- 1 root root 0 Jan 15 18:01 3.txt
-rw-r--r-- 1 root root 0 Jan 15 18:01 4.txt
-rw-r--r-- 1 root root 0 Jan 15 18:01 5.txt
-rw-r--r-- 1 root root 40 Jan 15 18:01 files
-rwxr-xr-x 1 root root 272 Jan 15 18:10 script.sh
list of files
cat files
1.txt 11.txt
2.txt 22.txt
3.txt 33.txt
running the script
./script.sh files
root#xx:~#
files in folder after running script
ll
total 8
-rw-r--r-- 1 root root 0 Jan 15 18:01 11.txt
-rw-r--r-- 1 root root 0 Jan 15 18:01 22.txt
-rw-r--r-- 1 root root 0 Jan 15 18:01 33.txt
-rw-r--r-- 1 root root 0 Jan 15 18:01 4.txt
-rw-r--r-- 1 root root 0 Jan 15 18:01 5.txt
-rw-r--r-- 1 root root 40 Jan 15 18:01 files
-rwxr-xr-x 1 root root 270 Jan 15 18:11 script.sh
the script
cat script.sh
#!/bin/bash
filename="$1"
folder_with_files=/root/
while read -r line
do
oldname=$(echo "$line" | awk '{print $1}')
newname=$(echo "$line" | awk '{print $2}')
[ -z "$oldname" ] && { break ; }
mv $folder_with_files$oldname $folder_with_files$newname
done < "$filename"

grep not extracting desired string

I'm working on the following question for my class (in Unix) and I'm running into some problems.
Using the grep command and regular expressions, create a pipe-based
chain of commands that will list all files in the default directory
that others can read or write.
This is the command I have so far and it will correctly match the right lines, but I only want to to print the name of the file that has the desired permissions.
ls -la | grep "^.......rw.*:\d\d\s(.*)$"
here is the result of just typing ls -la by the way which is what I'm "greping"
total 344
drwxr-xr-x 10 cameronpattisall staff 340 Apr 7 11:21 .
drwxr-xr-x 7 cameronpattisall staff 238 Apr 7 11:22 ..
-rw-r--r-- 1 cameronpattisall staff 6148 Apr 7 11:21 .DS_Store
-rw-r--r-- 1 cameronpattisall staff 11591 Apr 7 11:21 DifferencesToTagged.txt
-rw-r--r-- 1 cameronpattisall staff 4291 Apr 7 11:21 functions.py
-rw-r--r-- 1 cameronpattisall staff 6080 Apr 7 11:21 ls.txt
-rw-r--r-- 1 cameronpattisall staff 5511 Apr 7 11:21 prog4.py
-rw-r--r-- 1 cameronpattisall staff 345 Apr 7 11:21 shared.py
-rw-r--r-- 1 cameronpattisall staff 1832 Apr 7 11:21 subversion-log.txt
-rw-r--r-- 1 cameronpattisall staff 122295 Apr 7 11:21 testcases.txt
I guess the solution is to use:
grep -E "^-.{6}(r|.w)"
The structure of the first column is "-/d" (file/dir) + xxx (owner) + xxx (group) + xxx (others).
So you want to match those starting with - (file) and containing in the "gorup" part either r.. or .w..
To print just the file names, then you can pipe to grep -o '[^ ]*$'. This will print the last block of text. Note this is terrible fragile, since in a file name with spaces it will just print the last one.
Test
I stored your ls -la in the file a:
$ grep -E "^-.{6}(r|.w)" a | grep -o '[^ ]*$'
.DS_Store
DifferencesToTagged.txt
functions.py
ls.txt
prog4.py
shared.py
subversion-log.txt
testcases.txt
If you're already matching the right lines, you can append something like
| tr -s ' ' | cut -d ' ' -f 9- to your pipeline.
The tr -s ' ' replaces multiple sequential spaces with a single space; the cut command removes everything except the ninth field onwards from each line, with fields delimited by single space characters.

QTDir why not display all the folder in the root "/" in MacOs?

I'm starting to use QT, and trying QDir I copy the example in the references of QT the one which listing the content of a folder.
I'm trying to listing the content of the root path in a MacOS snow leopard, version of QT 5.1.1 But don't appear all of it :S
This is the code:
QFileInfoList list = QDir::root().entryInfoList();
for(int i=0; i<list.count(); i++){
cout<< list[i].fileName().toStdString()<<endl;
}
But the output of this program is:
.
..
Applications
Developer
Library
opt
sockets.log
System
Users
When I think it should be:
I know that ls -l don't show . and .. my worry is about the other folders, I put a line break separating the folders that appears in the output and ones who don't.
$ ls -l /
drwxrwxr-x+ 63 root admin 2142 Sep 18 21:22 Applications
drwxrwxr-x# 15 root admin 510 Jan 1 2012 Developer
drwxrwxr-t+ 63 root admin 2142 Sep 16 13:05 Library
drwxr-xr-x 3 root admin 102 Jul 23 02:45 opt
-rw-rw-rw- 1 Andreu admin 75 Sep 19 12:35 sockets.log
drwxr-xr-x 4 root wheel 136 Sep 15 20:49 System
drwxr-xr-x 5 root admin 170 Sep 15 20:17 Users
drwxr-xr-x# 2 root wheel 68 Jun 23 2009 Network
drwxrwxrwt# 5 root admin 170 Sep 16 14:01 Volumes
drwxr-xr-x# 39 root wheel 1326 Sep 15 22:46 bin
drwxrwxr-t# 2 root admin 68 Jun 23 2009 cores
dr-xr-xr-x 3 root wheel 4272 Sep 16 13:26 dev
lrwxr-xr-x# 1 root wheel 11 Sep 15 20:04 etc -> private/etc
dr-xr-xr-x 2 root wheel 1 Sep 16 13:26 home
-rw-r--r--# 1 root wheel 20828964 Jun 8 2011 mach_kernel
dr-xr-xr-x 2 root wheel 1 Sep 16 13:26 net
drwxr-xr-x# 6 root wheel 204 Sep 15 20:08 private
drwxr-xr-x# 67 root wheel 2278 Sep 15 22:46 sbin
lrwxr-xr-x# 1 root wheel 11 Sep 15 20:04 tmp -> private/tmp
drwxr-xr-x# 14 root wheel 476 Sep 16 13:07 usr
lrwxr-xr-x# 1 root wheel 11 Sep 15 20:04 var -> private/var
Anyone can tell me why the other folders not appear?
Thanks :)
Add filter to entryInfoList
On Unix entryInfoList() does not list hidden files. You have to "ask" for them. I think it will be similiar on Mac.
QFileInfoList list = QDir::root().entryInfoList(QDir::AllEntries | QDir::System | QDir::Hidden);
for(int i=0; i<list.count(); i++){
cout<< list[i].fileName().toStdString()<<endl;
}

Creating temporary sandbox environment in unix

Just wondering is there any way to create a temporary sandbox environment for running commands?
My requirement is that i am hosting a webservice in unix and i need to execute a commanline tool to return output to the webservice client. since i am passing the values received from the client to the commanline tool, i would like to execute the commands in sandboxed environment.
I'm not sure but, you can try to use the "chroot" command to create new "root" enviroment, for example,
If you have the directory structure and you want to "protect" the "license" file,
/
/etc
+ license
/bin
+ ls
/lib
+ ...
You can create a chroot enviroment as
itily#openzooey:~$ mkdir chroot_example
itily#openzooey:~$ cd chroot_example/
itily#openzooey:~/chroot_example$ mkdir -p usr/lib lib bin etc
itily#openzooey:~/chroot_example$ cd bin/
itily#openzooey:~/chroot_example/bin$ cp /bin/ls .
itily#openzooey:~/chroot_example/bin$ ldd ls
libsec.so.1 => /lib/libsec.so.1
libnvpair.so.1 => /lib/libnvpair.so.1
libcmdutils.so.1 => /lib/libcmdutils.so.1
libcurses.so.1 => /lib/libcurses.so.1
libc.so.1 => /lib/libc.so.1
libavl.so.1 => /lib/libavl.so.1
libidmap.so.1 => /usr/lib/libidmap.so.1
libnsl.so.1 => /lib/libnsl.so.1
libuutil.so.1 => /lib/libuutil.so.1
libmp.so.2 => /lib/libmp.so.2
libmd.so.1 => /lib/libmd.so.1
libm.so.2 => /lib/libm.so.2
Now populate the "shared lib" required by the ls command (using the ldd we know which are the required shared libs
itily#openzooey:~/chroot_example/bin$ ldd ls |awk '{print "cp "$3" lib/"}'
cp /lib/libsec.so.1 lib/
cp /lib/libnvpair.so.1 lib/
cp /lib/libcmdutils.so.1 lib/
cp /lib/libcurses.so.1 lib/
cp /lib/libc.so.1 lib/
cp /lib/libavl.so.1 lib/
cp /usr/lib/libidmap.so.1 lib/
cp /lib/libnsl.so.1 lib/
cp /lib/libuutil.so.1 lib/
cp /lib/libmp.so.2 lib/
cp /lib/libmd.so.1 lib/
cp /lib/libm.so.2 lib/
Now we need to copy to our new "lib" and usr/lib directory
itily#openzooey:~/chroot_example/bin$ cd ..
itily#openzooey:~/chroot_example$ ldd /bin/ls |awk '{print "cp "$3" lib/"}'|bash
itily#openzooey:~/chroot_example$ ls -ltr
total 9
drwxr-xr-x 2 itily staff 2 dic 22 14:37 etc
drwxr-xr-x 2 itily staff 3 dic 22 14:37 bin
drwxr-xr-x 2 itily staff 14 dic 22 14:38 lib
itily#openzooey:~/chroot_example$ cp /usr/lib/libidmap.so.1 usr/lib/
itily#openzooey:~/chroot_example$ cp /usr/lib/ld.so.1 usr/lib/
itily#openzooey:~/chroot_example$ cd lib/
itily#openzooey:~/chroot_example/lib$ ls -l
total 7615
-rwxr-xr-x 1 itily staff 14044 dic 22 14:38 libavl.so.1
-rwxr-xr-x 1 itily staff 1721400 dic 22 14:38 libc.so.1
-rwxr-xr-x 1 itily staff 26748 dic 22 14:38 libcmdutils.so.1
-rwxr-xr-x 1 itily staff 293876 dic 22 14:38 libcurses.so.1
-rwxr-xr-x 1 itily staff 97852 dic 22 14:38 libidmap.so.1
-rwxr-xr-x 1 itily staff 398704 dic 22 14:38 libm.so.2
-rwxr-xr-x 1 itily staff 87164 dic 22 14:38 libmd.so.1
-rwxr-xr-x 1 itily staff 25140 dic 22 14:38 libmp.so.2
-rwxr-xr-x 1 itily staff 648776 dic 22 14:38 libnsl.so.1
-rwxr-xr-x 1 itily staff 74776 dic 22 14:38 libnvpair.so.1
-rwxr-xr-x 1 itily staff 97500 dic 22 14:38 libsec.so.1
-rwxr-xr-x 1 itily staff 49556 dic 22 14:38 libuutil.so.1
itily#openzooey:~/chroot_example/lib$ cd ..
So, the final structure is
itily#openzooey:~/chroot_example$ ls -l
total 12
drwxr-xr-x 2 itily staff 3 dic 22 14:37 bin
drwxr-xr-x 2 itily staff 5 ene 10 20:43 etc
drwxr-xr-x 2 itily staff 14 ene 10 20:48 lib
drwxr-xr-x 3 itily staff 3 ene 10 20:40 usr
Also you need the group, passwd and other files
itily#openzooey:~/chroot_example$ echo "this is a test" > etc/license
itily#openzooey:~/chroot_example$ cd etc/
itily#openzooey:~/chroot_example/etc$ cat /etc/group |grep staff > group
itily#openzooey:~/chroot_example/etc$ cat /etc/passwd |grep itily > passwd
Now you can run the chroot command, but if you try to run as non root you will get the error
itily#openzooey:~$ chroot chroot_example bin/ls /etc
chroot: cannot change root directory to chroot_example: Not owner
So, you need to run as root
itily#openzooey:~$ pfexec chroot chroot_example /bin/ls -l /etc
total 6
-rw-r--r-- 1 101 10 11 Jan 10 19:43 group
-rw-r--r-- 1 101 10 18 Jan 10 19:42 license
-rw-r--r-- 1 101 10 49 Jan 10 19:43 passwd
I hope it's what you are looking for ...
Urko,
You didn't say which Unix. Solaris zones do that easily. Here's an example how to set one up:
http://www.solarisinternals.com/wiki/index.php/Zones
I routinely develop in sandboxes in Debian Linux and like to use chroots so that I don't destroy my host machine in case I do something stupid by accident (which happens a lot). I put together a set of scripts for Debian and Ubuntu for me to create chroots (both cross-distro and x86 in x86-64) which you may find helpful.
https://github.com/vtonehundred/vroot

Resources