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
Related
I'm on Red Hat Linux. I'm having some (probably newbie) problem with the includes in a C++ file. I created the following simple OpenCV script,
#include "opencv2/highgui/highgui.hpp"
using namespace cv;
int main(int argc, char ** argv){
Mat img = imread( argv[1], -1 );
if ( img.empty() ) return -1;
namedWindow( "Example1", cv::WINDOW_AUTOSIZE );
imshow( "Example1", img );
waitKey( 0 );
destroyWindow( "Example1" );
}
Then in the terminal I entered
g++ my_simple_script.cpp
and got the errors
newfile.cpp:1:39: error: opencv2/highgui/highgui.hpp: No such file or directory
newfile.cpp:3: error: 'cv' is not a namespace-name
newfile.cpp:3: error: expected namespace-name before ';' token
newfile.cpp: In function 'int main(int, char**)':
newfile.cpp:6: error: 'Mat' was not declared in this scope
newfile.cpp:6: error: expected ';' before 'img'
newfile.cpp:7: error: 'img' was not declared in this scope
newfile.cpp:8: error: 'cv' has not been declared
newfile.cpp:8: error: 'namedWindow' was not declared in this scope
newfile.cpp:9: error: 'img' was not declared in this scope
newfile.cpp:9: error: 'imshow' was not declared in this scope
newfile.cpp:10: error: 'waitKey' was not declared in this scope
newfile.cpp:11: error: 'destroyWindow' was not declared in this scope
I added
/home/m/maxwell9/2.4.3/include
to my PATH, where 2.4.3 indicates the version of OpenCV I'm using.
When I type
echo $PATH
I see
/opt/apps/jdk1.6.0_22.x64/bin:/apps/smlnj/110.74/bin:/usr/local/cuda/bin:/sbin:/bin:/usr/sbin:/usr/bin:/apps/weka/3.7.12:/home/m/maxwell9/bin:/home/m/maxwell9/2.4.3/include
I confirmed that there is a file at
/home/m/maxwell9/2.4.3/include/opencv2/highgui/highgui.hpp
Just adding the include path will only resolve your compile problem. You will still see linker errors.. (and right way of adding include path is using -I flag, PATH is not used for this..)
To compile and link your program successfully, you will need to both specify the Include path for header files and linker path to the pre-compiled OpenCV libraries and the list of libraries to be linked...
The standard way, had you installed the openCV to the standard installation directory,by using the following sequence
sudo make install (from your OpenCV build library)
echo '/usr/local/lib' | sudo tee -a /etc/ld.so.conf.d/opencv.conf
sudo ldconfig
printf '# OpenCV\nPKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig\nexport PKG_CONFIG_PATH\n' >> ~/.bashrc
source ~/.bashrc
the following would have compiled and linked your program successfully for you :
g++ my_simple_script.cpp `pkg-config --libs opencv` `pkg-config --cflags opencv`
But apparently you have not done that.. as you are trying to point to a non-standard include path. Hence in your case you will need to specify your include path explicitly by using -I flag and your pre-compiled library path by -L flag and list out all the individual libraries you might want to use by using -l<name_of_library>
g++ my_simple_script.cpp -I /home/m/maxwell9/2.4.3/include -L /home/m/maxwell9/2.4.3/<your build directory name>/lib/ -lopencv_core
(list of other openCV libraries you may need will have to be appended to above command using format: -l<name of the lib you need>)
The PATH doesn't matter, you need to add the include path to the compiler include paths (the -I parameter of gcc). Or to the CPLUS_INCLUDE_PATH environment variable.
I do not have permissions to put GLM into usr/local/include or usr/include but I need to use GLM for openGL. The code (I am not able to change) looks for GLM like this:
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
the folder glm is in the same directory as my main.cpp where this code is from. I think it's not working because it's looking for glm in usr/include where in built headers are (im using redhat linux)
How can I stop this from happening, since I cannot run:
g++ main.cpp -lGL -lglut -lGLEW
without these errors:
main.cpp:46:23: error: glm/glm.hpp: No such file or directory
main.cpp:47:40: error: glm/gtc/matrix_transform.hpp: No such file or directory
main.cpp:48:32: error: glm/gtc/type_ptr.hpp: No such file or directory
main.cpp:62: error: ‘glm’ has not been declared
main.cpp:62: error: expected constructor, destructor, or type conversion before ‘cameraMatrix’
main.cpp: In function ‘int setShaderData(const unsigned int&)’:
main.cpp:102: error: ‘glm’ has not been declared
main.cpp:102: error: expected ‘;’ before ‘projection’
main.cpp:105: error: ‘glm’ has not been declared
main.cpp:105: error: ‘projection’ was not declared in this scope
main.cpp:109: error: ‘glm’ has not been declared
main.cpp:109: error: expected ‘;’ before ‘modelview’
main.cpp: In function ‘void render()’:
main.cpp:187: error: ‘cameraMatrix’ was not declared in this scope
main.cpp:187: error: ‘glm’ has not been declared
main.cpp:200: error: ‘glm’ has not been declared
My answer isn't really related to the author's question, but I'm just leaving it here for those, who come here from ubuntu with a missing package
sudo apt-get install libglm-dev
GLM is not part of OpenGL. It's a C++ math library that has much of the same syntax as GLSL. In order to use it you need to download it from here or install it using your package manager (although if you don't have administrative rights on this machine, then you won't be able to do that).
Once you have it, you need to add it to your include path:
g++ main.cpp -lGL -lglut -lGLEW -I/path/to/glm/headers
Although if you install it with a package manager it will probably end up in your system include 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.
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/
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).