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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:54:24+00:00 2026-05-28T19:54:24+00:00

I want my makefile to build the same binary 2 times, first compiling with

  • 0

I want my makefile to build the same binary 2 times, first compiling with gcc and then with mingw. So, I’ve written this, but it does not work:

OBJ_DIR = obj
SRC_DIR = src
BIN_DIR = bin

INCLUDE = -I./$(SRC_DIR)
LIBS = 

_SRCS = print_current_dir.c test_main.c
_OBJS = print_current_dir.o test_main.o

SRCS = $(addprefix $(SRC_DIR)/,$(_SRCS))
OBJS = $(addprefix $(OBJ_DIR)/,$(_OBJS))

all: $(BIN_DIR)/pps-linux $(BIN_DIR)/pps-win32

$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
    $(CC) -c -o $@ $< $(CFLAGS)

$(BIN_DIR)/pps-linux: CC = cc
$(BIN_DIR)/pps-linux: CFLAGS = -g -Wall $(INCLUDE) $(LIBS)
$(BIN_DIR)/pps-linux: $(OBJS)
    $(CC) $(CFLAGS) $(OBJS) -o $@

$(BIN_DIR)/pps-win32: CC = i586-mingw32msvc-cc
$(BIN_DIR)/pps-win32: CFLAGS = -g -Wall $(INCLUDE) $(LIBS)
$(BIN_DIR)/pps-win32: $(OBJS)
    $(CC) $(CFLAGS) $(OBJS) -o $@

Once it compiles the objects file in $(OBJS) with gcc for the target pps-linux, it tries to build pps-win32 with the very same objects file, obviously failing, and despite the fact that I redefined CC and CFLAGS for the target pps-win32.
Here is the output:

$ make
cc -c -o obj/print_current_dir.o src/print_current_dir.c -g -Wall -I./src 
cc -c -o obj/test_main.o src/test_main.c -g -Wall -I./src 
cc -g -Wall -I./src  obj/print_current_dir.o obj/test_main.o -o bin/pps-linux
i586-mingw32msvc-cc -g -Wall -I./src  obj/print_current_dir.o obj/test_main.o -o bin/pps-win32
obj/print_current_dir.o: In function `print_dir':
/home/matteo/Desktop/pps/src/print_dir.c:23: undefined reference to `get_current_dir_name'
/home/matteo/Desktop/pps/src/print_dir.c:25: undefined reference to `puts'
/home/matteo/Desktop/pps/src/print_dir.c:27: undefined reference to `free'
/usr/lib/gcc/i586-mingw32msvc/4.4.4/../../../../i586-mingw32msvc/lib/libmingw32.a(main.o):(.text+0x85): undefined reference to `_WinMain@16'
collect2: ld returned 1 exit status
make: *** [bin/pps-win32] Error 1

How do I force the recompilation of the objects file just compiled with a different compiler?

Thank you.

  • 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-28T19:54:25+00:00Added an answer on May 28, 2026 at 7:54 pm

    By making the object files compiler-dependent too, rather than trying to overwrite the same .o file in place with different contents, eg.

    LINUX_OBJS = $(addprefix $(LINUX_OBJ_DIR)/,$(_OBJS))
    ...
    $(BIN_DIR)/pps-linux: $(LINUX_OBJS)
    

    NB. you may be able to do it more tidily by just using a target-dependent definition of OBJ_DIR, ie,

    $(BIN_DIR)/pps-linux: OBJ_DIR = linux-obj
    

    but I’d have to try it to be sure.

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

Sidebar

Related Questions

I want my Makefile to be as simple as possible and still function. This
I have used -Wall -Werror in my Makefile but I want to disable following
Want the function to sort the table by HP but if duplicate HPs then
This is my first time using CMake and I'm trying to build QJSon, a
I want to use a temp directory that will be unique to this build.
i have a small java project i want to build using a makefile, the
I have a Makefile from which I want to call another external bash script
I'm writing a custom makefile project using QtCreator and I want to delete a
I want to display current build(hg revision) number in the about box of my
I am creating a Makefile which I want it to be a single file

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.