Welcome to Linux Forums! With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.
Find the answer to your Linux question:
New to Linux Forums? Register here for free!
    Linux Forums > The Community > Everything BSD > problem with static library linking

Forgot Password?
 Everything BSD   For all discussions regarding Free/NetBSD and OpenBSD.

Site Navigation
Linux Articles
Linux Forums
Linux Downloads
Linux Hosting
Free Magazines
Job Board
IRC Chat
RSS Feeds


Linux Forum Topics
Linux Forums
Your Distro
Linux Resources
GNU Linux Zone
The Community
Reply
 
Thread Tools Display Modes
Old 03-25-2008   #1 (permalink)
Just Joined!
 
Join Date: Mar 2008
Posts: 2
problem with static library linking

Hi All,

I have a problem with the linking as explained below.


I created a new library mylib.a which uses a function func() present in the already existing library libpcap.a.

When I build mylib.a I did not see any error.

But when I build mylib.a with an executable I got a linking error of undefined reference to the function func(). Thi error was shown in a file which is present in mylib.a

On my link line I have tried the following order of linking.

1. libpcap.a mylib.a
2. mylib.a libpcap.a

But I am still having this error.

Could you please help me out.

Regards
-Harish
send2harish is offline  


Reply With Quote
Old 03-27-2008   #2 (permalink)
Just Joined!
 
Join Date: Mar 2008
Posts: 2
Smile Re:problem with static library linking

I have resolved the error.

The reason is the way I was including the header file.

The function func() present in the file ipv6hdrs.h( definition in ipv6hdrs.c) and in the library libpcap.a

In the library mylib.a and in the file test.cc I included ipv6hdrs.h as below

#include "ipv6hdrs.h"


Later I noticed that the definition of func() is present in the .c file rather than .cc file.

So I changed the header file inclusion to

extern C
{
#include "ipv6hdrs.h"
}

and it worked. I could build my executable properly.
send2harish is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Free Magazines
Run Your Own Web Server Using Linux & Apache - Free 191 Page Preview
Learn about everything you'll need to build and maintain your Linux servers, and to deploy Web applications to them.
subscribe
Open Source Security Myths Dispelled
Dispel the five major myths surrounding Open Source Security and gain the tools necessary to make a truly informed decision for your IT organization
subscribe
InformationWeek
InformationWeek is the only newsweekly you'll need to stay on top of the latest developments in information technology.
subscribe



All times are GMT. The time now is 12:53 PM.






© 2000 - 2009 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.3.0 RC2