I write a program including two files main.c
and comp.c
main.c
#include <stdio.h>
extern int secure_func(int, int);
void main()
{
printf("hello, world\n");
int result = secure_func(1, 1);
}
comp.c
int secure_func(int text, int key)
{
return text * key * key;
}
First, I directly use gcc to build program and run executable, that is fine.
gcc -o main main.c comp.c ./main hello, world
Then I try to use toolchain to build program step by step like this
gcc -c -o comp.o comp.c gcc -c -o main.o main.c ld -o main main.o comp.o -lc --entry main
ld generate a file main
. But if I try to run it, it show error
bash: ./main: No such file or directory
The executable has X permission.
List Info
> ~/test/segtest2$ ls -l
> total 24
> -rw-rw-r-- 1 kail kail 88 Sep 28 21:20 comp.c
> -rw-rw-r-- 1 kail kail 37 Sep 28 21:20 comp.h
> -rw-rw-r-- 1 kail kail 1248 Sep 28 21:22 comp.o
> -rwxrwxr-x 1 kail kail 3241 Sep 28 21:22 main
> -rwxrwxr-- 1 kail kail 137 Sep 28 21:20 main.c
> -rw-rw-r-- 1 kail kail 1568 Sep 28 21:21 main.o
Do I lost anything? Any suggestion will be appreciated. Thanks!