Really basic about C++/Boost - testing boost - c++

I think I have boost installed properly so I am trying to use the test "first.cpp" found here:
#include<iostream>
#include<boost/any.hpp>
int main()
{
boost::any a(5);
a = 7.67;
std::cout<<boost::any_cast<double>(a)<<std::endl;
}
And I get the following:
Jason#ITHAKA-DB44CFE1 /home/jason
$ g++ -o first first.cpp
first.cpp:2:24: boost/any.hpp: No such file or directory
first.cpp: In function `int main()':
first.cpp:6: error: `boost' has not been declared
first.cpp:6: error: `any' undeclared (first use this function)
first.cpp:6: error: (Each undeclared identifier is reported only once for each
unction it appears in.)
first.cpp:6: error: expected `;' before "a"
first.cpp:7: error: `a' undeclared (first use this function)
first.cpp:8: error: `boost' has not been declared
first.cpp:8: error: `any_cast' undeclared (first use this function)
first.cpp:8: error: expected primary-expression before "double"
first.cpp:8: error: expected `;' before "double"
first.cpp:9:2: warning: no newline at end of file
Jason#ITHAKA-DB44CFE1 /home/jason
$
Where my boost library is in my ./home/Jason/
Obviously something is up. Also, all the boost libraries themselves use this "boost/..." so for some reason either:
1 - I did something wrong with Boost
2 - C++/gcc is not "seeing" my boost
any input?

You need to pass -I/home/Jason/include to gcc, and probably a -L/home/Jason/lib too, because the library is not installed in the standard path. Try:
g++ -I/home/Jason/include -L/home/Jason/lib -o first first.cpp
Also, once compiled, it will not run properly because the libraries are not in the standard path again. To run it, you need to add /home/Jason/lib to the environment variable LD_LIBRARY_PATH.
Edit: As Tony D pointed out, you can set CPLUS_INCLUDE_PATH to /home/Jason/include instead, which is equivalent to the compiler option I gave you.
Edit
If you only want to test your install, you can run the ~/bin/Boost.Test script (assuming you had --with-libraries=test enabled when you installed it). Otherwise there should be a bin directory in hour home (if you used that as prefix), if there is anything with the name Boost in it, try to run it (but remember to set the LD_LIBRARY_PATH before).

header files link to '/usr/include'
$ cd /usr/include
$ sudo ln -s /usr/local/boost_xxxx/boost boost
compile boost library, and copy the so files to '/usr/lib'
$ sudo cp /usr/local/lib/libboost_regex-gcc41-mt-xxxx.so.xxxx /usr/lib/

Related

linux C++: libaio.h doesn't contain definition for io_context_t?

I've got a super simple .cpp file like below:
$cat test001.cpp
#include<libaio.h>
int main(){
io_context_t ctx={0};
struct iocb io,*p=&io;
return 0;
}
But once compile it with gcc 4.1.2, it prompts error:
$g++ test001.cpp -laio
test001.cpp:1:19: error: libaio.h: No such file or directory
test001.cpp: In function ‘int main()’:
test001.cpp:3: error: ‘io_context_t’ was not declared in this scope
test001.cpp:3: error: expected `;' before ‘ctx’
test001.cpp:4: error: aggregate ‘iocb io’ has incomplete type and cannot be defined
Well I'm already using "libaio.h". Why it still fails?
sudo apt-get install libaio-dev It should definitely fix the issue. It is for Linux kernel AIO access library - development files.

Library linking in linux

I am new in this domain.
I am installing a library that links to another library (gsl) at run time as follows:
g++ x.cpp y.cpp z.cpp -o abc -lgsl -lm -lgslcblas
I am currently working on a server and hence do not have root privileges.
gsl is a dependency and therefore I did a local installation of gsl. Following are the steps I followed:
1) Downloaded the gsl-latest.tar.gz
2) tar -zxvf gsl-latest.tar.gz
3) From inside the gsl-1.16 (latest) folder I did:
a) ./configure --prefix=local-folder-path
b) make
c) make check
d) make install
Everything is successfully completed.
Now, since the main library links it as run time, I set the path to this bin in the LD_LIBRARY_PATH.
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/a/b/c/gsl-1.16-bin/bin/
Now, when I go to the main library's folder and do a 'make' it still gives me the following errors such as:
error: gsl/gsl_vector.h: No such file or directory
error: ‘gsl_vector_get’ was not declared in this scope
error: ‘gsl_vector_set’ was not declared in this scope
error: ‘gsl_vector_get’ was not declared in this scope
error: ‘gsl_vector_set’ was not declared in this scope
error: ‘gsl_vector_memcpy’ was not declared in this scope
At global scope:
error: ISO C++ forbids declaration of ‘gsl_vector’ with no type
error: expected ‘,’ or ‘...’ before ‘*’ token
Do I need to set the path somewhere else too?
Any help would be appreciated.
Thank You
The problem is include paths. You need to add -I to compile line to find the directory.
Also maybe specify RPATH Wikipedia RPATH to specify where to find libraries

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.

C++ Compilation error against GNU's Multi-precision library

I get the following error when compiling this third-party library (called azove 2.0) which relies on the GNU Multi-precision library:
> make
g++ -Wall -O3 -DFIX_NUMBER_OF_SIGMDDNODE_SONS -DUSE_TIMER -I. -c conBDD.cpp -o conBDD.o
In file included from conBDDnode.hpp:27,
from conBDD.hpp:25,
from conBDD.cpp:22:
/usr/include/gmpxx.h: In destructor ‘__gmp_alloc_cstring::~__gmp_alloc_cstring()’:
/usr/include/gmpxx.h:2096: error: ‘strlen’ was not declared in this scope
conBDD.cpp: In member function ‘void conBDD::build()’:
conBDD.cpp:61: error: ‘numeric_limits’ was not declared in this scope
conBDD.cpp:61: error: expected primary-expression before ‘int’
conBDD.cpp:61: error: expected `;' before ‘int’
conBDD.cpp:68: error: expected primary-expression before ‘int’
conBDD.cpp:68: error: expected `;' before ‘int’
make: *** [conBDD.o] Error 1
I have tried adding either and both of the following lines
#include <cstdlib>
using std::strlen;
to conBDD.cpp, but the error persists.
I can't tell if this is an error comes from GNU's Multi-precision library or from Azove. Any pointers would be greatly appreciated.
I would start by apportioning blame. Create an empty cpp file, say test.cpp, in your project and include only the offending gmpxx.h file. If you can compile test cpp, GMP is off the hook. Then try including only the offending azove header. If you can compile the azove header in an otherwise empty file, azove is off the hook and something you are including/defining is interfering with them. Once you have narrowed down the source of the problem you should find it easier to fix.

Problem in setting up boost library on ubuntu

I have compiled and installed my boost library in '/media/data/bin' in ubuntu 9.10.
And I have setup the INCLUDE_PATH, LIBRARY_PATH env:
$ echo $INCLUDE_PATH
/media/data/bin/boost/include:
$ echo $LIBRARY_PATH
/media/data/bin/boost/lib:
But when I compile the asio example, I get the following error:
$ g++ blocking_tcp_echo_server.cpp
blocking_tcp_echo_server.cpp:13:26: error: boost/bind.hpp: No such file or directory
blocking_tcp_echo_server.cpp:14:31: error: boost/smart_ptr.hpp: No such file or directory
blocking_tcp_echo_server.cpp:15:26: error: boost/asio.hpp: No such file or directory
blocking_tcp_echo_server.cpp:16:28: error: boost/thread.hpp: No such file or directory
blocking_tcp_echo_server.cpp:18: error: ‘boost’ has not been declared
blocking_tcp_echo_server.cpp:22: error: ‘boost’ has not been declared
blocking_tcp_echo_server.cpp:22: error: expected initializer before ‘<’ token
blocking_tcp_echo_server.cpp:24: error: variable or field ‘session’ declared void
blocking_tcp_echo_server.cpp:24: error: ‘socket_ptr’ was not declared in this scope
What is wrong with
sudo apt-get install libboost-dev
after which you don't need to set any -I and -L flags. If you need Boost 1.40, you can still rebuild the current Debian unstable package.
To save everybody's time, here's the answer I gave to this question elsewhere:
http://permalink.gmane.org/gmane.comp.lib.boost.user/54626
Update 2016-02-11: It is necessary to specify the options directly:
g++ -I<prefix>/include -L <prefix>/lib
or use the right variables:
export CPLUS_INCLUDE_PATH=<prefix>/include
export LIBRARY_PATH=<prefix>/lib
try C_INCLUDE_PATH or use -I compiler option
BTW, use LD_LIBRARY_PATH to help find library
Check that headers is actually there:
/media/data/bin/boost/include/boost/bind.hpp
Also try using -I/media/data/bin/boost/include instead of env variable (notice no space after -I).