LinuxQuestions.org
Visit Jeremy's Blog.
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 12-10-2009, 04:06 PM   #1
glyn
LQ Newbie
 
Registered: Dec 2009
Posts: 2

Rep: Reputation: 0
Shared library - error when compiling


I have a function func.h that I am trying to compile into a shared library so that it can be linked to in other functions. I run the command

g++ -fPIC -shared /obj/func.o -o /lib/libFunction.so

which is fine, and then when I try to compile my function main.cpp (which has a line in it, #include "func.h"), and link it to this library, using the command

g++ -I/include -g -lm -fPIC -Wall -lFunction main.cpp -o /bin/main

I get the error:

In function 'main':
main.cpp:51: undefined reference to 'func(args)'

I have double checked to make sure that main has a #include line with the func.h header in it, and that the arguments listed in the error for the function func are consistent with what is being attempted, but everything seems fine. Am I somehow linking incorrectly or missing an important flag? Thanks in advance for your help.
 
Old 12-10-2009, 04:55 PM   #2
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,539

Rep: Reputation: 60
Is "func()" also implemented? That is, do you have more than just its prototype?
 
Old 12-10-2009, 06:25 PM   #3
glyn
LQ Newbie
 
Registered: Dec 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by nadroj View Post
Is "func()" also implemented? That is, do you have more than just its prototype?
func() is implemented, but I noticed in the header it is implemented as

func( const vector< double > &input )

whereas in the cpp file it is given as

func( vector< double > &input )

I didn't even think to check this - and now it compiles. Thanks for your help!
 
Old 12-10-2009, 06:35 PM   #4
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,539

Rep: Reputation: 60
Its sometimes easy to overlook things like this, and assume its a more complicated issue at hand. Therefore, its always good to check the prototype against its implementation (or do a copy/paste when you implement the prototype to make sure its the same). Good to see you got it working now.
 
  


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
Error during making a shared library smartgupta Solaris / OpenSolaris 1 11-09-2009 09:21 AM
shared library : libfg.so: cannot open shared object file error 40 x_gaurav Programming 2 06-28-2009 06:29 AM
Shared library error an_sush Linux - Newbie 7 01-09-2009 09:26 AM
cross compiling a shared library baba_gorakhnath Linux - Laptop and Netbook 0 03-10-2005 11:02 PM
Shared library error olscratch Slackware 3 11-05-2004 03:46 PM

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

All times are GMT -5. The time now is 10:36 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