Jump to content
  • Advertisement
Sign in to follow this  
bronxbomber92

Function's prototype and it's definition in separate libs?

This topic is 3642 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is it possible to declare a function's prototype in one static library, then in another static library have the function's definition? I tried something like this: http://rafb.net/p/U88DWt47.html but line 23 has a undefined symbol linking error.

Share this post


Link to post
Share on other sites
Advertisement
What is staticlib1.a? Are you compiling the header?
How do you create those libraries?
If you are compiling from command line make sude to link in proper order.

You may find this tutorial helpful.

Try this:
Compile staticlib2.cpp:
g++ -c staticlib2.cpp
Create the library:
ar -cvq staticlib.a staticlib2.o
Use the library:
g++ main.cpp -l:staticlib.a

Edit:
Just to make it clear, the compiler needs those function prototypes (declarations) to compile the code (before linking, before libraries come into play) this is why we include the header. We tell the compiler we are going to use a function void Foo(), so it knows how to invoke Foo() and that something like Foo(10)is wrong. Thus it doesn’t make any sense to create a library from the header.

[Edited by - Kambiz on October 26, 2008 4:02:56 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!