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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:14:09+00:00 2026-05-28T02:14:09+00:00

I have a Makefile that I use to build executable on mac os x,

  • 0

I have a Makefile that I use to build executable on mac os x, using mpicc compiler, linking mkl_lapack.h library.
Now this Makefile is perfectly working, the only problem is that I don’t know what to add if I want to compile Eigenvalues.c linking other .c files, if I want to link myfile.c where do I have to write it in Makefile?

MKL_INCLUDE=/opt/intel/mkl/include
MKLROOT=/opt/intel/mkl/lib

CC = mpicc
LD = mpicc
IFLAGS = -I$(MKL_INCLUDE)
CFLAGS = -Wall -O2 $(IFLAGS) -std=c99

LFLAGS =  $(MKLROOT)/libmkl_intel_lp64.a $(MKLROOT)/libmkl_sequential.a    $(MKLROOT)/libmkl_core.a  -lpthread -lm 

PROGRAMS = Eigenvalues

all: $(PROGRAMS)

Eigenvalues: 
    $(CC) $(CFLAGS) -o $@ $^ $(LFLAGS) 

%.o: %.c
    @echo C compiling $@
    $(CC) -c $(CFLAGS) -o $@ $<

clean:
    rm -rf *.o $(PROGRAMS)

Eigenvalues: Eigenvalues.c
  • 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-28T02:14:09+00:00Added an answer on May 28, 2026 at 2:14 am

    Simply have the Eigenvalues target depend on all the .o files (not the .c files, as you have!) that make up the application. Conventionally, the list of these objects is put in a variable:

    PROGRAMS = Eigenvalues
    Eigenvalues_OBJS = Eigenvalues.o foo.o bar.o #etc
    
    all: $(PROGRAMS)
    
    Eigenvalues: $(Eigenvalues_OBJS)
            $(CC) $(CFLAGS) -o $@ $^ $(LFLAGS) 
    
    # delete the "Eigenvalues: Eigenvalues.c" line,
    # leave everything else as you have it
    

    By the way, since you are using the standard variable names $(CC) and $(CFLAGS), you can leave out the %.o: %.c rule entirely; Make has a built-in rule that does the same thing.

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

Sidebar

Related Questions

I have the following makefile that I use to build a program (a kernel,
I have a Makefile that looks like this CXX = g++ -O2 -Wall all:
I have a working makefile that builds with mingw32. Now i renamed that makefile
I have a makefile project that builds and links a DLL, using the command-line
I have a section of makefile that has this sort of structure: bob: ifdef
Some Background I have been using Git for a while now. The projects that
I have this large C++ project that I need to build on a platform
I have this C++ project which compiles using a Makefile, and sometimes when (
I have a Makefile , that has variables version and build (those are not
I have a project that has a makefile with broken dependencies. Is there any

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.