user157629
user157629

Reputation: 634

Issue compiling with a new module on Linux

I'm trying to compile a project that contains different modules (.h files) so I'm using a makefile. I added a new module called semaphore_v2.h which I included in another module called connection.h. connection.h is included into jack.c where the main process is. When compiling using make command, I get the following error:

enter image description here

Seems like despite I included the module, it doesn't keep track of the references of the semaphore_v2.h module and I can't find the issue here. What's wrong?

makefile:

all: compilation

jack.o: jack.c
    gcc -c jack.c -Wall -Wextra
semaphore_v2.o: semaphore_v2.c semaphore_v2.h
    gcc -c semaphore_v2.c -Wall -Wextra
files.o: files.c files.h
    gcc -c files.c -Wall -Wextra
connection.o: connection.c connection.h
    gcc -c connection.c -Wall -Wextra
compilation: jack.o files.o connection.o
    gcc jack.o connection.o files.o -o jack -Wall -Wextra -lpthread

connection.h

#ifndef _CONNECTION_H_
#define _CONNECTION_H_

#include <unistd.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <time.h>

#include "files.h"

#include <ctype.h>
#include <pthread.h>

#include <sys/wait.h>
#include <sys/ipc.h>
#include <sys/shm.h>

#include "semaphore_v2.h"

typedef struct {
    int socketfd;
    int memid;
    semaphore *sinc;
}thread_input;

...

jack.c

#include <signal.h>
#include "connection.h"
...

Upvotes: 0

Views: 60

Answers (1)

Eliyahu Machluf
Eliyahu Machluf

Reputation: 1401

You should change your makefile compilation target to include also semaphore_v2.o

so you should have such a line at your makefile:

compilation: jack.o files.o connection.o semaphore_v2.o

    gcc jack.o connection.o files.o semaphore_v2.o -o jack -Wall -Wextra -lpthread

Note semaphore_v2.o appears twice, one time as a dependency to this target and one time as input to the gcc command.

Upvotes: 1

Related Questions