c - 如何使用 curses.h 为程序创建 makefile

标签 c makefile pdcurses

我正在努力使用 curses.h 为下面的示例代码制作一个 makefile。

#include <stdio.h>
#include <stdlib.h>
#include<curses.h>    

int main(){
WINDOW *initscr(void);
initscr();
int endwin(void);
return 0;
}

我在 Netbeans 中包含了库和 header ,但是当我尝试使用 makefile 构建时:

CC=C:\TDM-GCC-64\bin\gcc
CFLAGS=-std=gnu99 -Werror -Wall -lm -lncurses
DEPS=curses.h
OUTPUT=main

all:
    echo "Building all"
    $(CC) $(CFLAGS) render.c -o $(OUTPUT)

它给了我:

echo "Building all"
Building all
C:\TDM-GCC-64\bin\gcc -std=gnu99 -Werror -Wall -lm -lncurses render.c -o main
render.c:3:19: fatal error: curses.h: No such file or directory
 #include<curses.h>
                   ^
compilation terminated.
make.exe": *** [all] Error 1

BUILD FAILED(退出值2,总时间:150ms)

最佳答案

只需添加-I。 -L。对于您的 CFLAGS 宏,这会将项目库添加​​到预处理器和 linket 的搜索路径中。如果您的项目文件夹中有 curses 头文件和库文件,这应该可以工作。如果头文件或库文件位于不同的文件夹中,只需相应地修改 -I 或 -L 标志即可。

您最后的评论表明预处理和编译进行得很好,但链接器找不到库文件。

一般来说,将编译器标志放入 CFLAGS 并将链接器标志放入不同的宏是个好主意,比如 LDFLAGS。

宏 DEPS 也应该用于启用增量编译。它通常用作编译规则的依赖项,但由于您没有单独拥有它,因此您可以将它放在所有之外,例如:

all : $(DEPS)

关于c - 如何使用 curses.h 为程序创建 makefile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23745731/

相关文章:

ruby - 将 taglib 与 taglib-ruby 捆绑在一起

android - 通过命令行(Makefile)手动创建android apk

使用 clang 编译最小测试共享库

windows - Windows 7 上的 Python 3.4 中的 curses 需要什么?

c++ - pdcurses/ncurses 中的重叠窗口

c++ - cStrings 删除非字母/非空格字符 - C++

c - 悬空指针示例仍输出有效数据

c - 浮点乘法执行速度较慢,具体取决于 C 中的操作数

c - 为什么第一个字母后面有一个空格?

c - 使用 mingw 在 Linux 上将 c 编译为 (windows)exe 时出错