LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-28-2015, 07:35 AM   #1
shogun1234
Member
 
Registered: May 2004
Posts: 226

Rep: Reputation: 15
collect2: error: ld returned 1 exit status


A newbie programming question.

When compiling a program with command
Code:
gcc -o test test.c
gcc complains
Code:
/tmp/ccYeJqKe.o: In function `main':
test.c:(.text+0x12): undefined reference to `npth_init'
collect2: error: ld returned 1 exit status
The source is attached
Code:
#include <npth.h>

int main(int argc, char** argv) 
{

  npth_init ();
  
  return 0;
}
I am sure the library is installed. Package manager display
Code:
sudo dpkg -S npth.h
libnpth0-dev: /usr/include/npth.h
Adding -I/usr/include doesn't help.

My environment: gcc (Debian 4.9.2-10) 4.9.2, kernel: 4.0.0-2-rt-686-pae

How should I fix this error?

Thanks

Last edited by shogun1234; 08-29-2015 at 09:55 PM.
 
Old 08-28-2015, 08:14 AM   #2
shogun1234
Member
 
Registered: May 2004
Posts: 226

Original Poster
Rep: Reputation: 15
The problem is solved by adding -lnpth.
Code:
gcc -o test -lnpth test.c
So the above command fixes the problem.
Thanks

Quote:
Originally Posted by shogun1234 View Post
A newbie programming question.

When compiling a program with command
Code:
gcc -o test test.c
gcc complains
Code:
/tmp/ccYeJqKe.o: In function `main':
test.c:(.text+0x12): undefined reference to `npth_init'
collect2: error: ld returned 1 exit status
The source is attached
Code:
#include <npth.h>

int main(int argc, char** argv) 
{

  npth_init ();
  
  return 0;
}
I am sure the library is installed. Package manager display
[code]
sudo dpkg -S npth.h
libnpth0-dev: /usr/include/npth.h
[code]

Adding -I/usr/include doesn't help.

My environment: gcc (Debian 4.9.2-10) 4.9.2, kernel: 4.0.0-2-rt-686-pae

How should I fix this error?

Thanks
 
Old 08-28-2015, 12:59 PM   #3
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Note: always be precise when describe the problem: you had a linkage problem, not a compilation problem.

When you see the words: collect2 and/or ld then it is a linkage problem,
 
Old 08-29-2015, 09:56 PM   #4
shogun1234
Member
 
Registered: May 2004
Posts: 226

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by NevemTeve View Post
Note: always be precise when describe the problem: you had a linkage problem, not a compilation problem.

When you see the words: collect2 and/or ld then it is a linkage problem,
Thanks. I've updated so the question would be more precise.
 
Old 05-30-2019, 01:09 PM   #5
johnbstroud
LQ Newbie
 
Registered: May 2019
Posts: 1

Rep: Reputation: Disabled
Thumbs up GCC is just awesome like that.

gcc file.c -o file -lm
best of luck !
 
1 members found this post helpful.
  


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
C++ undefined reference grob115 Programming 4 01-22-2013 11:22 AM
Undefined reference to: ashlesha Programming 5 11-08-2006 01:07 PM
undefined reference? Sharky01252 Programming 3 11-07-2006 11:36 AM
Undefined Reference ChemicalBurn Programming 2 02-14-2005 03:01 AM
undefined reference mp4-10 Programming 3 01-25-2005 12:38 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:04 AM.

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