paultop6
paultop6

Reputation: 3761

Using library files in Linux

I'm trying to use some of the functions that are in the /lib/libproc-3.2.6.so library in my Ubuntu distribution.

I have downloaded and installed the header files and they are defined in my source files.

Currently, this is all I'm trying to do, just for starters...

proc_t **read_proc = readproctab(0);

But I get the following compiler error:

/tmp/cclqMImG.o: In function `Sysmon::initialise_sysmon()':
sysmon.cpp:(.text+0x494): undefined reference to `readproctab'
collect2: ld returned 1 exit status

I'm aware I'm probably doing some wrong with the command I'm using to compile it, but due to lack of experience I'm not sure what I'm doing wrong. This is the g++ command I'm using to compile my cpp file:

g++ -o sysmon.o sysmon.cpp `pkg-config --libs --cflags gtk+-2.0`

Can someone please give me some pointers as to where I'm going wrong.

Upvotes: 1

Views: 549

Answers (3)

Mateusz Piotrowski
Mateusz Piotrowski

Reputation: 9137

Ubuntu 17.04

You probably want to use -lprocps instead of -lproc.

Upvotes: 0

user54808
user54808

Reputation:

You are not actually linking against the library that you wish to use, you are merely including its header files, therefor, the compiler will complain about undefined references.

You can read up on linking against shared libraries here.

A small suggestion, start using the build tool SCons, it can take care of linking to libraries for you, just add the ones you wish to use in the SConstruct file required by SCons and then you don't have to mess about with compiler specifics. You also gain lots of other good stuff that SCons provide. It's highly recommended.

Upvotes: 0

ndim
ndim

Reputation: 37827

You are not linking your executable against libproc (that is a linker error message).

Try adding -lproc to the linker command.

Upvotes: 4

Related Questions