Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined reference to `forkpty'

Tags:

c++

linker

So I'm developing my project in Eclipse in Ubuntu 10.04. I have the following lines of code:

#include <pty.h>

pid_t pid;
int master;

pid = forkpty(&master, NULL, NULL, NULL);

But when I try to build it within Eclipse, I get the error:

undefined reference to 'forkpty'

Any idea how to solve this problem?

like image 563
Hank Avatar asked Dec 20 '10 16:12

Hank


2 Answers

That's a linking error; you're missing the util library. Do this to build on the command line:

g++ myprogram.cpp -lutil

Eclipse should have project-level settings for listing the libraries to link against.

like image 141
chrisaycock Avatar answered Nov 15 '22 16:11

chrisaycock


You need -lutil command line argument (to use libutil shared library).
For Eclipse: http://zetcode.com/articles/eclipsecdevelopment/

Select Project Properties. Expand the C/C++ Build tab. Select settings. From the Tool Settings tab, expand the GCC C Linker option. Click on libraries. Add the /usr/lib/libutil.so to the Libraries window. Notice, that this path may be different on your system.

like image 24
MK. Avatar answered Nov 15 '22 18:11

MK.