编译Dll能用,但如上图编译静态成静态lib,使用这个静态lib的时候,就会提示link2001未定义的外部符号,头文件、lib文件均已正常导入。
解决方法:
When building an application that uses the static libcurl library, you must
add -DCURL_STATICLIB to your CFLAGS. Otherwise the linker will look for
dynamic import symbols. If you get linker error like "unknown symbol
__imp__curl_easy_init ..." you have linked against the wrong (static)
library. If you want to use the libcurl.dll and import lib, you don't need
any extra CFLAGS, but use one of the import libraries below
请参考:http://curl.haxx.se/docs/faq.html#Link_errors_when_building_libcur
在需要调用静态lib的工程(非libcurl源代码工程)预编译器中添加 CURL_STATICLIB ,即可解决。
原因解析:
curl.h中部分代码
#ifdef CURL_STATICLIB
# define CURL_EXTERN
#elif defined(WIN32) || defined(_WIN32) || defined(__SYMBIAN32__)
# if defined(BUILDING_LIBCURL)
# define CURL_EXTERN __declspec(dllexport)
# else
# define CURL_EXTERN __declspec(dllimport)
# endif
#elif defined(BUILDING_LIBCURL) && defined(CURL_HIDDEN_SYMBOLS)
# define CURL_EXTERN CURL_EXTERN_SYMBOL
#else
# define CURL_EXTERN
#endif
没有定义CURL_STATICLIB的话,默认使用的是__declspec(dllimport),但是这是针对动态lib的,而静态lib无需任何申明。