简体   繁体   English

在 Linux 上使用新模块编译时出现问题

[英]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 .我正在尝试编译一个包含不同模块( .h文件)的项目,所以我使用的是makefile I added a new module called semaphore_v2.h which I included in another module called connection.h .我添加了一个名为semaphore_v2.h的新模块,我将它包含在另一个名为connection.h的模块中。 connection.h is included into jack.c where the main process is. connection.h包含在主进程所在的jack.c中。 When compiling using make command, I get the following error:使用make命令编译时,出现以下错误:

在此处输入图像描述

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.似乎尽管我包含了该模块,但它没有跟踪semaphore_v2.h模块的引用,我在这里找不到问题。 What's wrong?怎么了?

makefile : 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连接.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千斤顶.c

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

You should change your makefile compilation target to include also semaphore_v2.o您应该更改您的 makefile compilation目标以包括 semaphore_v2.o

so you should have such a line at your makefile:所以你的 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.请注意 semaphore_v2.o 出现两次,一次作为此目标的依赖项,一次作为 gcc 命令的输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM