0

I have seen several other answers in order to add a library to my C+= project in eclipse.I have tried to add the path to the linker in Miscellaneous section using -L"and the path of the folder" and -l"the name without the lib prefix in the begging and the .so at the end" I try to add libxl library so i use -lxl (for libxl.so) and -L/home/username/libxl3.5.3.0/lib/ (which the location of the lib file).

I have also tried to give it under the Linker menu and adding the name and the path in the Libraries section.

I get error that: /usr/bin/ld does not find -lxl file and it returns error

I am using -static to linker in order to make an executable that has the all the libs included but when i do not use -static the problem with the lib resolves from build but still when i try to run the program i get error that i the program can not open shared file libxl.so cause the file does not exist.How can i fix this?

kyrpav
  • 756
  • 1
  • 13
  • 43

1 Answers1

2

When you add the library name to a C++ project in eclipse, do not prefix it with -l. Eclipse will do this for you when it invokes the compiler. For example if you want the boost_regex library, just input boost_regex not lboost_regex. Eclipse will do the rest for you. Or in your specific case, just use xl not lxl. You don't need the - either, nor the -L before paths as erenon points out in the comment below. Note that the above applies to the method of adding libraries using the Project->Properties->C/C++ General->Paths and Symbols dialog form for adding libraries using the Libraries and Library Paths tabs.

You are trying to link statically to a shared library. In my experience I have always used *.a files rather than *.so files to employ static linkage. This other answer Static link of shared library function in gcc seems to suggest that you are not actually able to link statically to *.so files.

Community
  • 1
  • 1
mathematician1975
  • 21,161
  • 6
  • 59
  • 101
  • The same applies to lib paths, -L is not required. – erenon Dec 08 '13 at 14:41
  • You can prefix `-l` or `-L` when giving commands directly to linker. This is done from "Miscellaneous" options – P0W Dec 08 '13 at 14:45
  • i tried to give -l and -L to the linker directly and also i tried to with the Libraries section without giving and -l or -L.In the Libriaries section of the linker i have given only the name ("xl" without the ") and only the path which i choose from a browser that pop up. – kyrpav Dec 08 '13 at 14:53
  • OK I have updated to mention that this is for the Paths and symbols dialog – mathematician1975 Dec 08 '13 at 14:55
  • in the path and symbols dialog in the Libraries tab there is one addition that has the name xl and in the Libraries path tabe there is the path to the .so file – kyrpav Dec 08 '13 at 14:57
  • I am using -static to linker in order to make an executable that has the all the libs included but when i do not use -static the problem with the lib resolves from build but still when i try to run the program i get error that i the program can not open shared file libxl.so cause the file does not exist.How can i fix this? – kyrpav Dec 08 '13 at 15:26
  • You have to setup LD_LIBRARY_PATH if you use uninstalled DSOs. Before running your program: LD_LIBRARY_PATH=/home/platonas/Programmes/libxl-3.5.3.0/lib:$LD_LIBRARY_PATH – erenon Dec 08 '13 at 15:42
  • i wrote this to a terminal and tried again but i get the same error – kyrpav Dec 08 '13 at 15:50
  • Well i fould out that inside the debug folder that is my configuration when i built the project i get a libxl.dll file and also i get error that iit can not find the .so file – kyrpav Dec 08 '13 at 16:07