编译动态共享c库linux

时间:2017-02-03 21:49:44

标签: c

我尝试编译这个库" github.com/marzac/rs232 /"符合本教程" http://digego.github.io/extempore/c-xtlang-interop.html"在linux 64位机器上。 我收到了这个错误。:

robert@hog:~/rs232/rs232$ clang rs232-linux.c -dynamiclib -o librs232.so
clang: warning: argument unused during compilation: '-dynamiclib'
rs232-linux.c:42:9: warning: '__USE_MISC' macro redefined [-Wmacro-redefined]
#define __USE_MISC // For CRTSCTS
        ^
/usr/include/features.h:317:10: note: previous definition is here
# define __USE_MISC     1
         ^
1 warning generated.
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我发现的唯一一件事是clang缺少主要功能,因为它不知道它应该是一个动态库。所以当我添加" -shared"我得到这个错误:

robert@hog:~/rs232/rs232$ clang rs232-linux.c -shared -dynamiclib -o librs232.so 
clang: warning: argument unused during compilation: '-dynamiclib'
rs232-linux.c:42:9: warning: '__USE_MISC' macro redefined [-Wmacro-redefined]
#define __USE_MISC // For CRTSCTS
        ^
/usr/include/features.h:317:10: note: previous definition is here
# define __USE_MISC     1
         ^
1 warning generated.
/usr/bin/ld: /tmp/rs232-linux-66934f.o: relocation R_X86_64_32S against `.bss' can not be used when making a shared object; recompile with -fPIC
/tmp/rs232-linux-66934f.o: error adding symbols: Bad value
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我几乎没有编译c代码或编写c代码的经验。 任何帮助将非常感激。

的问候,

罗伯特

0 个答案:

没有答案