[英]Including headers in header file doesn't make it included in implementation file - or am I just using wrong command to compile?
Well, I have a header (my_prog.h) which looks like this: 好吧,我有一个标头(my_prog.h),看起来像这样:
#ifndef __MY_HEADER_H
#define __MY_HEADER_H
#include <stddef.h>
typedef struct {
size_t something;
size_t something_else;
}
void my_func();
#endif
and implementation file (my_prog.c) where I put: 和我放在其中的实现文件(my_prog.c):
#include "my_prog.h"
static size_t min(size_t a, size_t b) {...}
void my_func() {...}
When I try to compile my_prog.c to object file (I need it for linking with other files) I fet: 当我尝试将my_prog.c编译为目标文件(与其他文件链接时需要它)时,我感到:
error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘min’
The command I use for compiling is: 我用于编译的命令是:
gcc -c my_prog.c -o my_prog.h
There's no error saying that it couldn't find the source. 没有错误说它找不到源。 When I include in implementation file it compiles wihtout issues.
当我在实现文件中包含它时,它将编译所有问题。
Remove the ...
from the function body. 从功能体上拆下
...
Having them is a syntax error. 拥有它们是语法错误。
You have not given a typedef name to the structure and the ;
您尚未为该结构和the赋予typedef名称
;
is missing: 不见了:
typedef struct { size_t something; size_t something_else; } foo; ^^^^
In the compile line, following the -o
you are specifying the name of your header file. 在编译行中,在
-o
您将指定头文件的名称。 This is incorrect. 这是不正确的。 If the compilation goes fine(it will if you fix 1 and 2 above) , the compiler the wipe the original contents of
my_prog.h
and will overwrite it with the object file. 如果编译正常(如果您修复上面的1和2,它将进行编译),编译器将擦除
my_prog.h
的原始内容, my_prog.h
其用目标文件覆盖。 Instead do : 而是:
gcc -c my_prog.c -o my_prog.o
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.