c - 对自定义共享库的 undefined reference

标签 c linux gcc shared-libraries

我用下面的代码创建了一个 .so 文件,但是当我用 GCC 编译一个调用 .so 文件中的函数的文件时,我得到一个“undefined引用 'outlib1'"错误。

我的代码或命令有什么问题?谢谢。

操作系统 Ubuntu 11.10
海合会 4.6.1

//file name outscreen.c

#include <stdio.h>

void outlib1(void)
{
    printf("out screen func1\n");
}
//file name main.c
int main(int argc, char* argv[])
{
    outlib1();
}
gcc outscreen.c -fPIC -shared -o outscreen.so   
gcc main.c -L. -loutscreen -o call   
./call

最佳答案

尝试:

$ gcc outscreen.c -fPIC -shared -o liboutscreen.so   
$ gcc main.c -L. -loutscreen -o call   

(注意第一行的变化——第二行没有变化)

关于c - 对自定义共享库的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8418088/

相关文章:

c - n 在 `sscanf(s, "%d %n", &i, &n)` 中代表什么?

c++ - 为什么 gcc 会发出有关有条件支持的 offsetof 的警告?

c - Scanf 字符串空间问题 C

c - 在 C 中 printf() 中将 int 类型转换为 char

c# - Objective-C 到 C 到 C# 统一包装器可能导致内存泄漏?

linux - 在 Linux 上安装 FAAC,出现错误

linux - Git 错误 : gpg failed to sign the data on Linux

linux - 环境变量地址的随机化

c - 在 SDL 中设置 OGL 主要版本会导致错误

c++ - 神秘的编译器错误,可能与使用 "virtual"有关?