【发布时间】:2015-08-09 18:49:40
【问题描述】:
操作系统:ubuntu 14.04
编写两个名为dtest1.c和dtest2.c的.c文件
dtest1.c
int p = 2;
void print()
{
printf("this is the first dll test!\n");
}
dtest2.c
int p = 3;
void print()
{
printf("this is the second dll test!\n");
}
然后,编译得到两个文件,分别是dtest1.so和dtest2.so
$gcc -O -fpic -shared -o dtest1.so dtest1.c
$gcc -O -fpic -shared -o dtest2.so dtest2.c
编写一个名为 dtest3.c 的 .c 文件
dtest3.c
#include "dtest1.so"
int main ()
{
print();
return 0;
}
到目前为止,一切都很好。没有错误(只有警告
然后:
gcc -o dtest3 dtest3.c dtest1.so
错误:
In file included from dtest3.c:1:0:
dtest1.so:17:1: warning: null character(s) ignored [enabled by default]
dtest1.so:17:2: error: stray ‘\260’ in program
......
...... /*omit too many similar information */
dtest1.so:18:2: error: stray ‘\212’ in program
dtest1.so:18:2: error: stray ‘\1’ in program
In file included from dtest3.c:1:0:
dtest1.so:18:956: warning: null character(s) ignored [enabled by default]
In file included from dtest3.c:1:0:
dtest1.so:18:2: error: stray ‘\244’ in program
dtest1.so:18:2: error: stray ‘\1’ in program
In file included from dtest3.c:1:0:
dtest1.so:18:980: warning: null character(s) ignored [enabled by default]
dtest1.so:18:982: warning: null character(s) preserved in literal [enabled by default]
dtest1.so:18:982: warning: missing terminating " character [enabled by default]
In file included from dtest3.c:1:0:
dtest1.so:18:2: error: missing terminating " character
这有什么问题?
请帮我找出错误,谢谢。
【问题讨论】:
-
你不
#include编译库,你#includeC源代码,通常放在一个带有.h扩展名的文件中。 -
谢谢你的话,你启发了我解决这个问题。^_^