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 6963265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:46:00+00:00 2026-05-27T15:46:00+00:00

I have some trouble with the placement of the -l option when using gcc

  • 0

I have some trouble with the placement of the -l option when using gcc. Here’s a stripped down version for reproduce the problem.

t.c:

#include <pthread.h>

int main() {
    pthread_create(0, 0, 0, 0);
}

and in terminal:

$ gcc -lpthread t.c  
/tmp/ccmkwV7B.o: In function `main':  
t.c:(.text+0x29): undefined reference to `pthread_create'  
collect2: ld returned 1 exit status

$ gcc t.c -lpthread  
$ (compiles ok)

Why do I have to put -lpthread in the end to make it work? And it seems that this problem only occurs on 32bit linux.

My environment info is attached below:
gcc -lpthread t.c fails on this machine.

$ gcc --version  
gcc (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1  

$ uname -rm  
3.0.0-12-generic i686

gcc -lpthread t.c works on this machine.

$ uname -rm  
2.6.18-274.3.1.el5 x86_64  

$ gcc --version  
gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-51)  

I looked up the gcc manual, and it says that “the placement of -l is significant”. What exactly does it mean?

  • 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-05-27T15:46:01+00:00Added an answer on May 27, 2026 at 3:46 pm

    From the manual,

    It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, foo.o -lz bar.o searches library z after file foo.o but before bar.o. If bar.o refers to functions in z, those functions may not be loaded.

    This means it is very interesting that linking the library first works on gcc 4.1.2. This might have to do with the default libraries linked to by the compiler. I know on some installations I don’t need to explicitly link to pthreads.

    On further reflection, I think the issue is with the flag --as-needed, which may be on by default in your gcc 4.6 system. See this link for some discussion.

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

Sidebar

Related Questions

I have some trouble using decltype for member function pointers: #include <iostream> #include <type_traits>
I have some trouble with my trac installation (version 11.4). What should I do
I'm have some trouble with the fulltext CONTAINS operator. Here's a quick script to
i have some trouble here with my server and app.. so i want to
I have some trouble with creating window application using PyQt. For example: we have
I have some trouble understanding this one so here it is. I'm trying to
I have some trouble with using authlogic in my rails app, so I began
I have some trouble reading from an ini file using boost program options. The
I have some trouble using an Ajax query in a Rails + JQuery ecosystem.
I have some trouble with using enum types in signals. Basicly I have two

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.