2

何らかの理由で、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
4

1 に答える 1

2

$(OBJ)の後に-lncursesが表示されるように、makeコマンドを変更する必要がありました。

于 2012-05-26T17:31:47.957 に答える