ファイル cpstr.c でインライン関数 copy_string を定義し、cpstr.c ファイルの .so ファイル (libtest.so) を作成しました。この libtest.so を test.c にリンクしようとすると、次のようなエラーが発生します。
ild: (undefined symbol) char*copy_string(char*,const char*) -- referenced in the text segment of test.o
関数 copy_string からインラインを削除すると、正常に動作します。
以下は、私たちが試したコマンドです。
CC -c -xarch=v9 test.c
CC -G -xarch=v9 -o libtest.so -Kpic cpstr.c
CC -xarch=v9 -g -o test test.o /myplace/libtest.so
libtest.so の内容を取得しようとしたときにcopy_string
、 libtest.so ファイルに名前が見つかりませんでした。しかし、copy_string
function から「inline」を削除すると、コンテンツに表示されます。
インライン関数を削除せずに未定義のシンボルエラーを取り除く解決策を教えてください。
test.c
#include <stdio.h>
extern char *copy_string (char *, const char*);
int main()
{
char str[50];
copy_string(str,"hello");
printf("%s\n", str);
return 0;
}
cpstr.c
#include<string.h>
inline char *copy_string (char *str1, const char *str2)
{
return (str2 ? strcpy (str1, str2) : (char *) 0);
}
CC -c -xarch=v9 test.c
CC -G -xarch=v9 -o libtest.so -Kpic cpstr.c
CC -xarch=v9 -g -o test test.o /space/systpe/devendra/dhsqlroot/libtest.so
ild: (undefined symbol) char*copy_string(char*,const char*) -- referenced in the text segment of test.o