LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-04-2017, 11:39 AM   #1
Mark_667
Member
 
Registered: Aug 2005
Location: Manchester, England
Distribution: Ubuntu 17.04
Posts: 307

Rep: Reputation: 25
Linking to zlib


I'm getting a build fail with:
/usr/bin/ld: cannot find -lxyz
I've got zlib and the exact same version of zlib-devel installed.
After some Googling I did:
Code:
ld -lzlib --verbose
at the end of the output were a lot of failed attempts to open .a and .o files which aren't on disk. Is there something wrong with my zlib install?
 
Old 12-04-2017, 01:27 PM   #2
ccj4467
LQ Newbie
 
Registered: Jan 2009
Posts: 19

Rep: Reputation: 4
Quote:
Originally Posted by Mark_667 View Post
I'm getting a build fail with:
/usr/bin/ld: cannot find -lxyz
I've got zlib and the exact same version of zlib-devel installed.
After some Googling I did:
Code:
ld -lzlib --verbose
at the end of the output were a lot of failed attempts to open .a and .o files which aren't on disk. Is there something wrong with my zlib install?
Pretty sure the actual file for zlib is libz.so and/or libz.a

The proper command would be

Code:
ld -lz --verbose
The ld command will pre-pend lib to anything specified by the -l option.
 
1 members found this post helpful.
Old 12-04-2017, 02:13 PM   #3
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 702

Rep: Reputation: 286Reputation: 286Reputation: 286
Quote:
Originally Posted by Mark_667 View Post
I'm getting a build fail with:
/usr/bin/ld: cannot find -lxyz
Couple of questions:
  • What are you trying to build?
  • Why is the linker looking for libxyz?

As @ccj4467 says zlib is libz.so

A better (or less cluttered) way to check if the linker can see a library is to use ldconfig:
Code:
# lsb_release -rc
Release:	17.10
Codename:	artful

# ldconfig -p | grep libz.so
    libz.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/libz.so.1
    libz.so (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libz.so

# ls -l /usr/lib/x86_64-linux-gnu/libz.so
lrwxrwxrwx 1 root root 36 May 23  2017 /usr/lib/x86_64-linux-gnu/libz.so -> /lib/x86_64-linux-gnu/libz.so.1.2.11
 
Old 12-05-2017, 05:00 AM   #4
Mark_667
Member
 
Registered: Aug 2005
Location: Manchester, England
Distribution: Ubuntu 17.04
Posts: 307

Original Poster
Rep: Reputation: 25
>What are you trying to build?
A C++ app which uses zlib libraries for compression.

>Why is the linker looking for libxyz?
These are libraries that use zlib.

ldconfig -p | grep libz
libzypp.so.908 (libc6,x86-64) => /usr/lib64/libzypp.so.908
libzio.so.0 (libc6,x86-64) => /usr/lib64/libzio.so.0
libz.so.1 (libc6,x86-64) => /lib64/libz.so.1
libz.so.1 (libc6) => /lib/libz.so.1
libz.so (libc6,x86-64) => /usr/lib64/libz.so

Does this output mean anything to anyone?
 
Old 12-05-2017, 05:30 PM   #5
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 702

Rep: Reputation: 286Reputation: 286Reputation: 286
Quote:
Originally Posted by Mark_667 View Post
Does this output mean anything to anyone?
Sure. Part of it means that zlib is installed on your system and the linker sees it.

The title of your post has "linking to zlib" but the error that you posted says that the linker can't find libxyz.

In order to help we're going to need more information; like the command or the Makefile you are using to compile.

Perhaps a simple example that does nothing will help:
Code:
$ cat main.cpp 
#include <zlib.h>

int main() { 
    gzFile out = gzopen("foo.gz", "wb");
}

$ g++ main.cpp 
/tmp/ccHwh37Z.o: In function `main':
main.cpp:(.text+0x17): undefined reference to `gzopen'
collect2: error: ld returned 1 exit status

$ g++ main.cpp -lxyz
/usr/bin/ld: cannot find -lxyz
collect2: error: ld returned 1 exit status

$ g++ main.cpp -lz

$ ls -ln
total 16
-rwxr-xr-x 1 1000 1000 8400 Dec  5 16:20 a.out
-rw-r--r-- 1 1000 1000   76 Dec  5 16:15 main.cpp
 
1 members found this post helpful.
Old 12-12-2017, 05:51 AM   #6
Mark_667
Member
 
Registered: Aug 2005
Location: Manchester, England
Distribution: Ubuntu 17.04
Posts: 307

Original Poster
Rep: Reputation: 25
Luckily this turned out to not be zlib related, instead being due to missing .o files in other libraries it was trying to use. Don't know what those errors are about in teh output but they don't seem to be affecting anything.
 
  


Reply

Tags
gcc, zlib


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] issue linking .SO "g++: -lcyusb: linker input file unused because linking not done" rohaanembedded Red Hat 5 07-26-2013 02:14 AM
Static linking vs. dynamic linking? posix_memalign Programming 13 04-18-2010 03:27 PM
no matching comp found: client zlib none, zlib@openssh.com lost connection jorge_ivan Linux - Networking 0 08-14-2006 08:09 PM
Problem in using both load time linking and runtime linking durgaprasad_j Linux - General 0 08-01-2006 04:49 AM
zlib m2azer Linux - Newbie 1 09-16-2005 05:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:56 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration