How to automatically get g++ and ld to look into library?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Debian Jessie, FreeBSD 10.1 anything *nix to get my fix
Posts: 329
Rep:
How to automatically get g++ and ld to look into library?
i want to be able to type a simple compile command like : g++ -o myprogram mycode.cpp for my program to compile.
however, my mycode.cpp depends on a library.
1 the library is installed in /usr/local/include/foo-library-0.3/foo-library/
2.the library is also installed in /usr/local/lib/ which has entries for libfoo.a, libfoo.la, libfoo.so etc.
If i try to compile my program, i get error that the headers for foo.h etc are not declared and there is no such file or directory.
What do I need to do to get this program to compile? At the lowest level, i want to type in my compile commands myself. Do I need to change the paths for my shell, linker and g++?
I have tried reading stuff about 'LD_LIBRARY_PATH' & compiler flags etc, but i dont understand them. Can you give me sure fire entries that I should add to set my paths right if i need to do this?
[...] I have tried reading stuff about 'LD_LIBRARY_PATH' & compiler flags etc, but i dont understand them.[...]
That may be a bit of a problem.
Understanding preprocessor directives, linker options and makefiles is a rather fundamental part of learning to develop programs.
I'm not sure anyone can really give you explicit command-line options for your case without more information but, in general, you can specify directories to be searched for header files with the -I option, and directories to be searched for libraries with the -L option, and specific libraries to be linked with the -l option.
Of course, this assumes that you have specified the proper preprocessor directives in your source files so it knows what header files to include.
There are other options than the command line if you wish to include directories in the linker and/or preprocessor search paths. ldconfig will help you set some defaults for library paths, for instance.
Distribution: Debian Jessie, FreeBSD 10.1 anything *nix to get my fix
Posts: 329
Original Poster
Rep:
Is this error due to the libarary or wrong linking+compile commands?
thanks guys, this is what i have tried:
$ g++ -o ttt -I/usr/local/include/ClanLib-0.8/ -L/usr/local/lib TicTacToe.cpp
In file included from /usr/local/include/ClanLib-0.8/ClanLib/display.h:61,
from TicTacToeApp.h:4,
from TicTacToe.cpp:2:
/usr/local/include/ClanLib-0.8/ClanLib/Display/keys.h:352:24: error: X11/keysym.h: No such file or directory
In file included from TicTacToeApp.h:5,
from TicTacToe.cpp:2:
/usr/local/include/ClanLib-0.8/ClanLib/gl.h:53:19: error: GL/gl.h: No such file or directory
/usr/local/include/ClanLib-0.8/ClanLib/gl.h:54:20: error: GL/glu.h: No such file or directory
In file included from /usr/local/include/ClanLib-0.8/ClanLib/gl.h:59,
from TicTacToeApp.h:5,
from TicTacToe.cpp:2:
/usr/local/include/ClanLib-0.8/ClanLib/GL/opengl_window.h:56:22: error: X11/Xlib.h: No such file or directory
In file included from /usr/local/include/ClanLib-0.8/ClanLib/gl.h:59,
from TicTacToeApp.h:5,
from TicTacToe.cpp:2:
/usr/local/include/ClanLib-0.8/ClanLib/GL/opengl_window.h:101: error: ISO C++ forbids declaration of 'Display' with no type
/usr/local/include/ClanLib-0.8/ClanLib/GL/opengl_window.h:101: error: expected ';' before '*' token
$
Whats wrong here? someone said i probably need to include other libaries as well - but that does not make sense to me.
Also Is there a way to setup anjuta ide to do this automatically?
virtual int main(int, char **);
};
-----------------source code----------------
// Implementation (for the .cpp file)
#include "TicTacToeApp.h"
// This application instance is required or the app will not run
TicTacToeApp applicationInstance;
// Constructor
TicTacToeApp::TicTacToeApp() {}
// Destructor
TicTacToeApp::~TicTacToeApp() {}
int TicTacToeApp::main(int, char **) {
// Create a console window for text-output if not available
CL_ConsoleWindow console("TicTacToeApp Console");
console.redirect_stdio();
try {
// CL initialization functions
// These must be called or CL functions will not work
// Also, SetupCore must be init()'ed first and denit()'ed last
CL_SetupCore::init();
CL_SetupDisplay::init();
CL_SetupGL::init();
// Set display mode
CL_DisplayWindow window("TicTacToeApp", 500, 450);
Distribution: Debian Jessie, FreeBSD 10.1 anything *nix to get my fix
Posts: 329
Original Poster
Rep:
this didnt work. the script clanlib-config was afaik for clanlib 0-6 only. my version is 0.8. but this is a real simple 'example' program and i really do need to be able to compile it by hand ideally.
i also going to use anjuta ide - ive made a start reading the manual but unless i know the how & why of the command line syntax - i cant even have much hope of setting up anjuta to automatically do builds.
thanks for trying to help anyway.
you really ought to deploy a makefile. Life is much simpler once you have done that.
Failing that, you should study the utility pkg-config. If the library you need has a .pc file (usually in /usr/lib/pkgconfig or /usr/local/lib/pkgconfig) then you can include all the libs like this (note that I am using backquotes - the unshifted ~ key):
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.