LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-02-2012, 12:51 AM   #1
sadhup
LQ Newbie
 
Registered: May 2012
Posts: 3

Rep: Reputation: Disabled
How do i configure g++ to look into particular directory to search library fles?


Hi.. I dont have permission to install on the disk. My program needs to link to mysql DB. I copied the Mysql.h and rest headerrs to local folder and ran the program. While executing, the program throws an error sayin

./a.out: error while loading shared libraries: libmysqlclient.so.16: cannot open shared object file: No such file or directory.
I tried setting the LD_LIBRARY_PATH variable, but dint help. please help me how to go about it.
thanks in advance.
 
Old 05-02-2012, 01:22 AM   #2
sag47
Senior Member
 
Registered: Sep 2009
Location: Orange County, CA
Distribution: Kubuntu x64, Raspbian, CentOS
Posts: 1,832
Blog Entries: 36

Rep: Reputation: 451Reputation: 451Reputation: 451Reputation: 451Reputation: 451
g++ man page or the gcc docs.
Code:
-llibrary
-l library
    Search the library named library when linking. (The second alternative with the library as a separate argument is only for POSIX compliance and is not recommended.)

    It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, foo.o -lz bar.o searches library z after file foo.o but before bar.o. If bar.o refers to functions in z, those functions may not be loaded.

    The linker searches a standard list of directories for the library, which is actually a file named liblibrary.a. The linker then uses this file as if it had been specified precisely by name.

    The directories searched include several standard system directories plus any that you specify with -L.

    Normally the files found this way are library files---archive files whose members are object files. The linker handles an archive file by scanning through it for members which define symbols that have so far been referenced but not defined. But if the file that is found is an ordinary object file, it is linked in the usual fashion. The only difference between using an -l option and specifying a file name is that -l surrounds library with lib and .a and searches several directories.
Code:
-Ldir
    Add directory dir to the list of directories to be searched for -l.
So I would say
Code:
g++ -L/path/to/library -lmysqlclient ...

Last edited by sag47; 05-02-2012 at 01:25 AM.
 
Old 05-02-2012, 01:29 AM   #3
sadhup
LQ Newbie
 
Registered: May 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
I tried but is still throwing the same error. I also tried setting the environmental variable LIBRARY_PATH.

Thanks
 
Old 05-02-2012, 01:38 AM   #4
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,275

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
The environment variable is LD_LIBRARY_PATH. ld is the dynamic linkers, which resolves libraries at runtime whereas the compiler only needs them to link the final executable. You can compile an executable statically (with the -static flag) assuming all required libraries exist statically on the disk (as .a files, not .so files). This was, the program will have no external library dependencies at a cost of a (potentially much) larger binary.
 
Old 05-02-2012, 02:01 AM   #5
sadhup
LQ Newbie
 
Registered: May 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
@btmiller, the library file tat is not bein located is .so..can i use static flag while compiling??

thanks
 
Old 05-02-2012, 02:06 AM   #6
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
You will need the static library, which is usually supplied in the -devel package version. Actually, the devel versions of dependencies is usually needed when compiling from source.any way. The static library versions have .a extensions.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] ./configure problem for libsf library due to apparently missing libdb library. vectrum Linux - Software 6 08-05-2011 03:11 PM
[SOLVED] search rrdtool library for linux mosquito_soft Linux - Server 3 08-23-2010 01:37 PM
how can i run bin fles on vector linux bushcat Linux - Newbie 2 03-28-2009 11:25 AM
How to copy files after search in array from this directory to another directory! phanvinhgiap Programming 4 01-04-2009 07:48 PM
Any good apps to upload fles to website darin3200 Linux - Software 2 04-15-2003 10:45 PM


All times are GMT -5. The time now is 08:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration