4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

複数ファイルをコンパイルする小さなメモ

Last updated at Posted at 2017-09-07

※記事下部に頂いたコメントあり

コード

test.c
#include <stdio.h>
#include "functions.h"

int main(int arg, char *argv[]){
        printf("hello\n");
        int n;
        n = sum(1,2);
        printf("%d", n);
}
functions.c
int sum(int a, int b){
        int returnv;
        returnv = a + b;
        return returnv;
}
functions.h
int sum(int, int);

コンパイル

# gcc -c test.c
# gcc -c functions.c
★ここまででオブジェクトファイルができる
# gcc test.o functions.o -o test
# ./test
hello
3

参考

ほぼこの記事のまんま
複数ファイルのコンパイル http://7ujm.net/linux/2.html

4
3
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?