cannot not find library files in eclipse cdt - c++

properties/C/C++ Build/Settings
GCC C++ Linker/Libraries
Under libraries(-I) I have
libbost_system
libbost_filesystem
...
and under Library search path(-L) I have
/home/etobkru/boost_1_43_0/boostBinaries/lib
but when I compile I get
g++ -L/home/etobkru/boost_1_43_0/boostBinaries/lib/ -o"searchDirs" ./main.o -llibboost_system -llibboost_filesystem -llibboost_regex
/usr/lib/gcc/i586-suse-linux/4.1.2/../../../../i586-suse-linux/bin/ld: cannot find -llibboost_system
I have tried with libbost_system.so and libbost_system.a but i get the same error. What am I doing wrong and why cant eclipse find the files. Because they are there?

You don't need the "lib" part in the name. Just link with
-lboost_system -lboost_filesystem -lboost_regex

I think this is similar to /usr/bin/ld: cannot find -llibeststring.a
Did you try -lboost_system? The -l option doesn't expect the leading lib or the trailing .a or .so.

I know it's a little after the fact, but you can try -l:libbost_system.so and it will look for a library with exactly that name.

Actually after much frustration I decided to read the man page for ld!
l namespec
--library=namespec
Add the archive or object file specified by namespec to the list of files to link. This option may be used any number of times. If namespec is of the form :filename, ld will search the library path for a file called filename, otherwise it will search the library path for a file called libnamespec.a.
since my specific library was something along the lines of myfoobar.dll nothing worked until I realized I wanted ld to use the actual filename. As others have posted with screenshots how to add the library to the linker all I needed to do was change 'myfoobar' in the field to ':myfoobar.dll' and it worked fine.
You should use the ':' to get really specific on the filename to search for and stay away from the default file name formatting that is expected without it. Hope this eases frustration.
Krusty,

Related

Concorde installation : need to link an lp solver to use this function

I'be been trying to install the TSP solver of Concorde on Cygwin, but I'm facing some difficulties :
I downloaded Qsopt on the official website, the two files in the "Cygwin" part, and put them in /home/qs. Then, I download concorde, gunzip it, tar it, so I have /home/concorde. I go in this folder and type "./configure --with-qsopt=/home/qs". Everything seems to go well, so I type "make", and this is what I've got (several lines like this) :
/home/concorde/LP/lpqsopt.c:645 : undefined reference « QSget_param »
/home/concorde/LP/lpqsopt.c:674 : undefined reference « QSset_param »
/home/concorde/LP/lpqsopt.c:650 : undefined reference « QSset_param »
/home/concorde/LP/lpqsopt.c:655 : undefined reference « QSopt_dual »
Do you have an idea on how to solve this ? I didn't find anything on the web.
(I 've got automake 1.15)
The command that produce this error seems to be :
gcc -fPIC -O2 -g -o concorde concorde.o tsp.a ../PQ/pq.a ../VERIFY/verify.a ../LOCALCUT/localcut.a ../TINY/tiny.a ../LINKERN/linkern.a ../EDGEGEN/edgegen.a ../KDTREE/kdtree.a ../FMATCH/fmatch.a ../UTIL/util.a ../BIGGUY/bigguy.a ../CUT/cut.a ../HELDKARP/heldkarp.a ../LP/lp.a ../COMBS/combs.a /home/qs/qsopt.a -liberty -lm ../LP/lp.a(lpqsopt.o)
And then as you see, the errors seems to come from LP
Thanks a lot,
Djazouli
So I found the source code and it looks like the problem is in TSP/Makefile.in.
The problem is that the parameters given to the link editor (ld) are positional: object files (and convenience static archives) need to come before the libraries they link to.
In this case there is a second instance of ../LP/lp.a(lpqsopt.o) being passed at the end, and given nothing to link against. I'm not sure where that is coming from though. The build system is quite a mouthful to figure out where the error comes from.

error while executing "make" on terminal

I am a bit newbie to using terminal so I will appreaciate it a lot if you help me to sort this out.
This small folder named mismatch came with the code I downloaded,which is supposed take four arguments like this
./mismatch/mismatch 3 1 ${SFILE}
and compute mismatch scores for protein sequences. Folder 'mismatch' contains mismatchManager.cc, makefile and a folder named "CVS".
inside the makefile,
all: mismatchManager.cc
g++ mismatchManager.cc -o ../../bin/mismatch -lm
After a quick search, I found out that -o is used when you want to name your .exe file and -lm is used to link the executable to a library which I thought is "bin" here. So when I ran "make" command from the terminal, it gave the following error.
ld: can't open output file for writing: ../../bin/mismatch, errno=2
collect2: ld returned 1 exit status
I thought that "bin" directory could be /usr/local/bin where the executables are stored so, I replaced the above path to this one, however it gave the same error. Here there is a solution for ErrNo=21 Why does the name of a source file affect compilation?, as it is told I don't have a folder named mismatchManager though.
I also changed make file into
all: mismatchManager.cc
g++ -o mismatch mismatchManager.cc
then ran "make" command. It worked well, then I copied to mismatch.exe to /usr/local/bin manually. This time I was able to pass arguments but I didn't produce any results. I have no idea what I should do.
Thanks already!
Nice linker. Can't even interpret the error code for you? Lame. Anyway, errno=2 is "access violation", which means you don't have permissions to write to or create the file ../../bin/mismatch.
I can't say why that would be since I don't know what ../../bin is on your system, but certainly changing it to /usr/local/bin won't help since you likely don't have write permissions to that directory either.
You can try just changing it to -o mismatch which will write out a file named mismatch in the current directory, which you most likely do have write permissions for.
BTW, your statement -lm is used to link the executable to a library which I thought is "bin" here is not correct. -lm is asking the linker to link in the m, or math, library. bin is not a library, it's a directory (or some people call them "folders"), and it has nothing to do with the argument -lm.

Trouble including NSS header Files

Very recently, I had this idea to start using Mozilla NSS and to learn to use it, so that somewhere in the future, i can use it, or can atleast start contributing to it.
So i went to its Website and cloned it source code into a director "NSS" using mercurial
Then I used
make nss_build_all
instead of
gmake nss_build_all
Note : I don't know, if it makes a difference, gmake is just GNU Make
This make command created a dist folder outside the nss folder. So, Now my NSS folder has 3 folders nss,nspr,dist.
In .bashrc i added a line at the end
export LD_LIBRARY_PATH=/home/ayusun/workspace/NSS/dist/Linux3.5_x86_glibc_PTH_DBG.OBJ/lib
Then i went over to this Sample code, did a copy paste and saved it in my NSS Folder.
And then i tried to compile it, but it failed, stating it couldn't find iostream.h, I went over and changed the location of header files
So
<iostream.h> became <iostream>
"pk11pub.h" became "nss/lib/pk11wrap/pk11pub.h"
"keyhi.h" became "nss/lib/cryptohi/keyhi.h"
"nss.h" became "nss/lib/nss/nss.h"
I tried compiling again but this time error came, that it couldn't find "planera.h"
which is actually present in dist/*.OBJ/include/ which is a link to a file planeras.h in nspr
And so i don't know, how to include these files anymore.
I always have trouble when it comes to include 3rd party header files.
Thanks
This is an old question, but I'll answer it anyway for future reference.
The simplest way is just to use the NSS package for your operating system.
Then you can use things like nss-config --cflags, nss-config --libs, nspr-config --cflags and nspr-config --libs and add that to your CFLAGS and LDFLAGS as appropriate.
For those who do decide to compile their own NSS, I'll give the quick overview.
The NSS headers are in dist/public. Add -I/path/to/dist/public to your compiler command line. The NSPR headers are in dist/Debug/include¹ so add -I/path/to/dist/Debug/include to your comiler command line.
Now you can use #include <nspr/prio.h> and #include <nss/nss.h> and friends.
The NSS code relies on directly uncluding the NSPR headers, so you'll need to add -I/path/to/dist/Debug/include/nspr for it to find things like plarena.h. Or you could do the same and not prefix your includes like I did above. It's up to you.
Now add -L/path/to/dist/Debug/lib and -lnss3 -lnspr4 to your linker command line. You may want to also add -rpath /path/to/dist/Debug/lib for the runtime link path, or copy them to a system directory or use LD_LIBRARY_PATH.
I hope this gets you started.
¹ This actually depends on your operating system and build type. I hope you can figure out the name of the actual Debug directory in your case.

boost::filesystem3::path::parent_path() on Ubuntu

As an input the function gets the file path anmd name parameter
const QString& buildSourcePathAndName
It needs to extract the path onlyfor futher processing.
I used the below code to do that .
boost::filesystem::path p(string(buildSourcePathAndName.toLatin1().data()));
m_pSourceCodePath = p.parent_path().string();
On windows it works OK.But on linux (ubuntu) I can`t compile it,getting the error.
undefined reference to `boost::filesystem3::path::parent_path() const'
I`ve read about this error - proposes to change boost lib version.I can`t do that in our system.
What could be the possible solution for this issue?
(I don`t want to implement the code which extracts the path,but rathe use some existing functions)
On Windows, boost libraries use pragmas to automatically add the libraries to the linker command line. When building for linux you need to add the libraries explicitly in whatever build system you use (adding -lboost_filesystem at the end of the linker command line as suggested by ForEveR and hmjd)

dynamic linking:change of the linking path

Normally it happens that when ever the path of the library that has to be linked dynamically is defined in LD_LIBRARY_PATH or it it will be mentioned with -L flag while creating the binary.
In actual scenario if ,lets say the binary has been built and deployed at the client place.
Now if there is a change in the path of one of the dynamic link library path.
then we need to supply a new make file to all the clients where the binary was deployed.
is there any other method where we need not tell all the clients to change their makefiles and can something can be done in the code itself?
if yes...could anybody please suggest how?
This was ironically an interview question that was asked to me and i didnot have the answer for it.
EDIT:: I was specifically asked about what can be done in the code without touching the makefile.
Usually you should only change the LD_LIBRARY_PATH, unless this might be related to a compilation with a hard-coded search path: rpath.
Maybe the interviewers wanted to know about dlopen and dlsym?
http://linux.die.net/man/3/dlsym
Use environment variable, like MYLIBPATH, and use this variable in your makefile, rather than hard-coded value.
So every client can have own directory structure, and as long as they correctly specify MYLIBPATH, your program builds ok.
Alternatively you can look for library in your makefile, like this
LIBPATH = $(shell find / -name libmylib.a -exec dirname {} ";" -quit)
myprog: myprog.c
$(CC) myprog.c -lmylib -L$(LIBPATH)
EDIT: locate replaced with find that returns just first match with -quit option