I am currently encountering a few errors with Eclipse c++. I am a complete newbie to c++ and because I knew Eclipse from java I thought it might be ok. Now to the issue:
I want to use the curl library, but I have no idea how to include it correct. Everywhere around the internet I found that I have to go to the compiler settings, include the library there, go to the linker settings and include it there as well. Now the linker has 2 different panels, one for Libraries (-l) and one for Library paths (-L).
I have downloaded the curl library to this directory:
C:\Users\Hannes\Desktop\eclipseC\curl-7.45.0
How do I have to include the Library correctly now?
Here is the error:
g++ "-LC:\Users\Hannes\Desktop\eclipseC\curl-7.45.0\include\curl" -o HelloWorld.exe HelloWorld.o -lcurl
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -lcurl
In the editor the automatic completion for curl methods does work.
EDIT: Removing \include\curl from the Library path (-L) didn't work as well.
You have included what looks to be an include path not the library path. Is there a /lib directory under the curl path?
The c/c++ includes should be the path to the header files for curl, the linker path should be to the libraries not the headers, so .a and .dll files normally (normally under a /lib directory).
Related
I have downloaded a repository from github with a library with git clone
then I typed in terminal "make"
now I have a libmylibrary++.so file in folder mylibrary/src
Now I want to run a c++ file which uses the library but I can't compile it because of this error: "mylibrary.hpp: No such file or directory"
How to add it to PATH? yet I don't understand what exactly I need to add
Whether it is folder "/home/mylibrary" or folder with the .so file
Your C++ compiler only knows to search for header files and libraries in standard locations and directories. Just because you downloaded another library in some directory, somewhere, doesn't mean that your C++ compiler will automatically find it.
You will need to change your Makefile and compile your program with the additional compilation options that instruct your C++ compiler to search for header files and libraries in other directories -- typically -I and -L option.
Additionally, you will probably need to use either -R or -Wl,-rpath options in order for the compiled code to load the shared libraries from the non-standard locations.
You will find additional information in the gcc manual and documentation.
I am just trying to run replace_regex_copy in my code. For that I have included regex.hpp file. At the start it showed some errors like Unreferenced includes something like that. I googled it, I found that need to include -llibboost_regex in the linker. But after including that I am getting linker error as cannot find -libboost_regex.
But I have libboost_regex.a and libboost_regex.so in boost/lib folder.
Eclipse configuration I made:
Under GCC C++ Linker:
Libraries (-l) libboost_regex
Library Search Path (-L) /boost/lib
Even I tried to give entire path with the file in Libraries(-l) too. But nothing helps.
Still am getting cannot find -llibboost_regex error. Can anyone help me out?
I'm having an issue compiling a static library using Code::Blocks 13.12. I need to use a third party static library from within my own static library. So, I have libOtherLib.a and I'm trying to build libMyLib.a and link in libOtherLib.a. The problem is that the linker is not including libOtherLib.a during the linking phase of the build. Here is some additional information:
I am using the GNU GCC Compiler
In Project build options for the whole project (not specifically Debug or Release)
I have added libOtherLib.a in the Link Libraries list in the Linker Settings
I have added the path to libOtherLib.a in the Search directories -> Linker list
I have added the path to the .h file for libOtherLib.a in the Search directories -> Compiler list
The library compiles completely fine (produces bin/Debug/libMyLib.a with no errors)
Any help would be greatly appreciated. I have an inkling that it is related to this being a Static Library rather than an application (console or otherwise), but I'm not sure how or why. I did change the build target Type to "Console Application" in the Project Properties window and it looked like it was linking in libOtherLib.a, but it had other errors because this code is meant to be a library rather than an application.
Here is the linker command that is executed at the end of the build. libOtherLib.a is not there anywhere, that is the problem, just not sure what the solution is.
ar -r -s bin/Debug/libMyLib.a <all of my .o files>
Possible causes of the problem would also be nice - if this is mostly like the compiler, the linker, the setup or Code::Blocks itself.
When building a static library you are just putting together a bunch of object files into an entity easier to ship and use. There is no linking done when building a static library.
The unresolved references from your library are dealt with when building an application or certain shared objects. You'd just ship your library and require that users also supply the library your library deoends on when building.
If you want to include the library you are depending on in your library you can extract the object files from tgat library and include them into your library. Although technically possible it is questionable if you have the rights to do so. Also, that is normally not the way things are done and I'd recommend against doing so.
You can't link a static library in anoter static library.
However,you can do this:
Suppose MyPrograme.exe need to link static library libMyLib.a,make MyPrograme.exe also link libOtherLib.a.
Since libMyLib.a is static library,there is no need to link libMyLib.a.Just inclue the headers.
When build a static library,it will only be compiled,not be linked.
Despite all this "linking is not the right term for this" philosophy, you can patch Code::Blocks compiler configuration to support this, for example for the GCC/G++ compiler.
http://green-candy.osdn.jp/codeblocks_config.html
The idea is that you replace the "Link object files to static library" script in the "Advanced compiler options" window of GCC with:
rm -f $static_output
$lib_linker -r -s -T $static_output $link_objects
$lib_linker -r -c -T $static_output $link_options
Then you can put the relative path to your "libOtherLib.a" in the "Other linker options" editbox of your projects. This mod is not really officially endorsed but it works in my projects, so you get static libs in static libs just like in MS Visual Studio!
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?
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.
Good day! I am running a c++ project main.cpp in eclipse. i want to use my existing .so file and link it in main.cpp. I am searching about this but cant find the right method for me. I'm using ubuntu. Thanks for any help!
To link against a library you need to supply the compiler(or the linker) a -l flag and the library name. For example, if you want to link against a library called libjustine.so, you would supply your compiler(gcc if C, g++ if C++) a flag -ljustine and then the compiler would instruct the linker to link against a file libjustine.so in the library path (usually at least /usr/lib/ and /usr/local/lib/).
However, if you want to define your own library directory, for example a lib/ directory inside your project directory, you need to use the -L flag and supply the desired library directory(relative to the current directory) that way, for example -L/lib/ so the compiler can instruct the linker to look for the desired library from lib/ instead of for example /usr/lib/ where it looks for the file by default.