c - 无法链接到共享对象中的 ncurses

标签 c shared ncurses shared-libraries object-files

出于某种原因,我在编译使用 ncurses 的共享对象时遇到问题。即使我包含并使用 -lncurses 链接,编译 .so 文件也会失败。请指教。

#include <string.h>
#include "../include/mod_curse.h" /* Includes ncurses.h and friends */

int OnConsoleCmd(McapiS *API, ArgS *CmdArgs)    /* Just ignore these, they're included in mod_curse.h */
{
    if(!strcmp(CmdArgs->Data, "help"))
    {
        API->BPrintf(STD, "\n-- mod_curse.so --\n");

        return 0;
    }
}

int OnLoad(McapiS *API, va_list Args)
{
    initscr();  /* These are the problems */
}

/* Time to clean up and unload the module */
int OnDeload(McapiS *API, va_list Args)
{
    endwin();
}

这是 Makefile:

CC = clang
CFLAGS = -Wall -fPIC

# Object Files
OBJ =   mod_curse.o
# Header Files
INCLUDE =   include/mod_curse.h


# Main Module
mod_setup.so: $(OBJ) $(INCLUDE)
    $(CC) -shared -Wl,-soname,mod_curse.so,--no-undefined -o ../../mod_curse.so -lncurses $(OBJ)

# Source Files
mod_curse.o: src/mod_curse.c $(INCLUDE)
    $(CC) $(CFLAGS) -c src/mod_curse.c

clean:
    rm $(OBJ)

错误如下:

3 warnings generated.
clang -shared -Wl,-soname,mod_curse.so,--no-undefined -o ../../mod_curse.so -lncurses mod_curse.o 
mod_curse.o: In function `OnLoad':
src/mod_curse.c:(.text+0x81): undefined reference to `initscr'
mod_curse.o: In function `OnDeload':
src/mod_curse.c:(.text+0xb1): undefined reference to `endwin'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mod_setup.so] Error 1

最佳答案

我需要更改 make 命令以使 -lncurses 出现在 $(OBJ) 之后。

关于c - 无法链接到共享对象中的 ncurses,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10744796/

相关文章:

c - STM32F401RE Nucleo 板,无法切换用户 LED

linux - libstdc++.so.6 错误 : cannot open shared object file: No such file or directory

C Linux 共享内存错误 - ftruncate

c - 32 位和 64 位 c 数据类型的不同大小

c - GDB [[Inferior 1 (process 2710) exited with code 06]] 奇怪的输出

c - QtCreator Doxygen for c 项目

php - 哪个 php 框架适合共享主机?

c++ - 将流转换为函数参数以使用 Telnet 和 Ncurses

在curses 中无法使用箭头键移动光标(C)

python - Curses(Python)中两种颜色之间的淡入淡出