I'm facing an annoying problem that has been holding me back from programming for some time. I intend to start a personal project in which I need to use a database to store certain information and I decided to use SQLite however I did not like the C-ish API so I came across SOCI wrapper in the SQLite wiki.
I went to the official SOCI website, read the documentation and decided to give it a go. I followed the instructions in the 'Installation' chapter of the documentation and after installing all requirements I compiled it and installed it with:
cmake -DWITH_BOOST=ON -DSOCI_TESTS=ON -DWITH_SQLITE3=ON
make
make test
sudo make install
All tests completed successfully however when trying to run (after compiling with g++ test.cpp -o1 -lsoci_core -lsoci_sqlite3) a program such as this one:
test.cpp:
#include "soci/soci.h"
#include "soci/sqlite3/soci-sqlite3.h"
#include <iostream>
int main()
{
soci::session sql(soci::sqlite3, "testdb.db");
return 0;
}
I get an error saying: "Error while loading shared libraries: libsoci_sqlite3.so.3.1: cannot open shared object file: No such file or directory." but looking at the install log I can clearly see that the shared library is installed.
I believe I have found the issue. Doing a:
strace -e open ./1 2>&1 | grep soci
Outputs the following:
open("/usr/local/lib/libsoci_core.so.3.1", O_RDONLY) = 3
open("/lib/x86_64-linux-gnu/tls/x86_64/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/tls/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/x86_64/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/tls/x86_64/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/tls/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/x86_64/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib/tls/x86_64/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib/tls/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib/x86_64/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/tls/x86_64/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/tls/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
./1: error while loading shared libraries: libsoci_sqlite3.so.3.1: cannot open shared object file: No such file or directory
By looking at it you can clearly see that it searches /usr/local/lib/ only for soci_core whereas normally it should search for soci_sqlite3 as well. A quick and dirty hack that fixes the problem is to create a smylink to libsoci_sqlite3.so.3.1 in any of the other folders listed there but I'm quite sure that there is a better way of fixing it.
On your SOCI installation libs are located in /usr/local/lib64/
Following statement should work:
g++ test.cpp -o test -I/usr/local/include/soci -L/usr/local/lib64/ -lsoci_core -lsoci_sqlite3 \
-Wl,-rpath=/usr/local/lib64/
Related
I'm having trouble making GDB load a particular library as a replacement for a library used in a core file.
How can I make so GDB list which paths it tries for each library? Something like set debug auto-load on, but for shared libraries.
I'm having trouble making GDB load a particular library as a replacement for a library used in a core file.
GDB will look up absolute paths it obtains from the core.
Because of this, setting solib-search-path is ineffective, and only setting sysroot or solib-absolute-prefix is.
In addition, you need to set sysroot or solib-absolute-prefix before loading the core. That is, this works:
gdb -ex 'set sysroot /tmp/sysroot' -ex 'file a.out' -ex 'core core'
whereas this doesn't (sysroot setting happens after the file and core are already loaded):
gdb -ex 'set sysroot /tmp/sysroot` a.out core
How can I make so GDB list which paths it tries for each library?
There doesn't appear to be such an option. In particular, set debug solib on doesn't actually help here. Using trunk GDB:
gdb/gdb
GNU gdb (GDB) 14.0.50.20230115-git
...
(gdb) set debug solib on
(gdb) file /tmp/a.out
Reading symbols from /tmp/a.out...
(gdb) core /tmp/core
[New LWP 29158]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Core was generated by `./a.out'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x0000000000401116 in main () at crash.c:3
3 return *ip;
(gdb)
You can determine where GDB is looking for shared libraries by running it under strace:
strace -e open,openat -o /tmp/strace.out gdb/gdb -ex quit /tmp/a.out /tmp/core
In /tmp/strace.out:
...
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=29289, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
openat(AT_FDCWD, "/sys/devices/system/cpu/online", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/tmp/a.out", O_RDONLY|O_CLOEXEC) = 9
openat(AT_FDCWD, "/tmp/a.out", O_RDONLY|O_CLOEXEC) = 9
openat(AT_FDCWD, "/tmp/a.out", O_RDONLY) = 9
openat(AT_FDCWD, "/tmp/core", O_RDONLY|O_CLOEXEC) = 9
openat(AT_FDCWD, "/tmp/a.out", O_RDONLY|O_CLOEXEC) = 10
openat(AT_FDCWD, "/tmp/a.out", O_RDONLY) = 10
openat(AT_FDCWD, "/tmp/a.out", O_RDONLY|O_CLOEXEC) = 11
openat(AT_FDCWD, "/usr/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 11
openat(AT_FDCWD, "/usr/lib64/libc.so.6", O_RDONLY) = 11
openat(AT_FDCWD, "/usr/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 12
openat(AT_FDCWD, "/usr/lib64/ld-linux-x86-64.so.2", O_RDONLY|O_CLOEXEC) = 12
openat(AT_FDCWD, "/usr/lib64/ld-linux-x86-64.so.2", O_RDONLY) = 12
openat(AT_FDCWD, "/usr/lib64/ld-linux-x86-64.so.2", O_RDONLY|O_CLOEXEC) = 13
...
So I'm on mac and wanted to experiment with the latest llvm release, without having to wait for them to be passed on the xcode command line tools.
So I downloaded the LLVM 10 release pre-built binary from their downloads page, and stuck it in a folder called llvm. So the clang executable can be found in ~/SDKs/LLVM/bin.
I make this program:
#include <string>
#include <iostream>
int main(int argc, char const *argv[])
{
std::string myString("Hello World");
std::cout << myString;
return 0;
}
and run:
~/SDKs/Clang+LLVM10/bin/clang++ main.cpp
I get this fatal error:
~/SDKs/Clang+LLVM10/bin/../include/c++/v1/string.h:60:15: fatal error:
'string.h' file not found
#include_next <string.h>
^~~~~~~~~~
Which doesn't make sense because I can find string.h manually using finder, and it's right there in the folder that is quoted in the error.
I'm guessing this has something to do with clang++ searching my system include path first, finding an older string.h there and so choosing not to use the updated string.h, causing an error?
Some additional info if it helps:
Running this (the new compiler)
~/Programming/SDKs/Clang+LLVM10/bin/clang++ -Wp,-v -E -xc -x c++ /dev/null
Gives me:
clang -cc1 version 10.0.0 based upon LLVM 10.0.0 default target x86_64-apple-darwin18.7.0
ignoring nonexistent directory "/usr/include/c++/v1"
ignoring nonexistent directory "/usr/include"
#include "..." search starts here:
#include <...> search starts here:
~/SDKs/Clang+LLVM10/bin/../include/c++/v1
/usr/local/include
~/SDKs/Clang+LLVM10/lib/clang/10.0.0/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
# 1 "/dev/null"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 393 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "/dev/null" 2
Running (this is the default compiler with that comes with my mac)
clang++ -Wp,-v -E -xc -x c++ /dev/null
gives me
clang -cc1 version 11.0.0 (clang-1100.0.33.17) default target x86_64-apple-darwin18.7.0
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.
# 1 "/dev/null"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 374 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "/dev/null" 2
I also encountered this error. And after my a digging out, I found the reason:
The include_next is a gnu compiler extension, seems it does not exist in clang. Although clang(/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++) has packaged the original std lib under directory:
“ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/“, but as compile source codes from Apple Mac, generally it always specifies the system root path by option “-isysroot”, generally the command is like this:“-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk”
, to overwrite the default std lib search path.
So maybe you must overwrite the default sys root to ensure right std lib to be linked.
I am running a Virtual Machine of Ubuntu 18.04 via Oracle VirtualBox.
I need Eclipse (including cdt) for a c++ project. So I ran the following statement on the console:
sudo apt-get install eclipse eclipse-cdt g++
Then I waited until it finished installing. Afterwards, I tried to run Eclipse, which caused the following error:
An error has occurred. See the log file
/home/matthias/.eclipse/org.eclipse.platform_3.8_155965261/configuration/1540208856928.log
So, I checked the log file. It says the following:
!SESSION Mon Oct 22 13:38:43 CEST 2018
----------------------------------------- !ENTRY org.eclipse.equinox.launcher 4 0 2018-10-22 13:38:43.262 !MESSAGE
Exception launching the Eclipse Platform: !STACK
java.lang.ClassNotFoundException:
org.eclipse.core.runtime.adaptor.EclipseStarter at
java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:466)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:566)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:626)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584) at
org.eclipse.equinox.launcher.Main.run(Main.java:1438) at
org.eclipse.equinox.launcher.Main.main(Main.java:1414)
Unfortunately, I am an absolute beginner with Ubuntu, as well as c++. I have no idea what could cause this problem. Can anybody help me?
I found that on Ubuntu18.04 this is due to a packaging problem (debugged with the help of a talented coworker). The fix was to manually install files from the older libequinox-osgi-java_3.8.1-8 package, to keep packaging happy.
Locate and get the .deb file
Examine contents of package vs. the system for overlaps
Manually extract deb into '/'
Commands:
$ cd /tmp
$ wget http://archive.ubuntu.com/ubuntu/pool/universe/e/eclipse/libequinox-osgi-java_3.8.1-8_all.deb
$ dpkg -c /tmp/libequinox-osgi-java_3.8.1-8_all.deb
$ dpkg -L libequinox-osgi-java
$ cd /
$ sudo dpkg -x /tmp/libequinox-osgi-java_3.8.1-8_all.deb
Notes:
Here we see commands to show eclipse depends on eclipse-rcp, which depends on libequinox-osgi-java (>= 3.9.1), which are all installed:
$ lsb_release -rc
Release: 18.04
Codename: bionic
$ apt-rdepends eclipse 2>&1 | egrep '^eclipse-rcp|libequinox-osgi-java'
eclipse-rcp
Depends: libequinox-osgi-java (>= 3.9.1)
libequinox-osgi-java
$ dpkg-query -W eclipse eclipse-rcp libequinox-osgi-java
eclipse 3.8.1-11
eclipse-rcp 3.8.1-11
libequinox-osgi-java 3.9.1-1
These commands show that the out-of-the box eclipse stubbornly insists on loading the older osgi_3.8.1.dist.jar despite not being able to stat it or open it:
$ strace -f -e trace=file /usr/lib/eclipse/eclipse -debug -clean -initialize 2>&1 |
egrep '^Framework.located|file:.*osgi_3.*jar|stat.*osgi_3.*jar'
[pid 117096] stat("/usr/lib/eclipse/plugins/org.eclipse.osgi_3.8.1.dist.jar", 0x7f4f0ca95540) = -1 ENOENT (No such file or directory)
[pid 117096] stat("/usr/lib/eclipse/plugins/org.eclipse.osgi_3.8.1.dist.jar", 0x7f4f0ca954c0) = -1 ENOENT (No such file or directory)
[pid 117096] stat("/usr/lib/eclipse/plugins/org.eclipse.osgi_3.8.1.dist.jar", 0x7f4f0ca95550) = -1 ENOENT (No such file or directory)
[pid 117096] stat("/usr/lib/eclipse/plugins/org.eclipse.osgi_3.8.1.dist.jar", 0x7f4f0ca954d0) = -1 ENOENT (No such file or directory)
Framework located:
file:/usr/lib/eclipse/plugins/org.eclipse.osgi_3.8.1.dist.jar
...
The older package just happens to be the same package used in the Ubuntu16.04 eclipse packages. We tried a few different ways to force install both older and newer packages, etc. but this made packaging unhappy and the manual extract Just Worked(tm).
I noticed that the cmake generation step in my project was taking a long time and so I ran cmake through strace to figure out the root cause. I found that cmake was trying to find internal shared libraries in the wrong locations repeatedly, which was causing a lot of unnecessary file system lookups. Here is a simple project that illustrates the problem:
$ ll -R
.:
total 20K
drwxr-xr-x 2 mark mark 4.0K May 25 16:22 alpha
drwxr-xr-x 2 mark mark 4.0K May 25 16:22 beta
drwxr-xr-x 2 mark mark 4.0K May 25 16:42 build
-rw-r--r-- 1 mark mark 185 May 25 16:20 CMakeLists.txt
-rw-r--r-- 1 mark mark 0 May 25 16:16 dummy.cc
drwxr-xr-x 2 mark mark 4.0K May 25 16:22 gamma
./alpha:
total 4.0K
-rw-r--r-- 1 mark mark 0 May 25 16:16 alpha.cc
-rw-r--r-- 1 mark mark 69 May 25 16:20 CMakeLists.txt
./beta:
total 4.0K
-rw-r--r-- 1 mark mark 0 May 25 16:16 beta.cc
-rw-r--r-- 1 mark mark 67 May 25 16:18 CMakeLists.txt
./build:
total 0
./gamma:
total 4.0K
-rw-r--r-- 1 mark mark 35 May 25 16:19 CMakeLists.txt
-rw-r--r-- 1 mark mark 0 May 25 16:16 gamma.cc
alpha.cc, beta.cc, gamma.cc and dummy.cc are all empty cc files. Here are the contents of all the CMakLists.txt files:
Top level CMakeLists.txt
$ cat CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
add_subdirectory(alpha)
add_subdirectory(beta)
add_subdirectory(gamma)
add_executable(dummy_exec dummy.cc)
target_link_libraries(dummy_exec alpha)
alpha/CMakeLists.txt
$ cat alpha/CMakeLists.txt
add_library(alpha SHARED alpha.cc)
target_link_libraries(alpha beta)
beta/CMakeLists.txt
$ cat beta/CMakeLists.txt
add_library(beta SHARED beta.cc)
target_link_libraries(beta gamma)
gamma/CMakeLists.txt
$ cat gamma/CMakeLists.txt
add_library(gamma SHARED gamma.cc)
I invoke cmake (through strace) as follows:
$ cd build/
$ strace -f -o /tmp/s.out cmake ..
-- The C compiler identification is GNU 4.8.4
-- The CXX compiler identification is GNU 4.8.4
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mark/Downloads/cmake/build
When I inspect the strace output, I see it trying to access libalpha in invalid locations (such as under the beta/ and gamma/ sub directories):
31430 access("/home/mark/Downloads/cmake/build/beta/libalpha.so", R_OK) = -1 ENOENT (No such file or directory)
31430 access("/home/mark/Downloads/cmake/build/gamma/libalpha.so", R_OK) = -1 ENOENT (No such file or directory)
Similarly, it is trying to access libbeta and libgamma in invalid locations:
31430 access("/home/mark/Downloads/cmake/build/alpha/libbeta.so", R_OK) = -1 ENOENT (No such file or directory)
31430 access("/home/mark/Downloads/cmake/build/gamma/libbeta.so", R_OK) = -1 ENOENT (No such file or directory)
31430 access("/home/mark/Downloads/cmake/build/alpha/libgamma.so", R_OK) = -1 ENOENT (No such file or directory)
31430 access("/home/mark/Downloads/cmake/build/beta/libgamma.so", R_OK) = -1 ENOENT (No such file or directory)
For a large project with many shared libraries and many dependencies, these invalid lookups add up and seem to be causing big delays at the makefile generation step. Any idea on why this is happening and how I could prevent cmake from searching in these invalid paths ?
I was trying to build the Rodinia benchmark suite on my Ubuntu 12.04 Server.
I had already installed the cuda 4.0 in the /usr/local/cuda directory. I have already build the SDk samples.
On running make command to build the Rodinia benchmark suite I was getting the following errors
~/Downloads/rodinia_2.4$ make
cd cuda/cfd; make; cp euler3d euler3d_double pre_euler3d pre_euler3d_double /home/ncclab/Downloads/rodinia_2.4/bin/linux/cuda
make[1]: Entering directory `/home/ncclab/Downloads/rodinia_2.4/cuda/cfd'
nvcc -O2 -Xptxas -v --gpu-architecture=compute_20 --gpu-code=compute_20 euler3d.cu -o euler3d -I/if10/kw5na/NVIDIA_GPU_Computing_SDK4/C/common/inc -L/if10/kw5na/NVIDIA_GPU_Computing_SDK4/C/lib
euler3d.cu:5: fatal error: helper_cuda.h: No such file or directory
compilation terminated.
make[1]: *** [euler3d] Error 1
make[1]: Leaving directory `/home/ncclab/Downloads/rodinia_2.4/cuda/cfd'
cp: cannot stat `euler3d': No such file or directory
cp: cannot stat `euler3d_double': No such file or directory
cp: cannot stat `pre_euler3d': No such file or directory
cp: cannot stat `pre_euler3d_double': No such file or directory
make: *** [CUDA] Error 1
But looking into the cfd directory
ncclab#slave13:~/Downloads/rodinia_2.4$ cd cuda/cfd/ls
**euler3d.cu euler3d_double.cu Makefile Makefile_nvidia pre_euler3d.cu pre_euler3d_double.cu** README run
This is also the case with some other benchmark
cd cuda/srad/srad_v2; make; cp srad /home/ncclab/Downloads/rodinia_2.4/bin/linux/cuda/srad_v2
make[1]: Entering directory `/home/ncclab/Downloads/rodinia_2.4/cuda/srad/srad_v2'
/usr/local/cuda/bin/nvcc srad.cu -o srad -I/usr/local/cuda/include -L/usr/local/cuda/lib64
srad.cu:6: fatal error: srad.h: No such file or directory
compilation terminated.
make[1]: *** [release] Error 1
make[1]: Leaving directory `/home/ncclab/Downloads/rodinia_2.4/cuda/srad/srad_v2'
cp: cannot stat `srad': No such file or directory
make: *** [CUDA] Error 1
ncclab#slave13:~/Downloads/rodinia_2.4/cuda/srad/srad_v2$ ls
Makefile Makefile_nvidia README run srad.cu srad.h srad_kernel.cu
It clearly states the files are present in the directory. I can't understand why this error is occurring. Searching here and on google can't help me to find the cause. Can someone please help me.
What is the file helper_cuda.h contains. I cannot find it. Is it something that comes with gpu computing sdk samples. If so I was not having them. Is there any problem in its installation
Thanks in advance
Update to the latest version of CUDA (currently 5.5). You'll find the helper_*.h files in the $CUDA_PATH/samples/common/inc directory.
There version of CUDA that you have installed (CUDA 4.0) is quite old now, and the examples provided with 4.0 used a different set of helper functions in a library called cutil.