Troubles setting up Curl
-
Hello, thank you for your answer,
I took another version of cURL that I compiled with VC12, I then took the file called 'libcurl.lib' and linked it in the .pro file as you suggested:
LIBS+= -L"C:\Users\Banzai\Desktop\C++\QtPgrm\build-QtPgrm-Desktop_Qt_5_4_2_MSVC2010_OpenGL_32bit-Debug\includes" -llibcurl
Here is what I get when using 'curl_easy_init();' or any other 'curl_easy*':
error: LNK2019: unresolved external symbol __imp_curl_easy_init referenced in function "public: __cdecl MainWindow::MainWindow(class QWidget *)" (??0MainWindow@@QEAA@PEAVQWidget@@@Z)
And yes, it uses the same compiler. Thanks.
-
As I said earlier - skip the lib prefix, i.e.
-lcurl
not-llibcurl
. The linker adds the prefix automatically. -
Oh ok, my apologies.
Just tried it, however, it doesn't seem to look for the right file.
Here is the error message Qt threw back:LNK1181: cannot open input file 'curl.lib'
The folder in question contains:
- curl → directory
- libcurl.lib → file
Also tried to rename 'libcurl.lib' to 'curl.lib', and this time, the same error as the one given in my last post appears.
Thanks for your help.
-
Ah, just spotted another problem - you're using
\
in your path. That's an escape sequence. Either change that to/
or\\
.
-lcurl
is ok, so:LIBS += -LC:/Users/Banzai/Desktop/C++/QtPgrm/build-QtPgrm-Desktop_Qt_5_4_2_MSVC2010_OpenGL_32bit-Debug/includes -lcurl
-
Thanks for your help,
However, it sticks to the same issue (cannot open input file).
Here is my whole .pro file in case it might be of any help:
#-------------------------------------------------
Project created by QtCreator 2015-07-16T18:24:19
#-------------------------------------------------
QT += core gui widgets
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = QtPgrm
TEMPLATE = appQMAKE_LFLAGS += /INCREMENTAL:NO
SOURCES += main.cpp
mainwindow.cppHEADERS += mainwindow.h
FORMS += mainwindow.ui
LIBS+= -L"C:/Users/Banzai/Desktop/C++/QtPgrm/build-QtPgrm-Desktop_Qt_5_4_2_MSVC2010_OpenGL_32bit-Debug/includes" -lcurl
Thank you very much.
-
Are you sure you've got the path correctly? It's unusual that a .lib file would be placed in '.../includes' directory.
Oh, and after you make any kind of changes in the .pro file be sure to re-run qmake:Build->Run qmake
. -
Yes, I am pretty sure it's in the right directory.
Have made several tests to ensure the path is correct,
by modifying the -lcurl at the end, here is what I got:- -lcurl → LNK1181: cannot open input file 'libcurll.lib' (the one you advised me)
- -llibcurl → LNK2019: unresolved external symbol __imp_curl_easy_init referenced in function "public: __cdecl MainWindow::MainWindow(class QWidget *)" (??0MainWindow@@QEAA@PEAVQWidget@@@Z) (the one I used)
- -llibcurlaa → LNK1181: cannot open input file 'libcurlaa.lib' (it was to see the behavior when searching for known inexisting lib, which is pretty similar to the first case)
Thank you.
EDIT: And yes, every modifications made in the .pro file is followed by a Run QMake.
-
Sorry, I mistook something. It's the MinGw linker that adds the 'lib' prefix, but you're using VS2010 so it indeed should be
-llibcurl
, not-lcurl
. My bad.So it seems the lib is linked but it does not contain the symbol. You can verify this by running from command line
dumpbin.exe /exports your/path/to/libcurl.lib > foo.txt
and then inspecting foo.txt to see if the symbol is there.dumpbin
is part of your VS installation located in<VS dlocation>/VC/bin
.If the symbol is there then it means your app's compiler or compilation flags differ from the ones used to build curl.
If it's not there then your build of curl is somehow broken. -
Ah, no problem, a bit of my fault too as I switched between then both at the begining as MinGW had troubles running my code I made with VS.
Concerning the dumpbin, it effectively doesn't seem to be there, here is its content (which is pretty short):
Microsoft (R) COFF/PE Dumper Version 12.00.31101.0
Copyright (C) Microsoft Corporation. All rights reserved.Dump of file libcurl.lib
File Type: LIBRARY
Summary
C3 .debug$S 14 .idata$2 14 .idata$3 4 .idata$4 4 .idata$5 C .idata$6
Now, here is how I built it at first:
- Downloaded cURL 7.43.0 package
- Opened prompt and inputed ' "<PathtoVS>/bin/vcvars32.bat" '
- Inputed 'cd "<PathToCurlUpFolder>/curl-7.43.0/winbuild" '
- Inputed 'nmake /f Makefile.vc mode=dll
- Waited for it to finish, then went in 'libcurl-vc-x86-release-dll-ipv6-sspi-winssl'
- Copied the content of include/curl in my project directory (which is correctly linked)
- Did same as above with lib/libcurl.lib
- Left untouched lib/libcurl.exp , bin/curl.exe , libcurl.dll
Is there something wrong I have been doing ?
Thanks. -
Hello' Again,
I've decided to try it over MinGW compiler and a static build, apparently it got better but still have some errors.
Here is my .pro file:
QT += core gui widgets
TARGET = Launcher
TEMPLATE = appSOURCES += main.cpp
mainwindow.cppHEADERS += mainwindow.h
FORMS += mainwindow.ui
DEFINES += CURL_STATICLIB
LIBS += -L"C:/Users/Banzai/Desktop/C++/QtPgrm/Mingw Real/includes/curl" -lcurl
LIBS += "C:/Users/Banzai/Desktop/C++/QtPgrm/Mingw Real/includes/curl/libcurl.a"
LIBS += "C:/Users/Banzai/Desktop/C++/QtPgrm/Mingw Real/includes/curl/libcurldll.a"
INCLUDEPATH += "C:/Users/Banzai/Desktop/C++/QtPgrm/Mingw Real/includes"Also '#define CURL_STATICLIB' is declared in the header before the include of cURL.
Here is the error I got: error: undefined reference to `curl_easy_init'.
Not too sure what it could be. (I am using the 64 bits version while the compiler is 32 bits).When I've been using the 32 bits version, here is what I got:
undefined reference to {WSAStartup@8,WSACleanup@0}
<path>/curl/libcurl.a(easy.o): bad reloc address 0x0 in section `.data'.Apparently I've ready somewhere that I had to include something with -lwsock32, which I did this way:
LIBS += -lwsock32
Unfortunately it did not seem to change anything.
Thank you for your help.