V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
kuaiabcde
V2EX  ›  C

cl.exe #include"q.h"

  •  
  •   kuaiabcde · 2017-03-04 14:49:34 +08:00 · 1718 次点击
    这是一个创建于 2582 天前的主题,其中的信息可能已经有所发展或是发生改变。

    //file1:q.h int sum(int a, int b);

    //file2:q.c int sum(int a, int b){ return a+b; }

    //file3:qq.c #include"q.h" int main(){ sum(1,2); return 0; }

    $ cl qq.c

    qq.obj : error LNK2019: 无法解析的外部符号 _sum ,该符号在函数 _main 中被引用 qq.exe : fatal error LNK1120: 1 个无法解析的外部命令

    这头文件到底怎么 include? 总不可能 include"q.c"吧

    3 条回复    2017-03-04 16:33:53 +08:00
    lzhCoooder
        1
    lzhCoooder  
       2017-03-04 15:20:42 +08:00
    $cl q.c qq.c
    bp0
        2
    bp0  
       2017-03-04 16:00:12 +08:00 via Android
    单个 cl 就是编译,链接,生成可执行文件一气呵成。但是你只给了一个源文件,所以在链接阶段找不到 sum 函数。
    atempcode
        3
    atempcode  
       2017-03-04 16:33:53 +08:00
    这个报错是 link 阶段报的错, include 头文件是发生在 compile 阶段。写个 makefile 吧。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2779 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 11:55 · PVG 19:55 · LAX 04:55 · JFK 07:55
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.