c - 在 header 中声明枚举,在源文件中不可见?

标签 c dll enums header shared-libraries

在源文件(来自共享对象/DLL)中,我得到OKAY无法解析,尽管它位于 header 中。 header 位于另一个项目中,但我认为这不应该相关,因为 ppackage 已正确解析?

更新,来源如下:

从建筑地板项目构建输出。

make all 
Building file: ../src/foor.c
Invoking: GCC C Compiler
gcc -I"/home/lk/proj/m5/m5/src/include" -O0 -g3 -Wall -c -fmessage-length=0 -fPIC -MMD -MP -MF"src/foor.d" -MT"src/foor.d" -o "src/foor.o" "../src/foor.c"
In file included from ../src/foor.c:9:0:
/home/lk/proj/m5/m5/src/include/m5.h:33:3: warning: #warning ohshit
../src/foor.c:12:1: warning: missing braces around initializer
../src/foor.c:12:1: warning: (near initialization for 'fs[1]')
Finished building: ../src/foor.c

Building target: libfoor.so
Invoking: GCC C Linker
gcc -shared -o "libfoor.so"  ./src/foor.o   
Finished building target: libfoor.so

标题:

#include <stdio.h>

enum {
    OKAY = 0,
    ERR,
    ERRANY,
    // list shortened
    ERRNOTFOUND,
};

typedef struct { ..foobars.. } ppackage;

源文件:

#include <header.h> // Did add -I ../include, where the header is

ppackage knock(ppackage *in)
{
    return OKAY; // ERROR
}

最佳答案

如果包含 header ,则该 header 中的所有代码也可能已粘贴到 C 源文件中 #include 指令所在的位置。

听起来很奇怪,它不起作用。

要做的一件事是使用引号而不是尖括号来包含,因为您要包含第 3 方 header 。

此外,请包含准确的编译器输出。

关于c - 在 header 中声明枚举,在源文件中不可见?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9360118/

相关文章:

c - 我从 printf ("%d") 得到的输出是什么意思?

c++ - 如何部署 C++ DLL

c# - 在 C# 应用程序中导出 C++ 函数

python - 如何使用 Pony ORM 存储 Python 枚举?

c# - 处理意外枚举值的首选方法是什么?

c - 我将如何使用 gstreamer 将一组图像拼接在一起以形成视频幻灯片

c - 如何释放结构数组中的指针

c# - 如何创建虚拟音频设备

java - 枚举和单例

c - 强制编译器/链接器按定义对变量进行分组(物理上位于连续的 RAM 位置)