NewOasis
NewOasis

Reputation: 75

Including external c library in Netbeans 8.1

I swear I've been looking around the internet and especially on stackoverflow to find an answer for this since the question is really basic. But I just don't get it right, that's why I'm opening a new thread.

So, I want to include the libevent library in a C project on Netbeans. I have never worked with an external library before and I can't seem to find out how to include it in Netbeans (with which I have never worked before either). What I've found out so far is:

1) If I right-click on the project name and then click on properties I can somehow include external libraries.

2) I need to configure the libraries in the Build -> C Compiler and Build -> Linker section.

However, I can't figure out which files I have to include and where exactly I have to provide them (Include Directories, Include Headers, Additional Options...). There are so many different sections and in the libevent library are so many different files with endings like .h, .a, .so as well as a pkconfig and bin folder. I really don't know what to do with all this. I'm terribly confused. Could somebody maybe help? I would really, really appreciate it!

Upvotes: 2

Views: 583

Answers (1)

Sam
Sam

Reputation: 58

  1. Open the project properties and go to Build -> Linker. Click the three dots to the right of the Libraries section and then click Add PkgConfig Library. Does your library appear there? If so select it.

  2. If that doesn't work, look at the name of the .so files (shared libraries). For example, a file may be called libfoo.so. In the project properties Build -> Linker section, type the library name next to Additional Options, as so: -lfoo. That is, ignore the .so and replace the lib with l.

  3. If that still doesn't work, you may not have installed the library correctly. In this case, try adding the directory where the .so files are saved to the Additional Library Directories section of the Build -> Linker tab and repeat step 2.

Assuming you are using Linux and you ran make install, the libraries should already be installed to the correct directory so step 3 should be unnecessary.

Upvotes: 3

Related Questions