MinGW无法生成.a?

a_b_c_ 2007-09-04 08:30:49
尝试如下:
1 hellos.h文件中:
void printS(char* str);

2 hellos.c文件中:

#include "hellos.h"

void printS(char* str)
{
printf("print in static way: %s", str);
}

3 在MinGW中输入
gcc -c -o hellos.o hellos.c
ar cqs libhellos.a hellos.o
想生成一个libhellos.a库,却出现了如下的错误提示:

new@MICROSOF-ACBC06 /c/msys/local
$ cd /f/asdf

new@MICROSOF-ACBC06 /f/asdf
$ gcc -c -o hellos.o hellos.c
In file included from hellos.c:1:
hellos.h:6:7: warning: no newline at end of file
hellos.c:6:2: warning: no newline at end of file

new@MICROSOF-ACBC06 /f/asdf
$ ar cps libhellos.a hellos.o
libhellos.a: No such file or directory
C:\msys\mingw\bin\ar.exe:
new@MICROSOF-ACBC06 /f/asdf
$
怎么会这样?
...全文
226 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
a_b_c_ 2007-09-04
  • 打赏
  • 举报
回复
解决了,原来-L后面少了个点!!!晕死!!
a_b_c_ 2007-09-04
  • 打赏
  • 举报
回复
生成libhellos.c之后再建立文件:
/* main.c */
#include <stdio.h>
#include "hellos.h"

void main()
{
char* text = "Hello World!\n";
printS(text);
}

在MinGW执行:
new@MICROSOF-ACBC06 /f/asdf
$ gcc -o hello main.c -L -lhellos
main.c: In function `main':
main.c:5: warning: return type of 'main' is not `int'
main.c:8:2: warning: no newline at end of file
C:/DOCUME~1/new/LOCALS~1/Temp/ccYFbaaa.o:main.c:(.text+0x38): undefined reference to `printS'
collect2: ld returned 1 exit status
竟然提示找不到printS这个函数?!!!!!
星羽 2007-09-04
  • 打赏
  • 举报
回复
gcc -c HelloWorld.c -o HelloWorld.o


ar cqs libHelloWorld.a HelloWorld.o
wang_wuhui 2007-09-04
  • 打赏
  • 举报
回复
-s说错了..
wang_wuhui 2007-09-04
  • 打赏
  • 举报
回复
-c 好像可以生成.a的文件..

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧