无法针对 asm-generic/cmpxchg-local.h 进行编译

问题描述 投票:0回答:1

问题:我需要链接什么才能访问 /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
c gcc linker
1个回答
0
投票

您可能不想在用户程序中包含内核头文件...但您正在寻找的是以下 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 <objects>
的操作,并将包含内容更改为
#include <asm-generic/cmpxchg-local.h>
。 您可能需要添加更多
-I
路径来使用该头文件进行编译(但同样,这可能不是您想要做的)。

© www.soinside.com 2019 - 2024. All rights reserved.