一个极其简单的问题演示:
#include <stdio.h>
void myFunc()
{
puts("Greetings, Code 'Mon ...");
}
int main(int argc, char *argv[])
{
puts("zMain 01.\n");
myFunc();
puts("zMain 02.\n");
}
Target main_test2.run发出"文件未找到",正如通过gcc
在Ubuntu 20.04.6 RTS上发出的那样:
...
ld: warning: cannot find entry symbol _start; defaulting to 0000000000401030
...
/main_test/yikes01$ ./main_test2.run
bash: ./main_test2.run: No such file or directory
运行相同,但忽略main()作为|开始|MinGW / Windows 10上的要点:
c:\tmp\main_test\yikes01>main_test2.run
Greetings, Code 'Mon ...
c:\tmp\main_test\yikes01>main_test.run
zMain 01.
Greetings, Code 'Mon ...
zMain 02.
Project + makfile为github,但这里是后者:
cc=gcc -v
opts =
link = ld
ifdef OS
libs = -LC:/Windows/System32 -lkernel32 -lmingw32 -lcrtdll
else
libs = -lc
endif
all: main_test2.run main_test.run Makefile
# First function becomes void main(void) ...
main_test2.run: main_test.c
$(cc) $(opts) -c main_test.c
$(link) main_test.o -o main_test2.run $(libs)
rm -f main_test.o
main_test.run: main_test.c
gcc main_test.c -o main_test.run
clean:
rm -f *.o
rm -f *.run
你知道这里有什么备用吗?如何链接gmon_start?
注意:交换参数确实会产生一些略有不同的结果-在CLI(main_test.run)上的直接兼容总是有效的.