Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8932759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:22:57+00:00 2026-06-15T09:22:57+00:00

I followed the following tutorials to create a static library. http://tldp.org/HOWTO/Program-Library-HOWTO/static-libraries.html http://www.adp-gmbh.ch/cpp/gcc/create_lib.html http://www.cs.dartmouth.edu/~campbell/cs50/buildlib.html I

  • 0

I followed the following tutorials to create a static library.

http://tldp.org/HOWTO/Program-Library-HOWTO/static-libraries.html

http://www.adp-gmbh.ch/cpp/gcc/create_lib.html

http://www.cs.dartmouth.edu/~campbell/cs50/buildlib.html

I generated a static library in C using the ar tool. The library is from a different directory. I am generating the library properly, and I’m using it to compile with my program as follows:

gcc -lpthreads main.c -o server -L thread-pool -lthreadpool

The library under the current directory is called thread-pool which contains libthreadpool.a.

According to the tutorials, I need to include my .h file as follows in main.c: #include "threadpool.h". GCC is throwing an error saying threadpool.h is not found. That is obvious since it’s in a different directory.

When I include is as: #include threadpool/threadpool.h" it compiles but doesn’t actually work. It still does not recognise the functions. I’m not sure why this is happening. I thought when compiling a static library, you do not need to actually send the .h file or any source as a matter of fact.

What is the issue here? How can I overcome this?

EDIT:

I know .h files are not the same as static libraries. I’m not sure why what I said above make it seem as if I’m confused between both.

Anyway, so when one uses a static library, does it mean we also need the .h file and include it into the source, and not just compile the program with the static library?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:22:58+00:00Added an answer on June 15, 2026 at 9:22 am

    As Michael Burr said, the #include of the .h file, and the linking with the library file, are two different (but related) things.

    When you build a C program that consists of several parts, such as several .c source files, or libraries, the process is done in two steps. First the individual source .c files are compiled, that is, translated from the C source to modules of executable machine instructions. Then all the modules and libraries needed for the program are linked together, building the executable file.

    The difference between static and dynamic linking is just when the linking is done. Conceptually they are the same thing, but static linking (with a static library) is done in advance, forming an executable file that can be run at a later time, and dynamic linking is done immediately before execution.

    The type of linking (static or dynamic) doesn’t at all affect the compilation step.

    During compilation of an individual source file, the compiler needs to generate code for the calls to the library functions. For example, if a library contains a function f that takes a double as argument, and the source file contains the code f(7), the compiler needs to know that there is a function called f, and that it expects a double as argument, so the compiler can generate code that converts the integer 7 to a double, before actually calling the function f.

    This is done by putting function declarations in a .h file, which is then included in your .c source file. For example, that declaration might look like this:

    void f(double);
    

    This makes the compiler able to generate the correct code, and also to give the correct warnings and error messages if there is something wrong.

    The library, on the other hand, contains the compiled function definition, which is the actual code for the function that does something.

    Note that the compilation step has very little to do with the library file, and nothing to do with the difference between static or dynamic linking. To be able to #include the .h file, the compiler needs to know where to find the .h file. That may be in a completely different place from the actual library file. The library file doesn’t even have to be present on the same computer, or even exist at all. When the #include is performed, the actual functions in the library might not have been written yet.

    One source of confusion could be that the gcc command,

    gcc -lpthreads main.c -o server -L thread-pool -lthreadpool
    

    looks like it performs both compilation and linking. It does, but that is just for convenience, and behind the scenes it is still done in two separate steps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've followed this tutorial to try to add a template to Visual Studio: http://www.switchonthecode.com/tutorials/visual-studio-how-to-create-item-templates
I have followed the instructions at http://www.javacodegeeks.com/2011/01/advanced-smartgwt-tutorial-part-1.html and tried to create a simple screen
I followed the following tutorial to help me create a datagrid ( http://www.asp.net/web-pages/videos/aspnet-razor-pages/displaying-data-in-a-grid ),
I am learning .net and writing a service by following the tutorial below http://www.beansoftware.com/NET-Tutorials/Create-Windows-Services.aspx
I've followed these tutorials and produced the following. http://www.youtube.com/playlist?list=PL54DB126285ED0420 Main.java: public class Main extends
I've tried following this tutorial (http://www.raywenderlich.com/4666/how-to-create-a-hud-layer-with-cocos2d) however as you can probably tell I'm not
I'm following two tutorials from Google: http://code.google.com/apis/maps/articles/phpsqlgeocode.html http://code.google.com/apis/maps/articles/phpsqlajax_v3.html#createmap I have the first tutorial working
I'm learning masm32, following some tutorials. In one tutorial: http://win32assembly.online.fr/tut3.html there is stated: LOCAL
So I followed this tutorial from Google: http://developer.android.com/resources/tutorials/opengl/opengl-es20.html The triangle is supposed to rotate
I have followed this tutorial: http://www.phpjabbers.com/how-to-make-a-php-calendar-php26-6.html#comments to make a very basic calendar. My aim

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.