kuaiabcde
V2EX  ›  C

cl.exe #include"q.h"

  •  
  •   kuaiabcde · Mar 4, 2017 · 2343 views
    This topic created in 3359 days ago, the information mentioned may be changed or developed.

    //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 replies    2017-03-04 16:33:53 +08:00
    lzhCoooder
        1
    lzhCoooder  
       Mar 4, 2017
    $cl q.c qq.c
    bp0
        2
    bp0  
       Mar 4, 2017 via Android
    单个 cl 就是编译,链接,生成可执行文件一气呵成。但是你只给了一个源文件,所以在链接阶段找不到 sum 函数。
    atempcode
        3
    atempcode  
       Mar 4, 2017
    这个报错是 link 阶段报的错, include 头文件是发生在 compile 阶段。写个 makefile 吧。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   938 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 19:21 · PVG 03:21 · LAX 12:21 · JFK 15:21
    ♥ Do have faith in what you're doing.