简体   繁体   中英

Issues with linking library C++

My problem is I am not able to include a library into my current project. [The way to include a library in netbeans into a project is to link it via linker to the project]. However, in my current project(which is written by another programmer who left the organization) the option of linker is not appearing. I have attached a screenshot. I am faced with the issue that the option of linking the library via linker to my current project is not appearing in IDE. Can someone please please help me out. I'll be highly thankful to you for the same.

Please guide me as to how should I link the library to my project. I have really spent a lot of days doing it but I did not succeed. 屏幕截图

Assuming you are only interesting in libspatialindex:

  1. Make sure you have the appropriate files installed: try a locate libspatialindex and see where it is installed. You could have a *.a, *.so or similar extension. Note the path.
  2. Go into your project root directory, ie: /home/keira/netbeans/projects/myproject
  3. Try: gcc -i main.cpp -L/usr/lib/ -lspatialindex -o myfile

Replace the -L/usr/lib with the actual location where you know the library is at.

The cxx link flag is usually the name of the library with an -l prefix. If for example the name found in the system is libspatialindex.so then its a good bet to try with -lspatialindex .

There is a way to find the actual flags on Debian & Ubuntu systems but I cannot atm remember it. Alternatively you can always look on google or read the library documentation.

When you usually see linker errors with undefined functions, etc, it means you're not linking, provided you have included the headers and they are found.

Now for Netbeans, I assume there is the option of passing extra arguments to the compiler. In this case, all you need is the -lspatialindex flag, provided Netbeans knows where to find the library and the headers. That is how it works in KDevelop and other IDE's I have used.

Alternatively if you want more control and more automation, you may want use a tool like cmake.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM