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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:36:45+00:00 2026-05-27T08:36:45+00:00

I am trying to build a shared library with one set of code, and

  • 0

I am trying to build a shared library with one set of code, and everything works, except for this issue with my Makefile. Here’s my (simplified) Makefile thus far:

OBJS = bar.o

libfoo.so:    OS = LINUX      # These don't seem to happen
libfoo.dll:   OS = WINDOWS

# Linux
ifeq ($(OS), LINUX)
CC = gcc
...

# Windows
else ifeq ($(OS), WINDOWS)
CC = i686-pc-mingw32-gcc
...
endif


all: libfoo.so libfoo.dll

libfoo.so: clean $(OBJS)
    ...

libfoo.dll: clean $(OBJS)
    ...


bar.o: bar_$(OS).c bar.h
    ...

So, when you type make libfoo.so, I expect it to set OS = LINUX first. Then, when it gets to bar.o (it is a dependency of libfoo) it should know which bar_$(OS).c to use. However, I get the error:

make: *** No rule to make target `bar_.c', needed by bar.o. Stop.

Which tells me that when it tries to make bar.o, $(OS) is not set. But shouldn’t that be the first thing that happens when I try to make libfoo.so, and that rule is evaluated?

  • 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-27T08:36:45+00:00Added an answer on May 27, 2026 at 8:36 am

    If you want to set a target-specific variable, and then have that variable available outside the body of that rule, you can recursively call the Makefile, after exporting the variable:

    OBJS ?= foo.o                    # Use ? so it isn't blown away on recursive call
    
    libfoo.so: OS = LINUX
    libfoo.so: OBJS += linux_only.o
    libfoo.so:
        $(MAKE) -s build_libfoo_linux
    
    build_libfoo_linux: $(OBJS)
        @echo "OS = $(OS)"           # Should print "OS = LINUX"
    
    export OS                        # Can be anywhere
    

    You have to remember to export the variables you want to “persist” after the recursive make call. And also, as shown above, if you append to any variables before the call, you’ll want to make their initial assignment with ?= so they aren’t set the second time.

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

Sidebar

Related Questions

I've making a shared library (cross-platform), but when trying to compile the Windows build
I'm trying to build 5.6.4-labs-innodb-memcached, but having this issue: # cmake ./ -- MySQL
I am trying to build libraw as a Android shared library. It looks the
I'm trying to build a client server application using POSIX shared memory and POSIX
I am trying to setup a shared authentication system on a build server. We
I'm trying build a method which returns the shortest path from one node to
Trying to build sslsniff on a RHEL 5.2 system here. When compiling sslsniff on
I'm trying to do a debug build of the Rabbyt library using mingw's gcc
I am pulling the hair out of my head trying to figure this one
I'm trying to build a simple Android application using NDK. Here are the contents

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.