LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 11-12-2009, 05:26 PM   #1
richard64
LQ Newbie
 
Registered: Oct 2006
Posts: 6

Rep: Reputation: 0
Noob Compiling C/C++ code


I'm trying to follow the ALP tutorial (http://www.makelinux.net/alp/). I have just installed Ubuntu 9.04 so the system is pretty much a clean system.

I am trying to compile this code:

Code:
#include <stdio.h> 
#include <tiffio.h> 

int main (int argc, char** argv) 
{
  TIFF* tiff; 
  tiff = TIFFOpen (argv[1], "r"); 
  TIFFClose (tiff); 
  return 0; 
}
Code:
gcc tifftest.c -o tifftest -ltiff
The first problem I get is

Code:
tifftest.c:8:20: error: tiffio.h: No such file or directory
And when I look in /usr/include there is no file tiffio.h. So as a kludge I download the source for libtiff (http://www.libtiff.org/) and I copy the header files to the current directory (change the code appropriately) and try again. Now the code compiles but won't produce the object file:

Code:
/usr/bin/ld: cannot find -ltiff
collect2: ld returned 1 exit status
/uisr/lib has libtiff.so.4 and libtiff.so.4.2.1 so I am at a bit of a loss as to why ld is not finding libtiff.

Does anyone have some suggestions of what I should do now?

1) what do I need to do to install the libtiff header files properly?
2) how do I get gcc to find libtiff?

I am sure these are noob questions, but I haven't need able to find any answers in the searches I have done.

Richard
 
Old 11-12-2009, 06:10 PM   #2
ammorais
Member
 
Registered: Nov 2009
Location: Lisbon, Portugal
Distribution: Gentoo, CentOs, Ubuntu, Debian
Posts: 182

Rep: Reputation: 49
Code:
sudo apt-get install libtiff4-dev
 
Old 11-12-2009, 06:22 PM   #3
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
So it seems you have libtiff4 installed: it provides the libtiff.so.*.

Quote:
1) what do I need to do to install the libtiff header files properly?
libtiff4-dev provides the headers. So please remove the header files you downloaded from www.libtiff.org and then install the libtiff4-dev pacakge.

For libraries this is the standard convention with debian packages: if you want to compile against some lib, you'll need to install the corresponding dev pacakge.

Quote:
2) how do I get gcc to find libtiff?
There does not seem to be anything wrong with your gcc invocation, so I suspect it may just work after you've installed libtiff4-dev.

If you still have problems please post the error, and the output of the following command (will show if libtiff is really installed):
Code:
dpkg -l 'libtiff*'| grep ^ii
Cheers,

Evo2.
 
Old 11-12-2009, 08:33 PM   #4
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
Quote:
/usr/bin/ld: cannot find -ltiff
The Library used at link time is lib<name>.so .
( In rare occasions lib<name>.a )
lib<name>.so is a link to "so name" ( libtiff.so.4 )
( sometimes to "real name" ( libtiff.so.4.2.1 ))

'lib<name>.so' is provided by the package lib<name>-dev
together with the headers.
The reason for linking ( ld ) with lib<name>.so is :
You often have more than one version of a library,
and it is your descision, which one to use.

More info about shared libraries :
http://tldp.org/HOWTO/Program-Librar...libraries.html
.....

Last edited by knudfl; 11-12-2009 at 08:36 PM.
 
Old 11-12-2009, 09:44 PM   #5
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
@knudfl

Thanks for that. I'd always just assumed that the postinst script of libfoo was making the sym links. Guess I'd never experienced the OPs problem since without libfoo-dev the compile would fail, so I would never actaully see the link fail.

Evo2.
 
Old 11-13-2009, 06:07 AM   #6
richard64
LQ Newbie
 
Registered: Oct 2006
Posts: 6

Original Poster
Rep: Reputation: 0
Thanks knudfl and evo2 I've been able to get it all working again. The link to shared libraries was also a great help.

Richard
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
yum, rpm and compiling... the continued ramblings of a noob. NetDoc Red Hat 4 05-14-2009 01:49 PM
noob C++ compiling issues harkonen Programming 5 02-18-2008 01:42 AM
Help for noob and kernel 2.6.14 compiling? masterross Slackware 2 01-04-2006 06:20 PM
Compiling - Noob question Sc0rp Linux - Newbie 5 09-25-2004 06:38 AM
total noob compiling error goddamn walrus Linux - Newbie 6 10-06-2003 05:45 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 09:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration