前几天写了一个错误的写法,
大致上的关系长的像是下面这样
出错的地方在於我在 .h
档里面定义了一个变数
为何不可以这样写、以及要如何在 .h
档里面定义变数
的细节其实也还不是很清楚,
但总之就先把错误的写法纪录下来
// hello.h
#ifndef HELLO_H
#define HELLO_H
char *str = "Hello World\n";
void say_hello();
#endif
// hello.c
#include <stdio.h>
#include "hello.h"
void say_hello()
{
printf("%s", str);
}
// main.c
#include "hello.h"
int main(int argc, char **argv)
{
say_hello();
return 0;
}
编译:
$ gcc -c main.c
$ gcc -c hello.c
$ gcc -o hello_world main.o hello.o
/usr/bin/ld: hello.o:(.data.rel.local+0x0): multiple definition of `str'; main.o:(.data.rel.local+0x0): first defined here
collect2: error: ld returned 1 exit status
Day 28 - Android Studio使用GitHub连接 前一篇我们讲到了Kotlin的类...
这个插件就如同名称一样,是专门寄信使用的(恩对,介绍就这样而已)。 准备 在开始使用之前要先做好前置...
哈罗 ~ 大家好 ~ 欢迎回来 ~ 昨天提到 Power Automate 的自动化流程以及核准流程...
前言 今天来讲解特殊型别中的 never,never 是一种函式回传值的状况,跟 void 很像,稍...
这篇文章我们将说来谈谈《 Patterns of Enterprise Application Ar...