我一直在用 C(在 Linux 下)开发一个需要另一个模块(头文件在其他目录中)的模块。 我的问题是,当我使用 Makefile 编译代码时,gcc 编译器告诉我找不到某些 header 。
gcc -c render.c
所以我包含了目录来查找标题,但是在这里,gcc 试图找到不存在的“main”函数:它是一个模块...
gcc /opt/vc/include -c render.c
所以我想知道如何编译一个需要其他模块的模块(在 module.o 中输出)?
这是我的文件:
渲染.c:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "render.h"
int width,height;
int loop,counter;
int initRender(void(*setup)(void),void(*draw)(void),void(*end)(void))
{
init(&width, &height);
loop = -1;
counter = 0;
setup();
while(loop==-1)
{
Start(width, height);
draw();
End();
counter++;
}
end();
finish();
exit(0);
return 0;
}
渲染.h:
#include "VG/openvg.h"
#include "VG/vgu.h"
#include "fontinfo.h"
#include "shapes.h"
#ifndef RENDER_H_
#define RENDER_H_
extern int width,height;
extern int loop,counter;
int initRender(void(*setup)(void),void(*draw)(void),void(*end)(void));
#endif
生成文件:
INCLUDEFLAGS=-I/opt/vc/include -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/interface/vcos/pthreads -IopenVG
LIBFLAGS=-L/opt/vc/lib -lGLESv2 -lEGL -lbcm_host -lpthread -ljpeg -LopenVG
NEEDED= openVG/libshapes.o openVG/oglinit.o
all: render
render.o: render.c
gcc -Wall -g $(INCLUDEFLAGS) -c render.c
最佳答案
你可能想要
gcc -Wall -g -I/opt/vc/include -c render.c
这将产生一个 render.o
目标文件。
请花时间阅读有关invoking GCC 的文档强>。特别是检查每个选项的内容 -Wall
, -g
, -I
和 -c
方法。恕我直言,前两个非常重要。
稍后,您可能希望将所有目标文件与一些外部库链接到一个可执行文件中。也许你想要类似的东西
gcc -g -Wall -L/opt/vc/lib render.o main.o -lvc -o myprogram
(您确实想要 -Wall
和-g
选项;恕我直言,您需要成为专家才能敢于避免它们;一旦您调试了程序并想对其进行基准测试,添加 -O2
进行优化)
但当然,您需要其他选择。
注意 gcc
的参数顺序很重要很多
当然,您应该了解GNU make 并且您需要使用它。参见 this和 that例子。您可以使用 make --trace
(最近 make
)或 remake调试你的 Makefile
(这不好)。您还应该运行一次 make -p
了解更多 make
的内置规则.
也许你想要一个图书馆,然后阅读 Program Library HowTo .
关于c - GCC Linux C - 找不到编译对象头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34579595/