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

  • Home
  • SEARCH
  • 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 617107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:23:56+00:00 2026-05-13T18:23:56+00:00

I have a working setup, where all files are in the same directory (Desktop).

  • 0

I have a working setup, where all files are in the same directory (Desktop). The Terminal output is like so:

$ gcc -c mymath.c
$ ar r mymath.a mymath.o
ar: creating archive mymath.a
$ ranlib mymath.a
$ gcc test.c mymath.a -o test
$ ./test
Hello World!
3.14
1.77
10.20

The files:

mymath.c:

float mysqrt(float n) {
  return 10.2;
}

test.c:

#include <math.h>
#include <stdio.h>
#include "mymath.h"

main() {
  printf("Hello World!\n");
  float x = sqrt(M_PI);
  printf("%3.2f\n", M_PI);
  printf("%3.2f\n", sqrt(M_PI));
  printf("%3.2f\n", mysqrt(M_PI));
  return 0;
}

Now, I move the archive mymath.a into a subdirectory /temp. I haven’t been able to get the linking to work:

$ gcc test.c mymath.a -o test -l/Users/telliott_admin/Desktop/temp/mymath.a
i686-apple-darwin10-gcc-4.2.1: mymath.a: No such file or directory

$ gcc test.c -o test -I/Users/telliott_admin/Desktop/temp -lmymath
ld: library not found for -lmymath
collect2: ld returned 1 exit status

What am I missing? What resources would you recommend?

Update: Thanks for your help. All answers were basically correct. I blogged about it here.

  • 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-13T18:23:56+00:00Added an answer on May 13, 2026 at 6:23 pm

    To include the math libraries, use -lm, not -lmath. Also, you need to use -L with the subdirectory to include the library when linking (-I just includes the header for compiling).

    You can compile and link with:

    gcc test.c -o test -I/Users/telliott_admin/Desktop/temp /Users/telliott_admin/Desktop/temp/mymath.a
    

    or with

    gcc test.c -o test -I/Users/telliott_admin/Desktop/temp -L/Users/telliott_admin/Desktop/temp -lmymath
    

    where mymath.a is renamed libmymath.a.

    See link text for comments (search for “bad programming”) on the practices of using -l:

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

Sidebar

Ask A Question

Stats

  • Questions 299k
  • Answers 299k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can remove an element and add a different one.… May 13, 2026 at 7:44 pm
  • Editorial Team
    Editorial Team added an answer According to the documentation of java only a basename of… May 13, 2026 at 7:44 pm
  • Editorial Team
    Editorial Team added an answer I fixed the problem. The solution was: sudo su cd… May 13, 2026 at 7:44 pm

Related Questions

Forgive me coder for I have sinned. I put some code into a dll
I am required to develop software in English and Spanish and as such all
We've got a pretty complicated repository here, and I'm trying to get the most
I have been working with Struts for some time, but for a project I
I'm using Eclipse with Subclipse to do some perl development. The Subversion repository is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.