How to "include" libvlc and sdl1.2 on Raspbian C++ project? - c++

I have installed "libsdl1.2-dev" and "libvlc" (with sudo apt-get install blah) in Raspbian on my Raspberry Pi, I'm using gcc to compile the example project from https://wiki.videolan.org/LibVLC_SampleCode_SDL/
This is my compile command:
gcc -fpermissive test.cpp -lvlc -lsdl1.2-dev -o test
It seems to compile (after I added -fpermissive and manually placed the vlc headers in usr/include/vlc) the error seems to happen during the linking phase, I get these 2 errors;
/usr/bin/ld: cannot find -lvlc
/usr/bin/ld: cannot find -lsdl1.2-dev
I'm a bit new to Linux and I can't work out why it can't find them. I'm also unsure where it installs them by default, there seem to be a few different places they could be.

Use pkg-config to get the needed compile and link flags. pkg-config --cflags sdl libvlc will print the needed compilation flags, and pkg-config --libs sdl libvlc the needed link flags. You can use the $() feature of the shell to embed the output of pkg-config directly into your compile command. Also, use g++ to compile and link C++ code. gcc is for C code.
g++ $(pkg-config --cflags sdl libvlc) -fpermissive test.cpp -o test $(pkg-config --libs sdl libvlc)
The package names sdl and libvlc correspond to *.pc files that are installed in /usr/lib/pkgconfig. If no such files exist, then that means you forgot to install the -dev versions of the sdl and vlc libraries. So check if there's a libvlc-dev package you need to install. Use this:
apt-cache search vlc | grep dev
See if there's a dev package for libvlc that you need.

To install libraries and header files, try sudo apt-get install libvlc-dev this should install all the dependent libraries in the correct library paths. sudo apt-get install vlc is used to install the application which in your case you dont need.

Try sudo apt-get install vlc, you're probably missing some plugins and stuff

Related

Cpp including SDL library with GCC

Im currently trying to compile a cpp program with gcc that uses SDL2 library, and im using Ubuntu 20.04 LTS. Here is my folder structure
project
-out
-SDL2
-src
-main.cpp
Excluding the library i have uploaded everything to this repo https://github.com/probottpric/libtest if it gives a better understanding.
To install SDL2, I installed source code and ran ./configure and make all. I dont want to run make install which installs it on /usr/*. I want the library to be on the local folder.
To compile program im using this command
gcc -o ./out/main ./src/main.cpp -ISDL2 -lSDL2 -lSDL2main -lm -std=c++11
But It shows library not found error. What am i doing wrong ?

Link PCL libraries while compiling C++ programs in Linux

I am new to the Point Cloud Library. There is a thing that has been bugging me for some time.
So, on my system, whenever I have to compile a C++ program, which requires OpenCV libraries to be linked, I use the following terminal command:
g++ -std=c++11 fileName.cpp -o executableFile `pkg-config --cflags --libs opencv`
Now, things have turned to a point where I have to use PCL. But, everywhere (including the PCL's official website) people link PCL libraries using a CMake file, and I am not familiar with CMake.
Is there a way to include the PCL libraries without writing a CMake file and just including some more flags/parameters to the terminal command?
I am using Ubuntu 18.04.
I experimented for a while, and here is how I figured this out.
man pkg-config tells you the folders where pkg-config looks for .pc files. So, I checked those folders for the exact .pc file names that I want pkg-config to link with my .cpp file. I found the required file (pcl_io-1.11.pc) at \usr\local\lib\pkgconfig
Next, I modified my terminal command to the following (please consider two back-quotes as a single back-quote below)
g++ -std=c++14 pcd_write.cpp -o pcd_write ``pkg-config --cflags --libs pcl_io-1.11`` -lboost_system
Note: Not including the -lboost_system would result in another error message. I found this helpful.
This compiled successfully. But, on running the executable, I would get this error message:
./pcd_write:error while loading shared libraries:libpcl_io.so.1.11:cannot open shared object file:No such file or directory
The solution to this problem was found here
sudo /sbin/ldconfig -v
Then, running the executable gave the expected results.

Missing "libiconv.h" when crosscompiling for Windows with mingw on Ubuntu

I have been working on a program in SDL and I would like to send it to my friends who only run a Windows environment. I have done some reading and found that I should use mingw to cross-compile for Windows. The binary I found and compiled was x86_64-w64-mingw32-g++, however I am getting some issues getting my program to compile. Using the following command I get the following error:
/usr/bin/x86_64-w64-mingw32-g++ sapphire.cpp `pkg-config --cflags --libs sdl2` -lSDL2_image -lSDL2_mixer -lSDL2_ttf -std=c++11
fatal error: iconv.h: No such file or directory
While I realize I should make a makefile eventually, I am not going to do that now.
I tried installing iconv (Version 1.15) from here and used the following commands to compile it:
./configure --prefix=/usr/local
make
make all
My iconv.h is located in /usr/include but if I include that I get another error for missing gnu/stubs.h and if I include that then I get a myriad of errors that I'm not sure how/if I could fix seen here. Does anyone know how I could perhaps fix this? I would appreciate any help!
Thanks in advance!
You can use pkg-config with mingw in a crosscompiler environment but you should take care to where pkg-config searches for his .pc files.
I'm assuming your mingw crosscompiler is installed in /usr/x86_64-w64-mingw32, change it to the installation path where his "include" and "lib" subdirectories are.
Provided SDL windows developement package is installed in the same prefix on your computer and the installation has a correct pkg-config .pc file you can do:
export PKG_CONFIG_PATH=/usr/x86_64-w64-mingw32/lib/pkgconfig
and then try pkg-config from the command line:
pkg-config sdl2 --cflags
This should point you to some path inside /usr/x86_64-w64-mingw32, if it does your compilation will be successful.
Please note that if you want to compile a package for crosscompile (like the iconv you tried to compile) you should add to the ./configure script parameters:
--host=x86_64-w64-mingw32 --prefix=/usr/xx86_64-w64-mingw32
... and this may work or not, depending the package support the mingw32 compiler or not.
The way you compiled iconv built another linux version of it in /usr/local!
NOTE: As far as I know Ubuntu does not provide a windows package for SDL2, while other linux distro do, so you'll need to cross-compile SDL2 with the option I gave before you can compile your code. SDL2 does support cross-compilation using mingw.

Can't use static lib of mongo-cxx-driver on Linux

So I follow the official tutorial for the installation : https://mongodb.github.io/mongo-cxx-driver/mongocxx-v3/installation/
Neverless, I can't use the produced libraries as static.
So I managed to compile the C version of the driver as described, I've enabled the flag --enable-static=yes with the ./configure before doing make && sudo make install and I got the libmongoc-1.0.a and the libbson-1.0.a which are static. So this far, everything it's alright.
Then I have done the cxx version of the driver, except that there is no configuration file as in the C version. So I've juste done a
cmake -DCMAKE_BUILD_TYPE=Release -DBSONCXX_POLY_USE_BOOST=1 -DCMAKE_INSTALL_PREFIX=/usr/local
from the build folder, followed by a make && sudo make install
So I got the libmongocxx.a and the libbsoncxx.a, but when I try to compile with them, I can't run the binary because I got the following error :
error while loading shared libraries: libmongocxx.so._noabi: cannot open shared object file: No such file or directory
So I understand that is because there is some symbols missing and then I need to use the shared library to run the binary but I don't want this to happend, I want the symbols within the binary that I can run it without any LD_PRELOAD.
Any suggestions ?
I had the same issue in an Ubuntu 16.04 and I run a apt-get update & apt-get upgrade and the problem was solved.
It seems that there were some update to the compiler and some libraries that prevent some test from reaching the shared libraries.
I have a similar question, and solved, now I compiled and run my binary with static libs successfully.
I write my build script using newlisp, but the static link options are very helpful, I paste it here.
c++ /to/your/path/site/code/back_end/builder/object/files1.cc.o ... /to/your/path/site/code/back_end/builder/object/files10.cc.o -o bin/site -static-libgcc -static-libstdc++ -L/usr/lib -lpthread -l:libmongocxx.a -l:libbsoncxx.a -l:libmongoc-1.0.a -l:libbson-1.0.a -lrt -lssl -lcrypto -lsasl2 -l:libboost_log.a -l:libboost_log_setup.a -l:libboost_system.a -l:libboost_thread.a -l:libboost_filesystem.a -lcppcms -lbooster -lcurl -ljsoncpp

Linking boost::asio using terminal

I am trying to link boost::asio using terminal (I'm also using a text editor).
What I tried
I did some researches on Internet (I didn't found nothing about my distro) - I found I must install that library by executing the following command on the terminal:
sudo pacman -S libboost-all-dev
This is the output I get:
error: the following package was not found: libboost-all-dev
Final question
How can I install and link correctly boost::asio with my .cpp file?
Notes:
I'm using Archlinux
To find a package in Arch Linux, do:
sudo pacman -Ss boost
This will list packages with the string boost. Or, you can look up on the package website: https://www.archlinux.org/packages/extra/x86_64/boost/
One thing you should understand about boost is that a majority of its modules are header-only; if the linker complains about undefined references then you would have to link the required files. To link boost-asio, you would do
g++ -lboost-system <source> <exe>
How to install boost in Arch Linux
You cannot link libraries inside your *.cpp files. You should enumerate required libraries using the -l option in the g++ command line.
g++ -lboos-asio -lboost-system myfile.cpp -o myapp