我将尝试用gcc编译一个使用C语言编写的简单DLL。虽然我已经按照多个教程的指导进行了尝试,但即使我把文件精简到最基本也无法编译成功。
test_dll.c
#include <stdio.h>
__declspec(dllexport) int __stdcall hello() {
printf ("Hello World!\n");
}
尝试使用以下命令进行编译:
gcc -c test_dll.c
失败时,会得到以下输出。
test_dll.c: In function '__declspec':
test_dll.c:3:37: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'hello'
__declspec(dllexport) int __stdcall hello() {
^
test_dll.c:5:1: error: expected '{' at end of input
}
^
gcc版本
gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
__declspec(dllexport)
与 Windows 特殊的链接器语义(导入库)有关,而在其他系统上不存在。 - user2371524