【问题标题】:MSFT build, cl, and link with cross-library dependenciesMSFT 构建、cl 和链接与跨库依赖项
【发布时间】:2012-07-09 22:43:04
【问题描述】:

层次结构

\Folder1
    cpu.h
    cpu.c
    sources
\Folder2
    mem.h
    mem.c
    sources
dirs

cpu.h

...
#define nope 0
...
int chuckTesta(unsigned int a);
....

cpu.c

#include <cpu.h>
int chuckTesta(unsigned int a){ ... }

mem.c

#include <cpu.h> // A
extern int chuckTesta(unsigned int a); // B

cout << nope << endl; // C
cout << chuckTesta(1); // D

有没有办法将 cpu.lib 链接到 Folder2 中的文件并满足这些要求?

  • 删除 A 行
  • C 线和 D 线仍然有效
  • 编译和链接没有警告(现在我得到未解析的外部符号或定义错误)

注意:Folder2 的源文件只编译 Folder2 内的文件,并以 Folder1 作为包含路径。与 Folder1 类似。分别创建一个.lib文件,cpu.lib和mem.lib。

我正在为 Windows8 使用 LINK、CL 和构建。

【问题讨论】:

    标签: c visual-studio linker


    【解决方案1】:

    删除 A 行的问题是#define nope 0。如果在 cpu.lib 中将定义转换为静态整数(或加一),它应该可以工作。只需确保在最终的可执行文件中链接到 cpu.lib 和 mem.lib。

    cpu.h

    ...
    #define nope 0
    static int cpu_nope = nope;
    ...
    int chuckTesta(unsigned int a);
    ....
    

    mem.c

    extern int chuckTesta(unsigned int a);
    extern int cpu_nope;
    
    cout << cpu_nope << endl;
    cout << chuckTesta(1);
    

    【讨论】:

      猜你喜欢
      • 2015-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-18
      • 2020-02-01
      • 1970-01-01
      • 2011-10-31
      相关资源
      最近更新 更多