我有 main.c、snmpy.c、snmpy.o 和一个 makefile。我通过命令行在 Linux 服务器上运行它。这是所有这些...
主.c:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "snmpy.h"
int main(void) {
char* message = sayHello();
printf("%s", message);
return 0;
}
snmpy.c:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "snmpy.h"
char* sayHello(){
char* hiya = "Hello!!\n";
return hiya;
}
snmpy.h:
char* sayHello();
生成文件:
# Compiler
CC = /usr/bin/gcc
# Name of program
PROG = snmpy
# The name of the object files
OBJS = snmpy.o main.o
# All the header and c files
SRCS = main.c snmpy.c
HDRS = snmpy.h
# Add -I to the dir the curl include files are in
CFLAGS = -c -g -std=c99 -Wall
# Build the executable file
$(PROG): $(OBJS)
$(CC) $(CFLAGS) $(OBJS) -o $(PROG)
# Seperately compile each .c file
main.o: main.c snmpy.h
$(CC) $(CFLAGS) -c main.c
snmpy.o: snmpy.c snmpy.h
$(CC) $(CFLAGS) -c snmpy.c
# Clean up crew
clean:
rm -fv core* $(PROG) $(OBJS)
cleaner: clean
rm -fv #* *~
当我编译它时,它给了我这个错误:
/usr/bin/gcc -c -g -std=c99 -Wall snmpy.o main.o -o snmpy
gcc: snmpy.o: linker input file unused because linking not done
gcc: main.o: linker input file unused because linking not done
不知道发生了什么事情是我做的不对,或者我没有安装什么东西。我是制作文件的菜鸟。我有一段时间没做过了。
提前致谢!!