Jump to content
  • Advertisement
Sign in to follow this  

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

This topic is 3697 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
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

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!