【问题标题】:Can't compile against asm-generic/cmpxchg-local.h无法针对 asm-generic/cmpxchg-local.h 进行编译
【发布时间】:2012-02-02 22:34:48
【问题描述】:

问题:我需要链接什么才能访问 /asm-generic/cmpxchg-local.h?


信息:

我知道我在某些地方缺少链接,但我无法找出正确的命令。在链接编译器方面我不是很好。我试图编译一个简单的程序来测试我对 cmpxchg-local.h 的访问。我看到有人将其命名为“asm-generic/cmpxchg-local.h”,但这也不起作用。我运行了 locate,它在这里找到了文件:

/usr/src/linux-headers-3.0.0-14/include/asm-generic/cmpxchg-local.h

所以我尝试将整个文件路径放入我的包含中,如下所示:

#include </usr/src/linux-headers-3.0.0-14/include/asm-generic/cmpxchg-local.h>
#include <stdio>

int main()
{
    printf("Hello world!\n");
}

然后继续告诉我它找不到 linux/irqflags.h。显然有些链接丢失了,有什么建议吗?

编译:

 gcc cmpandswp.c -o test -lm

【问题讨论】:

    标签: compiler-construction linker


    【解决方案1】:

    您可能不想在用户程序中包含内核头文件...但您正在寻找的是以下 GCC 标志(来自手册页):

       -I dir
           Add the directory dir to the list of directories to be searched for header files.  Directories named by -I are searched before the standard system include directories.  If the
           directory dir is a standard system include directory, the option is ignored to ensure that the default search order for system directories and the special treatment of system
           headers are not defeated .  If dir begins with "=", then the "=" will be replaced by the sysroot prefix; see --sysroot and -isysroot.
    

    这样,您可以执行gcc -I/usr/src/linux-headers-3.0.0-14/include &lt;objects&gt; 之类的操作并将您的包含更改为#include &lt;asm-generic/cmpxchg-local.h&gt;。您可能需要添加更多 -I 路径以使用该头文件进行编译(但同样,这可能不是您想要做的)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-21
      相关资源
      最近更新 更多