我已经尝试制作正确的 makefile 一段时间了,但我不断收到错误
“make:*** 没有规则可以使目标‘全部’。停止。”
我有一个主程序:mpasswdsort.c 和 mpasswdsort 使用的 c 文件,它还带有一个标头:list.c 和 list.h
我的生成文件:
CC=gcc
CFLAGS=-Wall -pedantic -ansi
all: mpasswdsort
server: mpasswdsort.o list.o
$(CC) mpasswdsort.o list.o -o mpasswdsort
mpasswdsort.o: mpasswdsort.cpp
$(CC) $(CFLAGS) mpasswdsort.cpp
list.o: list.cpp
$(CC) $(CFLAGS) list.cpp
clean:
rm -f server client *.o core
Run Code Online (Sandbox Code Playgroud)
我不确定 makefile 是否错误或者 makefile 是否不应该是 .txt 文件。
我正在尝试构建我的程序,但不断收到相同的错误消息:
undefined reference to pthread_create
undefined reference to pthread_join
Run Code Online (Sandbox Code Playgroud)
我已包含 pthread.h 并在我的 makefile 中使用-pthread.
int threadAmount = strtol(nrthr, NULL, 0);
threadAmount--;
if(threadAmount > 0){
pthread_t tids[threadAmount];
for(int i = 0;i < threadAmount; i++){
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_create(&tids[i],&attr,search,&t1);
}
for(int i = 0;i < threadAmount; i++){
pthread_join(tids[i],NULL);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我在抱怨的地方调用 create 和 join 的地方。可能是什么问题呢?
用于构建的 makefile:
CC=gcc
CFLAGS= -pthread -std=gnu11 -Wall -Wextra -Werror -Wmissing-declarations -Wmissing-prototypes -Werror-implicit-function-declaration -Wreturn-type -Wparentheses -Wunused -Wold-style-definition -Wundef -Wshadow -Wstrict-prototypes -Wswitch-default -Wunreachable-code
all: mfind
list.o: list.c …Run Code Online (Sandbox Code Playgroud) 我需要在两个Htree之间进行比较并且这样做我实现了我自己的比较函数,它与sortBy一起使用,但是我想实现Eq和Ord类的派生实例,但是需要覆盖所有可能组合的案例量使它成为现实不切实际的.
data Htree a b = Leaf a b
| Branch a (Htree a b) (Htree a b)
deriving (Show)
instance (Eq a) => Eq (Htree a b) where
(Leaf weight1 _ ) == (Leaf weight2 _) = weight1 == weight2
(Branch weight1 _ _) == (Leaf weight2 _) = weight1 == weight2
(Leaf weight1 _ ) == (Branch weight2 _ _) = weight1 == weight2
(Branch weight1 _ _) == (Branch weight2 _ _) = weight1 == weight2
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我只想比较Htree的一个部分,它将是实际代码中的Integer,我需要为它编写四个案例.有没有办法概括这个,所以我只能在一个案例中写它?如果我比较两个Htree,比较他们的整数部分? …
我希望将两个字符之间的加法定义为隐含性,但不确定如何正确执行。
我的尝试:
instance Num Char where
(+) (a) (b) = [a] ++ [b]
Run Code Online (Sandbox Code Playgroud)
但是我得到的错误是返回类型不是预期的类型。
如前所述,我的预期输出是将两个字符叠加而成的字符列表。