我有一个具有libcurl依赖关系的简单c ++程序:
#include <curl/curl.h>
extern "C" int curlTest(void);
int curlTest(void) {
CURL *curl = curl_easy_init();
return 0;
}
我想在Windows上使用MinGW将其构建为共享的DLL库。如果编译并与dynamic libcurl链接,则一切顺利:
> g++ curlTest.cpp -c -o curlTestDynamic.o
> g++ curlTestDynamic.o -shared -o libCurlTestDynamic.dll -lcurl -lgdi32 -lws2_32
并且如果我用libCurlTestDynamic.dll
列出了dumpbin
的导出符号,则curlTest
会如预期那样显示在输出中:
> dumpbin /exports libCurlTestDynamic.dll
...
ordinal hint RVA name
1 0 00001450 curlTest
...
但是如果使用static libcurl构建,则此curlTest
符号只是丢失了:
> g++ -DCURL_STATICLIB curlTest.cpp -c -o curlTestStatic.o
> g++ curlTestStatic.o -shared -o libCurlTestStatic.dll C:/path_to/libcurl.a -lgdi32 -lws2_32
> dumpbin /exports libCurlTestStatic.dll
...
ordinal hint RVA name
1 0 000018A0 curl_easy_cleanup
2 1 000018F0 curl_easy_duphandle
...
(Lots of symbols like curl_* but no curlTest displayed)
...
这使我感到困惑,因为我什至无法使用curlTest
和libCurlTestStatic.dll
函数动态地将LoadLibrary
中的GetProcAddress
函数加载。
我认为您应该使用__declspec(dllexport)
装饰自己的出口。我不确定为什么它在一种情况下不起作用,而在另一种情况下不起作用,但是添加装饰应该万无一失。
也请查看libCurlTestStatic.dll中的导入。根据libcurl.a的构建方式,它可能会带来一些不需要的导入。