C语言中编译相关的常见错误
1. /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld 返回 1
Reason: no main function in source file
2. to get compile options -I and -lpkg-config lib
e.g: pkg-config --cflags --libs dbus-1 glib-2.0 dbus-glib-1
gcc -o send-sms send-sms.c `pkg-config --cflags --libs dbus-1 glib-2.0 dbus-glib-1`
3. 如何让pkg-config找到自己写的库在库中有一个文件libxxx.pc.in,其中会定义它所提供的头文件在哪里,有哪些,其库链接方式是怎么样,库在哪里,当然这都是库安装到系统以后的信息,换句话说,可能对于编译环境是无意义的。
#include <string.h>#include <stdlib.h>#include <stdio.h>#include "point.h"struct _Point { int x; int y;};Point make_point() { Point point = (Point) calloc(1, sizeof(struct _Point)); point->x = 0; point->y = 0; return point;}void print_point(Point point) { printf("point %d, %d\n", point->x, point->y);}void destroy_point(Point p) { if (p == NULL) { printf("warning, destroying NULL object"); return; } free(p);}