3

I am new in c/c++.... Recently I am trying to compile a program using libCurl. But it shows me these errors:

Error:  Error: Unresolved external '_curl_easy_init' referenced from D:\BC5\BIN\HTTP-POST.OBJ
Error:  Error: Unresolved external '_curl_easy_setopt' referenced from D:\BC5\BIN\HTTP-POST.OBJ
Error:  Error: Unresolved external '_curl_easy_perform' referenced from D:\BC5\BIN\HTTP-POST.OBJ
Error:  Error: Unresolved external '_curl_easy_cleanup' referenced from D:\BC5\BIN\HTTP-POST.OBJ

I have searched on net about these errors and came to know that this is linker error. I found many tutorials about that prob. But I can not understand that.

Note that I have libcurl.dll and lots of header file , I have copied header files in D:\BC5\INCLUDE.... Now what should I do?

Johan
  • 74,508
  • 24
  • 191
  • 319
Tuhin
  • 41
  • 4

2 Answers2

2

You need an import library for your DLL. You can use the implib utility provided by borland to create one from the DLL. Include the resulting .lib in your project and the linker errors should go away. If it start complaining at runtime make sure the DLL is in the same folders as your executable.

Eelke
  • 20,897
  • 4
  • 50
  • 76
  • Fortunately I have successfully created the .lib file..... Now would you plzzz tell me how to include the .lib file??? I copied the lib file in "D:\BC5\LIB" .... I am still receiving those errors ... dont know whats the wrong.... plzzz help me about including the .lib file on my project – Tuhin Jul 11 '11 at 16:52
  • @tuhin your problem sounds very similar to [this question](http://stackoverflow.com/questions/6243638/adding-static-libcurl-to-codeblocks-ide/6286504#6286504). For bcc just include that import lib at the end when you link. – greatwolf Jul 11 '11 at 16:56
  • 1
    @Tuhin, you have to add the lib to the project the same way you add cpp files. You may have to change the file mask in the file open dialog so you can see the lib file. Sorry can't be clearer BC++ is a long time ago for me. – Eelke Jul 11 '11 at 17:24
  • @Victor T.--- I have seen that question , but I didnt understand anything. There was not any similarity between the screenshots and my compiler(borland)..... – Tuhin Jul 12 '11 at 10:38
  • @Eelke----- I have opened the .lib file... I was unable to understand what should I do next.... After opening the .lib file,I have seen some unrecognizable texts..... – Tuhin Jul 12 '11 at 10:41
  • @Turin, the contents of a lib is indeed unreadable you shouldn't just open the file you have to add it to the project so it shows up in the project file tree. Look for menu items with the word Add in them like Add files or Add existing files or Add to project. Probably located in the popup menu shown when you right click the exe node of your project. – Eelke Jul 12 '11 at 10:51
  • Maybe the fault is in my compiler........ I have tried to find the "add"or"add to project" etc during 1.00 hrs. But I didnt find anything. I found "BinInclude" , it showed me "Include library file in target build" in the help hint. But after running that this appears "http://i53.tinypic.com/23urd4k.jpg";.... But it does not allow me to choose my .lib file, and I can not run my program... Dont know what should I do now.... And I am not so much noob that it takes me 1.00 hrs to find....Dont know wheres the fault, mine???? or the compilers????? Plzzzz help me.... – Tuhin Jul 12 '11 at 13:25
0

Eelke is correct that you need to import the libcurl library to properly resolve those errors. Based on your comments above so far, I'm going to assume you've already done the following:

  • You have the basic layout of the libcurl test project setup in the ide.
  • Added the necessary include and lib directories so libcurl can be properly located when building.
  • You've properly created the libcurl.lib import file for use with the linker.

There are two ways you can link in the desired libraries:

  1. Use the tool-chain specific #pragma directive. For example, near the top of one of your source files add:

     // eg. main.cpp
     #include <stdio.h>
     #include <curl/curl.h>
    
     #pragma comment(lib, "libcurl.lib")
    
     // ...
    

    or

  2. Add the libcurl import library to the project. You can do this by right-clicking on the project name->add node. In the 'Add to Project List' window change the file extension filter to look for .lib. By default it starts with C++ source. Locate your libcurl.lib you imported earlier and click open. This will add the import library to the project as a dependency.

Now perform a rebuild of your project (right-click project->build node) and it should work.

greatwolf
  • 20,287
  • 13
  • 71
  • 105
  • i seem to remember that there is a lib converter/tlbimp program you had to run. –  Jul 12 '11 at 18:44
  • @0A0d if he has the libcurl.dll, running something like `implib -a libcurl.lib libcurl.dll` should be enough to create the import. From what I can tell, the needed curl functions are exported as C functions so it should be very interoperable. – greatwolf Jul 12 '11 at 18:49
  • That's what I was thinking. The key is to use Borland's implib program. –  Jul 12 '11 at 18:50
  • @victor t--- I have tried your first method , but unfortunately I was receiving same errors. I changed the name from "libcurl.lib" to "libcurl.libewrwrfewr(or something like this)". It shows me "not found " or something like this kind of error msg. This proves when it was "libcurl.lib" then the compiler could successfully include that file. But my linker errors was still available.... Then I tried this code in Visual c++,there I add that .lib file. But the compiler said that .lib file was corrupted . – Tuhin Jul 13 '11 at 16:51
  • I have created that .lib file with IMPLIB tool. It needs libcurl.dll file. But libcurl does not come to me with that .dll file . I have downloaded that from internet. Now I am confused coz, am I receiving this linker errors because of my corruptness of my .lib file???? If so then suggest me what should I do now. If not then tell me which are other possible reasons behind this prob..... Plzzzz help me, I passed my whole day with this annoying errors...... ............ – Tuhin Jul 13 '11 at 16:52
  • @Tuhin The object format used by borland differs from VC. If you try to use a Borland import lib in VC or visa versa you'll get that corrupted error. – greatwolf Jul 13 '11 at 16:55
  • @Tuhin how did you create the .lib import without the libcurl.dll? Were you using a .def definition file? Note that if you download the libcurl binary package on [this page](http://curl.haxx.se/download.html), libcurl.dll *is* included along with other dll dependencies. Scroll down to the 'Win32 - Generic' section. – greatwolf Jul 13 '11 at 17:00
  • I have downloaded libCurl again from 'Win32 - Generic' ..... There I found libcurl.dll file.... I have created libcurl.lib file using that .dll file...... I have included the .lib file as you said.... But unfortunately I am still receiving those annoying linker errors ....... Dont know whats wrong...... – Tuhin Jul 15 '11 at 15:16
  • @Tuhin Make sure the public functions in the lib you exported *matches* what the linker expects to see. I recall that borland ilink32 expects exported C functions to be *undecorated* w/ an underscore '_' prepended if you're using C calling convention. You can use `tdump -l libcurl.lib` to verify this. See my first comment to 0A0d on how you can reimport with the needed underscore. – greatwolf Jul 15 '11 at 18:36
  • @victorT I did not found no such option named "-a" in implib.But I have continued with "implib -a libcurl.lib libcurl.dll".There I received an error "bad option"..... – Tuhin Jul 17 '11 at 12:11
  • I have done my 85% of project in 5-6 days..... But now I am having prob with this annoying linker errors.... Plzzz help me.... – Tuhin Jul 17 '11 at 12:19
  • @Tuhin it looks like the implib that comes with Borland 5.02 doesn't support this which is necessary to create proper name mappings in the import lib. The free borland commandline tools 5.5 and dmc comes with implib.exe that can do this as well as all versions of C++ Builder. – greatwolf Jul 17 '11 at 21:12
  • @Tuhin Another way to create the import library is to use impdef but that involves manually editing the definition file; it's much more involved and not recommended if you don't know what you're doing – greatwolf Jul 17 '11 at 21:15
  • @Tuhin why are you using borland 5.02 anyway instead of a more recent version of this compiler? – greatwolf Jul 17 '11 at 21:16
  • Thank you all of you guys especially Victor T for trying to help me...... I downloaded DEV C++ just now and included the linkers ,and finally I have reached my goal ............ – Tuhin Jul 18 '11 at 10:13