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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:47:12+00:00 2026-05-17T16:47:12+00:00

I have a file hello.c #include<stdio.h> void hello() { printf(Hello!\n); } A header hello.h

  • 0

I have a file hello.c

#include<stdio.h>

void hello()
{
    printf("Hello!\n");
}

A header hello.h

#ifndef _hello_
#define _hello_

void hello();

#endif

main.c

#include<stdio.h>
#include "hello.h"

int main()
{

  hello();
  return 0;
}

I am currently in the folder /home/user/name/programs

I am trying to build a static library mylib.a. Here is what I do to build it

1. gcc -c hello.c 
2. ar rcs mylib.a hello.o
3. gcc -static main.c -L/home/user/name.programs -lib -o hello

I get the following error

/usr/bin/ld: cannot find -lib
collect2: ld returned 1 exit status

My questions are

`1. why is gcc searching for the file in the folder /usr/bin - I understand this is   
    what is happening ?
 2. How do I fix this?`
  • 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-17T16:47:12+00:00Added an answer on May 17, 2026 at 4:47 pm

    Change the library name to start with lib

    ar rcs libmy.a hello.o
           ^^^^^^^
    gcc -static main.c -L/home/user/name.programs -lmy -o hello
                                                  ^^^^^  
    

    And its not searching in /usr/bin,. The error is split by the linker (ld) which resides in /usr/bin.

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

Sidebar

Related Questions

I have written a simple Hello World program. #include <stdio.h> int main() { printf(Hello
I have a C file that looks like this: #include <stdio.h> int main(void) {
I have a c program #include <stdio.h> int main () { printf(Hello); } On
Here is my program: #include <stdio.h> int main(int argc, char **argv) { printf(hello world\n);
I have a library I created, File mylib.c: #include <mylib.h> int testlib() { printf("Hello,
So I have a main.py file inside /home/richard/projects/hello-python directory: import sys sys.path.append('/home/richard/projects/hello-python') from Encode
Hello ever one I have made a main function and two files one header
Please have a look on this code: #include <unistd.h> #include <stdlib.h> #include <stdio.h> int
#include<stdio.h> #include flite.h cst_voice *register_cmu_us_kal(); int main() { cst_voice *v; cst_wave *w; char *text
#include<stdio.h> #include flite.h cst_voice *register_cmu_us_kal(); int main() { cst_voice *v; cst_wave *w; char *text

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.