Package 'libmongoc-1.0', required by 'libmongocxx', not found - c++

I am trying to get the libmongocxx to run on Debian Jessie 64bit after compiling it according to the :
quickstartguide
I added the path the find command returned as the location for the libmongoc-1.0.pc file the compiler is complaining missing:
$: sudo find / -name "libmongoc-1.0.pc"
/opt/mongo-c-driver/src/libmongoc-1.0.pc
/opt/mongo-c/lib/pkgconfig/libmongoc-1.0.pc
I try to set the dependency specific in the pkg path declaration:
PKG_CONFIG_PATH=/opt/mongo-c/lib/pkgconfig c++ --std=c++11 main.cpp - o hellomongo $(pkg-config --cflags --libs libmongocxx)
But I keep getting this error given xx different tries:
Package libmongoc-1.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libmongoc-1.0.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libmongoc-1.0', required by 'libmongocxx', not found
c++: error: main.cpp: No such file or directory
c++: fatal error: no input files
compilation terminated.
I hope somebody can enligthen me.

Related

how to add pinocchio (a robotics package) as library in cmake

I have to include pinocchio (an open-source library for robotics) in a c++ project via cmake, but it fails currently. (https://github.com/stack-of-tasks/pinocchio)
I've installed pinocchio c++ without the python bindings via
sudo apt install -qqy robotpkg-pinocchio
I've tried out the simple examples from the documentation https://gepettoweb.laas.fr/doc/stack-of-tasks/pinocchio/master/doxygen-html/index.html#OverviewComplex
If I compile it like this with the source code from the simplest example, it works:
g++ -std=c++11 overview-simple.cpp -o overview-simple $(pkg-config --cflags --libs pinocchio)
For including Pinocchio in a separate c++ project, I've tried the following things:
finding it as a package like this:
find_package(pinocchio 2.6.10)
but it fails with this message:
By not providing "FindPinocchio.cmake" in CMAKE_MODULE_PATH this project
has asked CMake to find a package configuration file provided by
"Pinocchio", but CMake did not find one.
Could not find a package configuration file provided by "Pinocchio"
(requested version 2.6.10) with any of the following names:
PinocchioConfig.cmake
pinocchio-config.cmake
Add the installation prefix of "Pinocchio" to CMAKE_PREFIX_PATH or set
"Pinocchio_DIR" to a directory containing one of the above files. If
"Pinocchio" provides a separate development package or SDK, be sure it has
been installed.
Can I somehow specify the path of the installed pinocchio library in the cmake file?
adding the compile options/flags just like in the example from the documentation
target_compile_options(${PROJECT_NAME} PUBLIC $(pkg-config --cflags --libs pinocchio))
but that also throws an error message. If it helps pkg-config --cflags --libs pinocchio, gives the following:
-DPINOCCHIO_WITH_URDFDOM -DPINOCCHIO_WITH_HPP_FCL -DHPP_FCL_HAS_OCTOMAP -DHPP_FCL_HAVE_OCTOMAP -DFCL_HAVE_OCTOMAP -DOCTOMAP_MAJOR_VERSION=1 -DOCTOMAP_MINOR_VERSION=9 -DOCTOMAP_PATCH_VERSION=7 -I/opt/openrobots/lib/pkgconfig/../../include -I/opt/openrobots/include -I/usr/local/include/eigen3 -I/usr/lib/x86_64-linux-gnu/pkgconfig/../../../include -L/opt/openrobots/lib/pkgconfig/../../lib -L/opt/openrobots/lib -L/usr/lib/x86_64-linux-gnu/pkgconfig/../../../lib/x86_64-linux-gnu -Wl,-rpath,/opt/openrobots/lib/pkgconfig/../../lib -lpinocchio -Wl,-rpath,/usr/lib/x86_64-linux-gnu -lboost_filesystem -lboost_serialization -lboost_system -lurdfdom_sensor -lurdfdom_model_state -lurdfdom_model -lurdfdom_world -lconsole_bridge -Wl,-rpath,/opt/openrobots/lib -lhpp-fcl -loctomap -loctomath
Thank you very much!
From the pinocchio website pinocchio:
Configure environment variables
All the packages will be installed in the /opt/openrobots directory. To make use of installed libraries and programs, you must need to configure your PATH, PKG_CONFIG_PATH, PYTHONPATH and other similar environment variables to point inside this directory. For instance:
export PATH=/opt/openrobots/bin:$PATH
export PKG_CONFIG_PATH=/opt/openrobots/lib/pkgconfig:$PKG_CONFIG_PATH
export LD_LIBRARY_PATH=/opt/openrobots/lib:$LD_LIBRARY_PATH
export PYTHONPATH=/opt/openrobots/lib/python2.7/site-packages:$PYTHONPATH # Adapt your desired python version here
export CMAKE_PREFIX_PATH=/opt/openrobots:$CMAKE_PREFIX_PATH
So try setting CMake environnement variable called CMAKE_PREFIX_PATH or use -D flag during cmake invocation:
cmake -D CMAKE_PREFIX_PATH=/usr/local/lib <path to source or build dir>
It specifies the path which will be used by the FIND command

How do I install and use PNGwriter to write PNG image files?

I'd like to learn how to write PNG images pixel-by-pixel using both RGB and HSV color models with C++. I read that this should be fairly easy using PNGwriter (https://github.com/pngwriter/pngwriter), but I've spent many hours struggling with installing it (on Ubuntu) and compiling my code with it. Any help would be much appreciated.
Disclaimer: I have a weird background in the sense that I have many years of experience in using Unix-like operating systems, doing stuff in the terminal, and writing code, but I know little/nothing about installing software from the source code or compiling programs manually or with makefiles from multiple source code files.
The installation instructions on GitHub advise to do one of the following:
Spack:
spack install pngwriter
spack load pngwriter
From Source:
First install the dependencies zlib, libpng, and (optional for text support) freetype. PNGwriter >can then be installed using CMake:
git clone https://github.com/pngwriter/pngwriter.git
mkdir -p pngwriter-build
cd pngwriter-build
# for own install prefix append: -DCMAKE_INSTALL_PREFIX=$HOME/somepath
cmake ../pngwriter
make -j
# optional
make test
# sudo is only required for system paths
sudo make install
I managed to install Spack and then PNGwriter, but couldn't compile the simplest program with it and wasn't able to figure out why. I then installed PNGwriter manually, but still couldn't compile anything with it. This was many hours of struggling ago so I, unfortunately, don't remember what kind of errors or problems I was encountering at this point.
The instructions on GitHub say the following about linking:
First set the following environment hint if PNGwriter was not installed in a system path:
# optional: only needed if installed outside of system paths
export CMAKE_PREFIX_PATH=$HOME/somepath:$CMAKE_PREFIX_PATH
Use the following lines in your projects CMakeLists.txt:
find_package(PNGwriter 0.7.0)
if(PNGwriter_FOUND)
target_link_libraries(YourTarget PRIVATE PNGwriter::PNGwriter)
endif(PNGwriter_FOUND)
Questions: How do I know if PNGwriter was or wasn't installed in a system path? I have libPNGwriter.a in /usr/local/lib and pngwriter.h in /usr/local/include --- does this mean that it was installed in a system path? When installing I simply tried to follow the instructions above. Do I just type the environment hint to the terminal or add it to some file? If the former then does it need to be given every time I open a new terminal session? Is "somepath" /usr/local/lib, /usr/local/include or something else?
Questions: Does the second part regarding "CMakeLists.txt" depend on whether PNGwriter was installed in a system path? What is "CMakeLists.txt"? I assume it's some file one's IDE creates, but my NetBeans projects don't seem to contain such files. What if I have a single source file and compile it manually in the terminal?
Now, let's say I'd like to compile the PNGwriter quickstart example:
#include <pngwriter.h>
int main()
{
int i;
int y;
pngwriter png(300, 300, 0, "test.png");
for(i = 1; i ≤ 300; i++)
{
y = 150 + 100*sin((double)i*9/300.0);
png.plot(i, y, 0.0, 0.0, 1.0);
}
png.close();
return 0;
}
The PNGwriter manual instructs to compile as
g++ myprogram.cc -o my_program `freetype-config --cflags` -I/usr/local/include -L/usr/local/lib -lpng -lpngwriter -lz -lfreetype
but I get errors
$ g++ example.cpp -o example `freetype-config --cflags` -I/usr/local/include -L/usr/local/lib -lpng -lpngwriter -lz -lfreetype
Package freetype2 was not found in the pkg-config search path.
Perhaps you should add the directory containing `freetype2.pc'
to the PKG_CONFIG_PATH environment variable
Package 'freetype2', required by 'virtual:world', not found
Package freetype2 was not found in the pkg-config search path.
Perhaps you should add the directory containing `freetype2.pc'
to the PKG_CONFIG_PATH environment variable
Package 'freetype2', required by 'virtual:world', not found
Package freetype2 was not found in the pkg-config search path.
Perhaps you should add the directory containing `freetype2.pc'
to the PKG_CONFIG_PATH environment variable
Package 'freetype2', required by 'virtual:world', not found
Package freetype2 was not found in the pkg-config search path.
Perhaps you should add the directory containing `freetype2.pc'
to the PKG_CONFIG_PATH environment variable
Package 'freetype2', required by 'virtual:world', not found
sed: -e expression #1, char 0: no previous regular expression
sed: -e expression #1, char 0: no previous regular expression
In file included from example.cpp:1:0:
/usr/local/include/pngwriter.h:66:22: fatal error: ft2build.h: No such file or directory
compilation terminated.
The answer to this Stack Overflow question (Trying to install pygame on ubuntu which gives error) suggests to install libfreetype6-dev, but I apparently have the latest version already whereby the errors remain unchanged. If I instead actually add the directory containing freetype2.pc (I found it by going to / and using find -name "freetype2.pc") to the environment variable (added export PKG_CONFIG_PATH="/usr/lib/x86_64-linux-gnu/pkgconfig/:$PKG_CONFIG_PATH to ~/.bashrc and did source ~/.bashrc) then I get new errors
$ g++ example.cpp -o example `freetype-config --cflags` -I/usr/local/include -L/usr/local/lib -lpng -lpngwriter -lz -lfreetype
/usr/bin/ld: cannot find -lpngwriter
collect2: error: ld returned 1 exit status
Here I figured out that I needed to replace -lpngwriter with -lPNGwriter (i.e., the manual is erroneous). Then I get:
$ g++ example.cpp -o example `freetype-config --cflags` -I/usr/local/include -L/usr/local/lib -lpng -lPNGwriter -lz -lfreetype
/usr/bin/ld: /usr/local/lib/libPNGwriter.a(pngwriter.cc.o): undefined reference to symbol 'png_set_sig_bytes##PNG12_0'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
This is where I'm currently stuck. I can't seem to find a solution by googling (at least one that I'd understand).
Question: How do I get this working? How do I get it working in NetBeans? Do I get these problems because I effed up the linking step above?
Edit1: As per john's comment, I tried swapping -lpng and -lPNGwriter and I again get new errors:
$ g++ example.cpp -o example `freetype-config --cflags` -I/usr/local/include -L/usr/local/lib -lPNGwriter -lpng -lz -lfreetype
/usr/local/lib/libPNGwriter.a(pngwriter.cc.o): In function `pngwriter::close()':
pngwriter.cc:(.text+0x41c2): undefined reference to `png_convert_to_rfc1123_buffer'
/usr/local/lib/libPNGwriter.a(pngwriter.cc.o): In function `pngwriter::read_png_info(_IO_FILE*, png_struct_def**, png_info_def**)':
pngwriter.cc:(.text+0x4fdf): undefined reference to `png_set_longjmp_fn'
collect2: error: ld returned 1 exit status
I'm still left clueless.
Thanks to john, I think I got it figured out. My guess is that the installation from the source (after the Spack installation) messed things up somehow. I reinstalled PNGwriter using Spack and, now apparently having all the pieces for the compilation command, was finally able to compile the example code.
Summary:
Source Spack
# For bash/zsh/sh
$ . spack/share/spack/setup-env.sh
# For tcsh/csh
$ source spack/share/spack/setup-env.csh
# For fish
$ . spack/share/spack/setup-env.fish
Install using Spack (skip if already installed)
spack install pngwriter
Load PNGwriter (I guess one needs to do this in every new terminal session)
spack load pngwriter
Compile (note that this isn't quite what the PNGwriter manual suggests)
g++ example.cpp -o example `freetype-config --cflags` -I/usr/local/include -L/usr/local/lib -lPNGwriter -lpng -lz -lfreetype

Linking Paho C Mqtt library error in C++ Project

I'm trying to include the MQTT-C-Client-Library in a simple C++ project.
I have included the header file succesfully like this #include "MQTTClient.h". Compiling it in the linux terminal was printing this errors:
[xy#localhost mosquittoProject]$ sudo g++ *.cpp -o MQTTTest
/tmp/ccHn3s6m.o: In function `main':
mosquitto_test.cpp:(.text+0x11e): undefined reference to `MQTTClient_create'
mosquitto_test.cpp:(.text+0x13f): undefined reference to `MQTTClient_connect'
collect2: error: ld returned 1 exit status
I figured out that I need to link the library after some googling: Example MQTT Client Code not working C
Based on this question and answer I tried compiling it again like this:
sudo g++ -L/home/xy/Desktop/paho.mqtt.c/build/output/ *.cpp -l paho-mqtt3c -o MQTTTest
Which compiles fine but when running I get still an error.
Console commands and output:
[xy#localhost mosquittoProject]$ sudo g++ -L/home/xy/Desktop/paho.mqtt.c/build/output/ *.cpp -l paho-mqtt3c -o MQTTTest
[xy#localhost mosquittoProject]$ ./MQTTTest
./MQTTTest: error while loading shared libraries: libpaho-mqtt3c.so.1: cannot open shared object file: No such file or directory
I replaced the actual username by xy in this post.
What am I doing wrong here?
The problem looks like the library (libpaho-mqtt3c.so.1) is not on the library path.
It looks like you are linking against the build location of the library and have not installed it to the default system location (e.g. /usr/local/lib) by running sudo make install.
By default on Linux the runtime linker searches the locations listed in /etc/ld.so.conf and /etc/ld.so.conf.d. if you edit these remember to run sudo ldconfig to update the cache.
You can add the location of the library to the LD_LIBRARY_PATH environment variable e.g.:
$ LD_LIBRARY_PATH=/home/xy/Desktop/paho.mqtt.c/build/output/ ./MQTTTest

Eclipse 3.8 won't see gtkmm.h

I'm quite new to C++ and I aspire to learn gtkmm. I'm using linux mint 17.2 and Eclipse 3.8. When I enter:#include <gtkmm.h> the compiler will complain and give this error:
fatal error: gtkmm.h: No such file or directory
I've used synaptic and installed libgtkmm-3.0-dev and when I search for the header file locate gtkmm.h I get back the following path:
/usr/include/gtkmm-3.0/gtkmm.h
So, now if enter to eclipse #include gtkmm-3.0/gtkmm.h I get a new error: fatal error: glibmm.h: No such file or directory
locate glibmm.h
shows me this path: /usr/include/glibmm-2.4/glibmm.h.
So if I enter again: #include <glibmm-2.4/glibmm.h>
I get back the same error. fatal error: glibmm.h: No such file or directory
So what am I missing here ?
OK I think I got it. in
Project->Properties -> C/C++ Build -> Settings ->GCC C++ Compiler-> Miscellaneous
you add
`pkg-config --cflags gtkmm-3.0`
in other flags.
In GCC/C++ Linker on Miscellaneous section you add `pkg-config --libs gtkmm-3.0` in other flags.
Now is GCC C++ Compiler again, on command line pattern you move the ${FLAGS} to the end.
It's working so far here.

Package gtkglext-1.2.0 was not found in the pkg-config search path

I am trying to write an application using c++. I have decided to use gtk3+ and the gtk opengl extensions. Bellow is the build command i am running
gcc -Wall `pkg-config --cflags "gtk+-3.0 gtkglext-1.2.0"` -c -o main.o main.c
This creates the bellow output error
Package gtkglext-1.2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtkglext-1.2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gtkglext-1.2.0' found
If instead of using gtkglext-1.2.0 i use gtkglext-1.0 then this causes alot of compiler warnings.
How can i setup pkg-config properly?
Note: I have brew installed gtk3+ and gtkglext
UPDATE:
howbrew has installed gtkglext-1.2.0 but there is only gtkglext-1.0.pc & gtkglext-x11-1.0.pc available. Bellow is the new build command
gcc -Wall `pkg-config --cflags "gtk+-3.0 gtkglext-1.0 gtkglext-x11-1.0"` -c -o main.o main.c
This causes lots of compile errors, bellow is a sample
In file included from main.c:9: In file included from
/usr/local/Cellar/gtkglext/1.2.0/include/gtkglext-1.0/gtk/gtkgl.h:22:
In file included from
/usr/local/Cellar/gtkglext/1.2.0/include/gtkglext-1.0/gdk/gdkgl.h:34:
In file included from
/usr/local/Cellar/gtkglext/1.2.0/include/gtkglext-1.0/gdk/gdkglpixmap.h:25:
In file included from
/usr/local/Cellar/gtk+/2.24.25/include/gtk-2.0/gdk/gdkpixmap.h:35: In
file included from
/usr/local/Cellar/gtk+/2.24.25/include/gtk-2.0/gdk/gdkdrawable.h:35:
/usr/local/Cellar/gtk+/2.24.25/include/gtk-2.0/gdk/gdkgc.h:198:23:
error: a parameter list without
types is only allowed in a function definition GdkColormap *GSEAL (colormap);
^ /usr/local/Cellar/gtk+/2.24.25/include/gtk-2.0/gdk/gdkgc.h:198:16:
error: duplicate member 'GSEAL' GdkColormap *GSEAL (colormap);
^ /usr/local/Cellar/gtk+/2.24.25/include/gtk-2.0/gdk/gdkgc.h:193:8:
note: previous declaration is here gint GSEAL (clip_x_origin);
^ /usr/local/Cellar/gtk+/2.24.25/include/gtk-2.0/gdk/gdkgc.h:205:27:
error: unknown type name 'GdkGC' void (*get_values) (GdkGC
*gc,
^ /usr/local/Cellar/gtk+/2.24.25/include/gtk-2.0/gdk/gdkgc.h:207:27:
error: unknown type name 'GdkGC' void (*set_values) (GdkGC
*gc,
^ /usr/local/Cellar/gtk+/2.24.25/include/gtk-2.0/gdk/gdkgc.h:210:27:
error: unknown type name 'GdkGC' void (*set_dashes) (GdkGC
*gc,
^ /usr/local/Cellar/gtk+/2.24.25/include/gtk-2.0/gdk/gdkgc.h:225:1:
error: unknown type name 'GdkGC' GdkGC *gdk_gc_new
(GdkDrawable *drawable);
Brew is OSX, right? I don't know much about OSX dev, but in general the pkg-config files get dumped in $prefix/lib/pkgconfig, where prefix depends on what you passed to the configure script, cmake, our whatever underlying build system the package in question uses. Either you can reinstall with a different prefix option or you can modify the PKG_CONFIG_PATH environment variable when building your app like this:
PKG_CONFIG_PATH=$prefix/lib/pkgconfig:$ PKG_CONFIG_PATH gcc command here
Which prepends the correct location of the pkg-config files to PKG_CONFIG_PATH. Where these are I can't tell you, as I know not brew and OSX, but once you find it you're golden. The files should be named gtk+-3.0.pc and gtkglext-1.2.0.pc respectively.