How can I avoid circular dependency in my Makefile compiling obj file with g++ and gcc?

Clément

I tried to create a makefile for a project that use c++ and c. I need to compile those file in order to make de .o file, but when I compile using make I have circular dependency that is dropped.

I don't know why this error occurs as I tried to separate the building of .o files that comes from .c and .o files that comes froms .cpp files.

Here is my makefile :

SRC = $(wildcard *.c)
SRC++ = $(wildcard *.cpp)
OBJ = $(SRC++:.cpp=.o) $(SRC:.c=.o)
DEP = $(SRC:.c=.d) $(SRC++:.cpp=.d)

CC=gcc
CXX=g++

CFLAGS = -Wall
CXXFLAGS = -Wall

all: $(OBJ)

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

%.cpp : %.o
    $(CXX) -c $(CXXFLAGS) $< -o $@  

# Clean the project
clean:
    @rm -f $(OBJ) $(DEP)

-include $(DEP)

Do you have any idea of what I am doing wrong ?

David Grayson

The rules you wrote are %.cpp : %.o and %.c : %.o. You wrote those rules the wrong way around. The target being built must be to the left of the colon, and the things it depends on must be to the right.

The error message tells you about a circular dependency because GNU Make defines an implicit rule where the dependencies are defined in the correct direction.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

how can I solve my compiling problem with makefile

Can not comprehend this circular dependency in Makefile

How can I solve this circular dependency?

What is a circular dependency and how can I solve it?

Circular dependency - how to resolve and avoid

How to avoid circular dependency in this project?

How to refactor this to avoid a circular dependency?

How can I avoid a circular reference situation

How can I make my Makefile build to the obj/ folder, not the src/ folder?

Circular Dependency in my .NET 5.0 C# project - how can I solve it?

How can I write my own Makefile (.mak file)?

How can I avoid filling my JavaScript code with type-checking logic when using dependency injection?

Is it possible to use gcc/g++/nvcc automatic dependency -M in a single pass of a Makefile without saving dependencies to a file?

How to avoid circular dependency with Dagger 2?

Vuerouter : need to import, but how to avoid circular dependency?

How to avoid circular dependency in multiple API healthchecks?

Circular dependency dropped in makefile

Makefile: Circular - Dependency dropped

How can i avoid circular references in type aliases

How can I avoid circular logic when synchronizing Java Threads?

How Can I Avoid Sql Circular Reference In This Instance?

How can I avoid `#pragma once in main file` in GCC when using precompiled headers?

How can i avoid the "i" dependency in this loop? Fortran

Avoid Circular Dependency injection

avoid circular dependency on hibernate

How can I make a pattern rule dependency optional in a Makefile?

How can I build a specific file with makefile?

Circular dependency detected, i can't see it

How can I load environment variables from another file in my makefile?