Reputation: 297
I am trying to install a C++ library (armadillo) in a unix cluster where I do not have root permissions.
I managed to compile the C++ libraries without user permissions by running the following make command:
make install DESTDIR=my_usr_dir
But then in the armadillo readme file it says:
where "my_usr_dir" is for storing C++ headers and library files. Make sure your C++ compiler is configured to use the sub-directories present within this directory.
The compiler the armadillo uses to install the libraries is gcc-4.8.1. I am not sure where the compiler was installed but it's loaded when I start my session in the unix cluster.
After installing armadillo I am trying to compile open source code that uses the armadillo libraries. This open source code also has a makefile.
However, when I go to the open source code and I type in:
make
it calls g++. How can I make sure g++ will recognize the armadillo libraries previously installed in my_usr_dir?
Currently I get the following error if I go to src and then type make:
opencode.cpp:28:21: fatal error: armadillo: No such file or directory
#include <armadillo>
^
compilation terminated.
make: *** [mmcollapse] Error 1
Upvotes: 4
Views: 8028
Reputation: 255
This question looks similar to
If you dont want to change the .bashrc
use -rpath as suggested in the post above.
gcc XXX.c -o xxx.out -Lmy_usr_dir -lXX -Wl,-rpath=my_usr_dir
-L is for static linking -rpath for adding the directory to the linker search path
more on -rpath here
Dont bother to upvote the answer because this is really not an answer. I would have commented but i could not locate the add comment for your post.
Upvotes: 1
Reputation: 3083
you can use
alias gcc="gcc -I./my_usr_dir/include -L./my_usr_dir/lib"
and so on in your .bashrc
file. In that way, whenever you invoke gcc on the command line, the flags will be added before every other argument you enter on the command line
Upvotes: 3
Reputation: 45424
I think the readme file refers to the usage of the library headers and library files from applications. For those to be useful, the compiler/linker/loader (usually all driven by the "compiler") have to know where to find them. The compiler always looks in some default directories, such as /usr/include
(for headers) and /usr/lib/
(for libraries), but they require root permission to write into. However, you can tell the compiler with the flag -I
directory to search in directory directory for headers. For libraries use -l
and -L
(check the manual page of your compiler). You may also need to consider the LD_LIBRARY_PATH
and LD_RUN_PATH
environment variables, if you're using dynamic linking (shared object files).
Upvotes: 1