- 论坛徽章:
- 0
|
本帖最后由 冷寒生 于 2012-12-05 15:35 编辑
1. 已经在MinGW下编译libcurl出了libcurl.a
参考文章:http://timothyqiu.com/archives/build-libcurl-with-mingw/
2. 在MinGW下测试libcurl
// simple.c
#include <stdio.h>
#include <curl/curl.h>
int main(void)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://www.baidu.com");
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* Check for errors */
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}
gcc -L F:/Source/curl-7.28.0/lib simple.c -DCURL_STATICLIB -lcurl -lws2_32 -lwldap32
#编译成功!!!
3. 在Qt Creator中编写测试程序
// main.cpp
#include <QtCore/QCoreApplication>
#include <curl/curl.h>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
CURL *curl;
curl = curl_easy_init();
return a.exec();
}
///////////////////////////////////////
.pro文件
#-------------------------------------------------
#
# Project created by QtCreator 2012-12-05T15:05:51
#
#-------------------------------------------------
QT += core
QT -= gui
TARGET = test
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
LIBS += -L F:/Source/curl-7.28.0/lib -DCURL_STATICLIB -lcurl -lws2_32 -lwldap32
SOURCES += main.cpp
4. 编译
为项目test执行构建步骤 ...
正在启动 "D:\Qt\qtcreator-2.2.1\mingw\bin\mingw32-make.exe"
D:/Qt/qtcreator-2.2.1/mingw/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `D:/Qt/qtcreator-2.2.1/未命名-build-desktop'
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -I"..\..\4.7.3\include\QtCore" -I"..\..\4.7.3\include" -I"..\..\4.7.3\include\ActiveQt" -I"debug" -I"..\test" -I"." -I"..\..\4.7.3\mkspecs\win32-g++" -o debug\main.o ..\test\main.cpp
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-subsystem,console -mthreads -Wl -o debug\test.exe debug/main.o -L"d:\Qt\4.7.3\lib" -L F:/Source/curl-7.28.0/lib -DCURL_STATICLIB -lcurl -lws2_32 -lwldap32 -lQtCored4
mingw32-make[1]: Leaving directory `D:/Qt/qtcreator-2.2.1/未命名-build-desktop'
debug/main.o: In function `main':
D:\Qt\qtcreator-2.2.1\未命名-build-desktop/../test/main.cpp:9: undefined reference to `_imp__curl_easy_init'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\test.exe] Error 1
mingw32-make: *** [debug] Error 2
进程"D:\Qt\qtcreator-2.2.1\mingw\bin\mingw32-make.exe"退出,退出代码 2 。
构建项目test 时发生错误 (目标: 桌面)
当执行构建步骤 'Make'时 |
|