libtorrent-rasterbar7: g++ linker unable to find libtorrent/session.hpp - c++

When compiling the libtorrent tutorial 'hello world' with:
g++ main.cpp -o run -ltorrent-rasterbar -lboost_filesystem-mt -L /usr/lib/
=> fatal error: libtorrent/session.hpp: No such file or directory
Despite having libtorrent-rasterbar7 installed (both libtorrent-rasterbar.so.7 and libtorrent-rasterbar.so.7.0.0 exist in /usr/lib/). Also I'm able to run a simple python script that imports and uses libtorrent without issues.
The g++ command I'm using is identical to the solution for a similar issue with version 6 yet still having the error.

You haven't installed the libtorrent-rasterbar header files. The
package you are missing is the libtorrent-rasterbar development
package. What it is called depends on your distro. (On Debian or Ubuntu
it is libtorrent-rasterbar-dev. On Fedora it is libtorrent-rasterbar-devel).
Whenever you want to write an application that links with a packaged library
you need to install not simply the runtime library but the associated development
package, which provides both the runtime library and its header files.
BTW, there is no need to pass -L /usr/lib to the linker as /usr/lib is one of the default linker search directories.

Related

MinGW undefined reference libcurl

So i have written an app in c++ to download mp3s from the web using a list.
It uses libcurl to download them.
I am on linux. Compiling with
g++ main.cpp -lcurl -o word2mp3
works fine.
I need an windows executable, but running
x86_64-w64-mingw32-g++ main.cpp -o wordtest returns the
undefined reference to `__imp_curl_easy_init'
followed by the other curl functions. Adding -lcurl to the command also gives an error saying that curl isn't found.
I've tried and searched everywhere, no luck, I'm a beginner.
Link to my github repo: https://github.com/sharpclone/Word2Mp3
You need to compile libcurl with MinGW, or find a precompiled one. The one you installed to compile your app on Linux was compiled with a Linux compiler, and wouldn't work with MinGW.
MSYS2 repos have a bunch of precompiled libraries for different flavors of MinGW.
I've made a script to automatically download those libraries, since their package manager only works on Windows.
git clone https://github.com/holyblackcat/quasi-msys2
cd quasi-msys2
make install _gcc _curl
env/shell.sh
cd ..
git clone https://github.com/sharpclone/Word2Mp3
cd Word2Mp3/
win-clang++ main.cpp -lcurl -o word2mp3
This doesn't rely on an external MinGW installation, and only requires Clang (and LLD) to be installed (a regular Clang for Linux, unlike GCC you don't need to install a special version of it to cross-compile).
Or, if you prefer your existing compiler, you can stop at make install _curl, then manually specify the path to the installed library, normally -Lquasi-msys2/root/mingw64/lib. You just need to make sure the MSYS2 repo you're using matches your compiler.
To fix the undefined reference warning, you need to link to the required library, so the -lcurl is correct and required.
If the compiler cannot find the library, you need to tell him where to find it, that can be done by passing -L followed by the path to the library (that would be the path to the directory where libcurl.dll.a is in).
The order of the parameters can also be relevant, I think the correct order would be -L <path> -lcurl.

"Error while loading shared libraries" raised when linking boost library, except I cannot use root access to fix it

I am trying to run some code on my school's super computer, running on Ubuntu.
That code happens to require the timer library in boost.
So I uploaded the boost 1.71.0 repository, built it succesfully.
Then I built it with the following command (successfully)
g++ -g src/foo.cpp -o run/foo -I ../boost_1_71_0/ -L ../boost_1_71_0/stage/lib/ -lboost_timer -fopenmp -std=c++11
Then when I try to run the file, this happens:
Error while loading shared libraries: libboost_timer.so.1.71.0: cannot open shared object file: No such file or directory
I scrolled through several forum discussions, and apparently running the following command should update the library path and fix everything:
sudo /sbin/ldconfig -v
But since I have no root access, I cannot run it.
I'm looking for a workaround that doesn't involve any sudoing.
You can run your program by ensuring ../boost_1_71_0/stage/lib/ is in LD_LIBRARY_PATH so the dynamic loader knows where to search for the Boost shared libraries. Run your program as follows, assuming the Boost libraries are located at ../boost_1_71_0/stage/lib/ relative from the directory where your program is located on disk.
LD_LIBRARY_PATH=../boost_1_71_0/stage/lib/ ./program

How can I compile ndpiReader.c that comes with nDPI library in Windows?

I want to create a .exe of ndpiReader.c demo program that comes with nDPI library. I was successful to compile it on Ubuntu using commands specified on their github page as bellow:
./autogen.sh
./configure
make
I have tried to cross compile it using GCC inside Ubuntu but I wasn't successful. I also tried to use the pcapExample.sln to compile it in Visual Studio 2012, but I keep getting error messages like:
Error 29 error C1083: Cannot open include file: 'ndpi_api.h': No such file or directory
Although ndpi_api.h and all other files that I get this error for already are listed in the project solution explorer.
Has anyone actually been able to make a win32 executable out of this ndpiReader.c file? If yes, please specify the steps, requirements, or a link.
nDPI lib is hosted here: https://github.com/ntop/nDPI
ndpiReader.c is hosted here: https://github.com/ntop/nDPI/tree/dev/example
pcapExample.sln is hosted here: https://github.com/ntop/nDPI/tree/dev/example/Win32
I saw from your other questions that you had already tried to compile this with CYGWIN and ran into a number of problems.
Here’s a step-by-step guide I just used to compile nDPI (including the ndpiReader.exe example):
Install CYGWIN:
Accept the default directories, and pick a mirror.
At the Select Packages step, expand the Devel category, and select the following developer packages to install:
autoconf
autoconf2.5
automake
automake1.15
binutils
cmake
cygwin-devel
gcc-core
gcc-tools-epoch2-autoconf
gcc-tools-epoch2-automake
libtool
make
pkg-config
w32api-headers
w32api-runtime
Install libpcap under CYGWIN:
Download and unpack the Winpcap Developer's pack.
Copy libpacket.a and libwpcap.a from WpdPack\Lib\ to cygwin\lib\
In cygwin\lib, copy libwpcap.a to libpcap.a
In cygwin\usr\include, create a pcap directory
Copy all headers from WpdPack\Include to cygwin\usr\include\pcap
I'm sure you've installed winpcap already as part of everything else you've tried, but double-check that the necessary (packet.dll and wpcap.dll) libraries are already in cygwin\c\WINDOWS\system32.
Now you've got all the necessary tools and libraries to compile nDPI on Windows!
Building nDPI
Download and unpack nDPI again in a clean directory, so you don't get tripped up by any issues from the previous build you tried.
Open a CYGWIN terminal, and cd into the nDPI directory.
Run autogen.sh
./autogen.sh
This should complete without any errors.
If it stops with "somepackage is missing: please install it and try again," you've missed installing a CYGWIN package that is needed to build the source.
If it stops with "Missing libpcap(-dev) library," double-check the previous steps you did to copy libpcap.a in cygwin\lib.
autogen.sh should start running the configure stage for you. (If it doesn't, or part of this stage fails, you can rerun configure after fixing any issue.)
./configure
After checking for a number of things, configure will end by creating a Makefile.
Build the nDPI library, by running make.
make
It will build the library, then try to build the examples, but fail because it can't find pcap.h
cd into the example directory, and manually compile ndpiReader.c by adding -I/usr/include/pcap to the command:
cd example/
gcc -DHAVE_CONFIG_H -I. -I.. -I../src/include -I/usr/include/pcap -g -O2 -c -o ndpiReader.o ndpiReader.c
I included my command as an example. If your compiler command is slightly different, just add -I/usr/include/pcap to what your Makefile had invoked.
Leave the example directory, and resume the make.
cd ..
make
This last step will link ndpiReader with the ndpi library, and create the executable you're looking for.

Including and using libraries with autotools

I am an autotools newbie; I'm doing an application that needs to parse xml files, using xerces-c 3.1.
My code works fine when I install the xerces-c library with the apt-get utility (then xerces-c libraries and include files are installed in /usr/lib and /usr/include/xercesc, respectively). In my configure.ac file I have the following macro:
AC_CHECK_LIB([xerces-c],[main],[],[AC_MSG_ERROR([*** xerces-c lib not found])])
OK, as I said, this works as expected. However, I want to have the libraries inside the project directory (to be included in the distribution package), and here my problems begin.
I uninstall the xerces-c libraries, and I copy the xerces-c libraries (downloaded from the xerces-c webpage) to my project directory. Then, I add the to my confgure.ac the macro:
LDFLAGS="$LDFLAGS -L/home/xxxx/workspace/P3/src/lib"
Finally, I generate the makefiles and compile, just executing the following commands in the project root directory:
autoconf
automake
./configure
make
The compilation looks good, and the linking looks fine too:
g++ -g -O2 -L/home/xxxx/workspace/P3/src/lib -o app app-P3.o -lxerces-c
But when I execute the application I got an error like:
./src/app: error while loading shared libraries: libxerces-c-3.1.so: cannot open shared object file: No such file or directory
What I'm doing wrong?
Thanks in advance.
Since you are using a shared library libxerces-c-3.1.so needs to be somewhere where it can be found by ld. In the previous case where you installed the xerces-c package, libxerces was installed in /usr/lib or somewhere where it could be found. You can probably get it working for now by:
LD_LIBRARY_PATH=$PATH:/home/xxxx/workspace/P3/src/lib ./src/app
but this is something that you'll have to figure out eventually for your package install.

Getting started with the Halide programming language?

I'm trying to get started with a domain-specific language (C++ extension) for image processing called Halide.
Following the Halide README, here's what I've tried:
Downloaded the Ubuntu 12.04 Halide binary, and extracted in a directory called ~/halide.
In the ~/halide directory, I created hello_halide.cpp, as described in the Using Halide section of this page.
Tried to compile hello_halide.cpp:
g++-4.6 -std=c++0x hello_halide.cpp -L halide -lHalide -ldl -lpthread -o hello_halide
But, g++ can't find libhalide:
/usr/bin/ld: error: cannot find -lHalide
Tried adding ~/halide to my $PATH and $LD_LIBRARY_PATH, but this didn't help.
How can I compile this basic hello_halide.cpp Halide program?
Notes:
CUDA is one of Halide's dependencies. I have CUDA installed, and I can compile/run CUDA programs.
I'm using Ubuntu 12.04.
My g++ version is 4.6.3.
-L halide tells the linker to look for the library in the subdirectory halide. In this case that means that your source file hello_halide.cpp should be in a folder ~/myfolder/, and the library libHalide.so at ~/myfolder/halide/libHalide.so (or .a if it's static). If it's somewhere else, pass an absolute path to -L.
Your idea of setting LD_LIBRARY_PATH or PATH does not work since the latter is for directories that will be searched for executables and the former is for directories that will be searched for shared libraries when you launch an executable that needs shared libraries.