使用string.h中生成文件时出错 [英] makefile error when using string.h

查看:219
本文介绍了使用string.h中生成文件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这可能已经回答了,但我无法找到它。当使用做来​​编译以下文件:

 的#include< cs50.h>
#包括LT&;&stdio.h中GT;
#包括LT&;&string.h中GT;INT主要(无效)
{
    //文字的GET行
字符串s = GetString的();//打印字符串,每行一个字符
的for(int i = 0; I<的strlen(S);我++)
{
    焦C = S [I]
    的printf(%C \\ n,C);
}
返回0;
}

我得到以下信息:

  $作例子
CC example.c -o例子
适用于建筑x86_64的未定义符号:
  _GetString,从引用:
      在_main例如,iPNXBe.o
LD:符号(S)未找到x86_64的架构
铿锵:错误:连接命令,退出code 1(使用-v看看调用)失败
使:*** [示例]错误1


解决方案

页面CS50 你可能需要像 -lcs50 CC年底命令。


或者你也可以只使用 cs50.o 目标文件和链接它。

  CC example.c cs50.o例如-o

I realize this has probably been answered but I just cannot find it. When using "make" to compile the following file:

#include <cs50.h>
#include <stdio.h>
#include <string.h>

int main(void)
{
    // get line of text
string s = GetString();

// print string, one character per line
for (int i = 0; i < strlen(s); i++)
{
    char c = s[i];
    printf("%c\n", c);
}
return 0;
}

I get the following message:

$ make example
cc     example.c   -o example
Undefined symbols for architecture x86_64:
  "_GetString", referenced from:
      _main in example-iPNXBe.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [example] Error 1

解决方案

Judging from the cs50 page you probably need something like -lcs50 at the end of the cc command.


Or you can just use the cs50.o object file and link with it.

cc example.c cs50.o -o example

这篇关于使用string.h中生成文件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆